rtcservice

package
v0.0.0-...-e1c190b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package rtcservice provides utility functions for the cloudprober project used when dealing with the Runtime Configurator API. https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/ This API essentially provides a small key/val store for GCE projects. Cloudprober uses this for things like maintaining a lameduck list, listing probing hosts in the projects, and in general any shared state that cloudprober instances might require.

Because RTC requires a GCE project, this package provides all functionality as methods on the Config interface. This allows the behavior to be more easily mocked for testing.

rtcservice.Config is meant to represent a configuration or resource in the RTC sense (see https://cloud.google.com/deployment-manager/runtime-configurator/). If one needs to interact with multiple configurations, they will need multiple instances of rtc.Config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	// Write adds or changes a key value pair to a configuration.
	Write(key string, val []byte) error
	// Delete removes a variable from a configuration.
	Delete(key string) error
	// Val returns the Value stored by a variable.
	Val(v *runtimeconfig.Variable) ([]byte, error)
	// List lists all variables in a configuration. These variables will not
	// include their Text or Value fields.
	List() ([]*runtimeconfig.Variable, error)
	// FilterList will list all variables in a configuration, filtering variable
	// names by the filter string. This mirrors the behavior found in
	// https://cloud.google.com/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables/list
	FilterList(filter string) ([]*runtimeconfig.Variable, error)
}

The Config interface provides communication to the Runtime Configurator API. It represents a single runtime configuration, allowing one to read and write variables to the configuration.

func New

func New(proj string, cfg string, c *http.Client) (Config, error)

New provides an interface to the RTC API for a given project. The string proj represents the project name (such as "google.com:bbmc-test"), and the string "cfg" will represent the name of the RTC resource.

In order to provide fail-fast sanitation, New will check that the provided project string and cfg string are reachable. If not, an error will be returned. Note that this means New cannot be used to establish a new RTC configuration --- the configuration must already exist.

New also takes an OAuth2.0 enabled *http.Client for API access. If a nil *http.Client is provided, a new http.Client is created using google.DefaultClient, which uses default credentials.

type Stub

type Stub struct {
	// contains filtered or unexported fields
}

Stub provides a stubbed version of RTC that can be used for testing larger components.

func NewStub

func NewStub() *Stub

NewStub returns a Stub interface to RTC which will store all variables in an in-memory map.

func (*Stub) Delete

func (s *Stub) Delete(key string) error

Delete removes a key/val pair.

func (*Stub) FilterList

func (s *Stub) FilterList(filter string) ([]*runtimeconfig.Variable, error)

FilterList is not supported by this Stub. Simply returns s.List().

func (*Stub) List

func (s *Stub) List() ([]*runtimeconfig.Variable, error)

List provides all vals in the map. To match the behavior of rtc.go, this will not include the value (to test that your code does not rely on such a behavior).

func (*Stub) Val

func (s *Stub) Val(v *runtimeconfig.Variable) ([]byte, error)

Val gets the value associated with a variable.

func (*Stub) Write

func (s *Stub) Write(key string, val []byte) error

Write will add or change a key/val pair.

func (*Stub) WriteTime

func (s *Stub) WriteTime(key string, val string, time string) error

WriteTime adds or changes a key/val pair, but with the UpdateTime field set to the given string. This is passed in as a string rather than a time so invalid times can be tested.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL