extraconfig

package
v1.5.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GuestInfoPrefix is dictated by vSphere
	GuestInfoPrefix = "guestinfo."

	// ScopeTag is the tag name used for declaring scopes for a field
	ScopeTag = "scope"
	// KeyTag is the tag name by which to override default key naming based on field name
	KeyTag = "key"
	// RecurseTag is the tag name with which different recursion properties are declared
	RecurseTag = "recurse"

	// HiddenScope means the key is hidden from the guest and will not have a GuestInfoPrefix
	HiddenScope = "hidden"
	// ReadOnlyScope means the key is read-only from the guest
	ReadOnlyScope = "read-only"
	// ReadWriteScope means the key may be read and modified by the guest
	ReadWriteScope = "read-write"
	// VolatileScope means that the value is expected to change and should be refreshed on use
	VolatileScope = "volatile"

	// SecretSuffix means the value should be encrypted in the vmx.
	SecretSuffix = "secret"
	// NonPersistentSuffix means the key should only be written if the key will be deleted on guest power off.
	NonPersistentSuffix = "non-persistent"

	// RecurseDepthProperty controls how deep to recuse into a structure field from this level. A value of zero
	// prevents both encode and decode of that field. This is provided to control recursion into unannotated structures.
	// This is unbounded if not specified.
	RecurseDepthProperty = "depth"
	// RecurseFollowProperty instructs encode and decode to follow pointers.
	RecurseFollowProperty = "follow"
	// RecurseNoFollowProperty instructs encode and decode not to follow pointers.
	RecurseNoFollowProperty = "nofollow"
	// RecurseSkipEncodeProperty causes the marked field and subfields to be skipped when encoding.
	RecurseSkipEncodeProperty = "skip-encode"
	// RecurseSkipDecodeProperty causes the marked field and subfields to be skipped when decoding.
	RecurseSkipDecodeProperty = "skip-decode"
)
View Source
const (
	// Invalid value
	Invalid = 1 << iota
	// Hidden value
	Hidden
	// ReadOnly value
	ReadOnly
	// WriteOnly value
	WriteOnly
	// ReadWrite value
	ReadWrite
	// NonPersistent value
	NonPersistent
	// Volatile value
	Volatile
	// Secret value
	Secret
)
View Source
const GuestInfoSecretKey = GuestInfoPrefix + "ovfEnv"

The value of this key is hidden from API requests, but visible within the guest #nosec: Potential hardcoded credentials

Variables

View Source
var (
	// DefaultTagName is the annotation tag name we use for basic semantic version. Not currently used.
	DefaultTagName = "vic"

	// DefaultPrefix is prepended to generated key paths for basic namespacing
	DefaultPrefix = "vice."

	//Separator for slice values and map keys
	Separator = "|"
)

TODO: this entire section of variables should be turned into a config struct that can be passed to Encode and Decode, or that Encode and Decode are method on

View Source
var (
	ErrKeyNotFound = errors.New("key not found")
)
View Source
var Unbounded = recursion{/* contains filtered or unexported fields */}

Unbounded is the value used for unbounded recursion

Functions

func CalculateKey added in v1.4.1

func CalculateKey(obj interface{}, field string, prefix string) string

CalculateKey is a specific case of CalculateKeys that will panic if more than one key matches the field pattern passed in.

func CalculateKeys

func CalculateKeys(obj interface{}, field string, prefix string) []string

CalculateKeys gets the keys in extraconfig corresponding to the field specification passed in for obj. Examples:

type struct A {
    I   int    `vic:"0.1" scope:"read-only" key:"i"`
    Str string `vic:"0.1" scope:"read-only" key:"str"`
}

type struct B {
    A A                      `vic:"0.1" scope:"read-only" key:"a"`
    Array []A                `vic:"0.1" scope:"read-only" key:"array"`
    Map   map[string]string  `vic:"0.1" scope:"read-only" key:"map"`
}

b := B{}
b.Array = []A{A{}}
b.Map = map[string]string{"foo": "", "bar": ""}
// returns []string{"a/str"}
CalculateKeys(b, "A.Str", "")

// returns []string{"array|0"}
CalculateKeys(b, "Array.0", "")

// returns []string{"array|0"}
CalculateKeys(b, "Array.*", "")

// returns []string{"map|foo", "map|bar"}
CalculateKeys(b, "Map.*", "")

// returns []string{"map|foo"}
CalculateKeys(b, "Map.foo", "")

// returns []string{"map|foo/str"}
CalculateKeys(b, "Map.foo.str", "")

func Decode

func Decode(src DataSource, dest interface{}) interface{}

Decode populates a destination with data from the supplied data source

func DecodeWithPrefix

func DecodeWithPrefix(src DataSource, dest interface{}, prefix string) interface{}

DecodeWithPrefix populates a destination with data from the supplied data source, using the specified prefix - this allows for decode into substructres.

func Encode

func Encode(sink DataSink, src interface{})

Encode serializes the given type to the supplied data sink

func EncodeWithPrefix

func EncodeWithPrefix(sink DataSink, src interface{}, prefix string)

EncodeWithPrefix serializes the given type to the supplied data sink, using the supplied prefix - this allows for serialization of subsections of a struct

func SetLogLevel

func SetLogLevel(level logrus.Level)

SetLogLevel for the extraconfig package

Types

type DataSink

type DataSink func(string, string) error

DataSink provides a function that, given a key/value will persist that in some manner suited for later retrieval

func GuestInfoSink

func GuestInfoSink() (DataSink, error)

GuestInfoSink uses the rpcvmx mechanism to update the guestinfo key/value map as the datasink for encoding target structures

func GuestInfoSinkWithPrefix

func GuestInfoSinkWithPrefix(prefix string) (DataSink, error)

GuestInfoSinkWithPrefix adds a prefix to all keys accessed. The key must not have leading or trailing separator characters, but may have separators in other positions. The separator (either . or /) will be replaced with the appropriate value for the key in question.

func MapSink

func MapSink(sink map[string]string) DataSink

MapSink takes a map and populates it with key/value pairs from the encode

func ScopeFilterSink

func ScopeFilterSink(filter uint, sink DataSink) DataSink

ScopeFilterSink will create a DataSink that only stores entries where the key scope matches one or more scopes in the filter. The filter is a bitwise composion of scope flags

type DataSource

type DataSource func(string) (string, error)

DataSource provides a function that, give a key will return a value this is to be used during extraConfig decode to obtain values. Should return ErrKeyNotFound if the key does not exist in the data source.

func GuestInfoSource

func GuestInfoSource() (DataSource, error)

GuestInfoSource uses the rpcvmx mechanism to access the guestinfo key/value map as the datasource for decoding into target structures

func GuestInfoSourceWithPrefix

func GuestInfoSourceWithPrefix(prefix string) (DataSource, error)

GuestInfoSourceWithPrefix adds a prefix to all keys accessed. The key must not have leading or trailing separator characters, but may have separators in other positions. The separator (either . or /) will be replaced with the appropriate value for the key in question.

func MapSource

func MapSource(src map[string]string) DataSource

MapSource takes a key/value map and uses that as the datasource for decoding into target structures

type MapStore

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

func New

func New() *MapStore

func (*MapStore) Get

func (t *MapStore) Get(key string) (string, error)

func (*MapStore) Put

func (t *MapStore) Put(key, value string) error

type SecretKey

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

SecretKey provides helpers to encrypt/decrypt extraconfig values

func NewSecretKey

func NewSecretKey() (*SecretKey, error)

NewSecretKey generates a new secret key

func (*SecretKey) FromString

func (s *SecretKey) FromString(key string) error

FromString base64 decodes an existing SecretKey

func (*SecretKey) Sink

func (s *SecretKey) Sink(ds DataSink) DataSink

Sink wraps the given DataSink, encrypting any secret values

func (*SecretKey) Source

func (s *SecretKey) Source(ds DataSource) DataSource

Source wraps the given DataSource, decrypting any secret values

func (*SecretKey) String

func (s *SecretKey) String() string

String base64 encodes a SecretKey

type Store

type Store interface {
	Get(string) (string, error)
	Put(string, string) error
}

Store provides combined DataSource and DataSink.

Directories

Path Synopsis
Package vmomi is in a separate package to avoid the transitive inclusion of govmomi as a fundamental dependency of the main extraconfig
Package vmomi is in a separate package to avoid the transitive inclusion of govmomi as a fundamental dependency of the main extraconfig

Jump to

Keyboard shortcuts

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