Documentation ¶
Index ¶
- Constants
- Variables
- func Fingerprint(m ...*Any) string
- func Get(path []string, object interface{}) interface{}
- func List(path []string, object interface{}) []string
- func Put(path []string, value interface{}, object interface{}) bool
- func SortDurations(d []time.Duration)
- func SortPaths(p []Path)
- type Any
- func AnyBytes(data []byte) *Any
- func AnyCopy(any *Any) *Any
- func AnyString(s string) *Any
- func AnyValue(v interface{}) (*Any, error)
- func AnyValueMust(v interface{}) *Any
- func AnyYAML(y []byte) (*Any, error)
- func AnyYAMLMust(y []byte) *Any
- func GetValue(path []string, object interface{}) (*Any, error)
- type Changes
- type Dependency
- type Duration
- type Durations
- type Hierarchical
- type Identity
- type InterfaceSpec
- type Link
- func (l Link) Context() string
- func (l Link) Created() time.Time
- func (l *Link) Equal(other *Link) bool
- func (l *Link) InMap(m map[string]string) bool
- func (l *Link) KVPairs() []string
- func (l Link) Label() string
- func (l *Link) Map() map[string]string
- func (l Link) Valid() bool
- func (l Link) Value() string
- func (l *Link) WithContext(s string) *Link
- func (l *Link) WriteMap(target map[string]string)
- type Metadata
- type Object
- type Path
- func (p Path) Base() string
- func (p Path) Clean() Path
- func (p Path) Dir() Path
- func (p Path) Dot() bool
- func (p Path) Equal(other Path) bool
- func (p Path) Index(i int) *string
- func (p Path) Join(child Path) Path
- func (p Path) JoinString(child string) Path
- func (p Path) Len() int
- func (p Path) Less(other Path) bool
- func (p Path) MarshalJSON() ([]byte, error)
- func (p Path) Rel(path Path) Path
- func (p Path) Shift(i int) Path
- func (p Path) String() string
- func (p *Path) UnmarshalJSON(buff []byte) error
- func (p Path) Valid() bool
- type Paths
- type Pointer
- type Spec
- type Specs
- func (list Specs) Changes(other Specs) Changes
- func (list Specs) Delta(other Specs) (add Specs, remove Specs, changes [][2]Spec)
- func (list Specs) Difference(other Specs) Specs
- func (list Specs) Len() int
- func (list Specs) Less(i, j int) bool
- func (list Specs) Slice() []Spec
- func (list Specs) Swap(i, j int)
- type URL
Constants ¶
const ( LinkLabel = "infrakit-link" LinkContextLabel = "infrakit-link-context" LinkCreatedLabel = "infrakit-link-created" )
Link related labels
Variables ¶
var ( // NullPath means no path NullPath = Path([]string{}) // Dot means self - this. Dot = Path([]string{"."}) )
Functions ¶
func Fingerprint ¶
Fingerprint returns a MD5 hash of the opague blob. It also removes newlines and tab characters that are common in JSON but don't contribute to the actual content.
func Get ¶
func Get(path []string, object interface{}) interface{}
Get returns the attribute of the object at path
func List ¶
List lists the members at the path If the value at the path is listable, then a slice of the children (unqualified) will be returned. If the value at the path doesn't exist, a nil will be returned. A value is listable if it is 1. a slice, 2. a map, 3. a struct (fields will be listed) or a 4. a types.Any where the any object will be unpacked and the same rules above will be applied to the decoded struct.
Types ¶
type Any ¶
type Any json.RawMessage
Any is the raw configuration for the plugin
func AnyValueMust ¶
func AnyValueMust(v interface{}) *Any
AnyValueMust returns an Any from a value by marshaling / encoding the input. It panics if there's error.
func AnyYAMLMust ¶
AnyYAMLMust constructs any Any from a yaml, panics on error
func (*Any) MarshalJSON ¶
MarshalJSON implements the json Marshaler interface
func (*Any) UnmarshalJSON ¶
UnmarshalJSON implements the json Unmarshaler interface
func (*Any) UnmarshalYAML ¶
UnmarshalYAML decodes from yaml and populates the any
type Changes ¶
type Changes struct { // Current is the current specs Current Specs // New is the new specs New Specs // Add is the set of specs to add to current Add Specs // Remove is the set of specs to remove Remove Specs // Changes is a set of before/after specs Changes [][2]Spec }
Changes contain the changes needed to make current specs into the new specs
type Dependency ¶
type Dependency struct { // Kind is the Kind of the spec this spec depends on Kind string `json:"kind"` // Name is the Name of the spec this spec dependes on Name string `json:"name"` // Bind is an associative array of pointer to the fields in the object to a variable name that will be referenced // in the properties or template of the owning spec. Bind map[string]*Pointer `json:"bind"` }
Dependency models the reference and usage of another spec, by spec's Kind and Name, and a way to extract its properties, and how it's referenced via the alias in the Properties section of the dependent Spec.
type Duration ¶
Duration is a wrapper for time.Duration that adds JSON parsing
func DurationFromString ¶
DurationFromString returns either the parsed duration or a default value.
func FromDuration ¶
FromDuration constructs a Duration from a time.Duration
func MustParseDuration ¶
MustParseDuration returns a duration from a string, panics if can't parse
func (Duration) MarshalJSON ¶
MarshalJSON returns the json representation
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON unmarshals the buffer to this struct
type Hierarchical ¶
type Hierarchical interface { // List returns a list of *child nodes* given a path, which is specified as a slice List(path Path) (child []string, err error) // Get retrieves the value at path given. Get(path Path) (value *Any, err error) }
Hierarchical is the interface for any hierarchical, tree-like structures
func HierarchicalFromMap ¶
func HierarchicalFromMap(m map[string]interface{}) Hierarchical
HierarchicalFromMap adapts a map to the hierarchical interface
type Identity ¶
type Identity struct { // ID is a unique identifier for the object instance. ID string `json:"id" yaml:"id"` }
Identity uniquely identifies an instance
type InterfaceSpec ¶
type InterfaceSpec struct { // Name of the interface. Name string // Version is the identifier for the API version. Version string // Sub is the name of 'subclass' entity that follows the general contract but has a distinguishing name Sub string }
InterfaceSpec is metadata about an API.
func DecodeInterfaceSpec ¶
func DecodeInterfaceSpec(s string) InterfaceSpec
DecodeInterfaceSpec takes a string and returns the struct
func (InterfaceSpec) Encode ¶
func (i InterfaceSpec) Encode() string
Encode encodes a struct form to string
func (InterfaceSpec) String ¶
func (i InterfaceSpec) String() string
String implements the stringer for fmt printing
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link is a struct that represents an association between an infrakit managed resource and an entity in some other system. The mechanism of linkage is via labels or tags on both sides.
func NewLinkFromMap ¶
NewLinkFromMap constructs a link from data in the map. The link will have missing data if the input does not contain the attribute labels.
func (*Link) WithContext ¶
WithContext sets a context for this link
type Metadata ¶
type Metadata struct { // Identity is an optional component that exists only in the case of a real object instance. *Identity `json:",inline,omitempty" yaml:",inline,omitempty"` // Name is a user-friendly name. It may or may not be unique. Name string `json:"name"` // Tags are a collection of labels, in key-value form, about the object Tags map[string]string `json:"tags"` }
Metadata captures label and descriptive information about the object
func (Metadata) AddTagsFromStringSlice ¶
AddTagsFromStringSlice will parse any '=' delimited strings and set the Tags map. It overwrites on duplicate keys.
func (Metadata) Fingerprint ¶
Fingerprint returns a unqiue key based on the content of this
type Object ¶
type Object struct { // Spec is the specification / desired state of the object instance. Spec // State is the current snapshot / status of the object instance. State *Any `json:"state,omitempty" yaml:",omitempty"` }
Object is an instance or realization of the Spec. It has Spec as the desired attributes, as well as, the instance identifier (ID), and State, which represents the current snapshot of the object instance.
type Path ¶
type Path []string
Path is used to identify a particle of metadata. The path can be strings separated by / as in a URL.
func PathFromString ¶
PathFromString returns the path components of a / separated path
func RFC6901ToPath ¶
RFC6901ToPath takes a path expression in the format of IETF RFC6901 (JSON pointer) and convert it to a Path
func (Path) Clean ¶
Clean scrubs the path to remove any empty string or . or .. and collapse the path into a concise form. It's similar to path.Clean in the standard lib.
func (Path) JoinString ¶
JoinString joins the input as a child of this path
func (Path) MarshalJSON ¶
MarshalJSON returns the json representation
func (Path) Rel ¶
Rel returns a new path that is a child of the input from this path. e.g. For a path a/b/c/d Rel(a/b/) returns c/d. NullPath is returned if the two are not relative to one another.
func (Path) Shift ¶
Shift returns a new path that's shifted i positions to the left -- ith child of the head at index=0
func (*Path) UnmarshalJSON ¶
UnmarshalJSON unmarshals the buffer to this struct
type Paths ¶
type Paths []Path
Paths is an alias for a slice of Path
func ListAll ¶
func ListAll(h Hierarchical, start Path) (Paths, error)
ListAll returns all the paths under the start path, unsorted
func PathsFromStrings ¶
PathsFromStrings returns the path from a list of strings
type Pointer ¶
type Pointer struct {
// contains filtered or unexported fields
}
Pointer is a JSON pointer where the path is specified per IETF RFC6901 -- see https://tools.ietf.org/html/rfc6901
func PointerFromPath ¶
PointerFromPath creates a pointer from the path
func PointerFromString ¶
PointerFromString constructs a pointer from a string path.
func (*Pointer) Get ¶
func (p *Pointer) Get(v interface{}) interface{}
Get retrieves the value at the given point path location
func (Pointer) MarshalJSON ¶
MarshalJSON returns the json representation
func (*Pointer) Set ¶
Set is a non-copy mutation on the input doc, setting the attribute at the pointer to v
func (*Pointer) UnmarshalJSON ¶
UnmarshalJSON unmarshals the buffer to this struct
type Spec ¶
type Spec struct { // Kind is the category of the resources and kind can have types -- e.g. instance-aws/ec2-instance Kind string `json:"kind"` // Version is the name of the interface and version - instance/v0.1.0 Version string `json:"version"` // Metadata is metadata / useful information about object Metadata Metadata `json:"metadata"` // Template is a template of the resource's properties Template *URL `json:"template,omitempty" yaml:",omitempty"` // Properties is the desired properties of the resource, if template is specified, // then the values of properties override the same fields in template. Properties *Any `json:"properties"` // Options is additional data for handling the object that is not intrinsic to the object itself // but is necessary for the controllers working with it. Options *Any `json:"options,omitempty" yaml:",omitempty"` // Depends is a list of dependencies that this spec needs to have resolved before instances can // be instantiated. Depends []Dependency `json:"depends,omitempty" yaml:",omitempty"` }
Spec is the specification of the resource / object
func SpecFromBytes ¶
SpecFromBytes parses the input either as YAML or JSON and returns the Specs
func SpecFromString ¶
SpecFromString returns the Specs from input string as YAML or JSON
func (Spec) Compare ¶
Compare implements the comparable. This implementation will compute a finger print and use that as a comparison. So
func (Spec) Fingerprint ¶
Fingerprint returns the fingerprint of the spec
type Specs ¶
type Specs []Spec
Specs is a collection of Specs
func SpecsFromBytes ¶
SpecsFromBytes parses the input either as YAML or JSON and returns the Specs
func SpecsFromString ¶
SpecsFromString returns the Specs from input string as YAML or JSON
func (Specs) Delta ¶
Delta computes the changes necessary to make the receiver match the input: 1. the add Specs are entries to add to receiver 2. the remove Specs are entries to remove from receiver 3. changes are a slice of Specs where changes[x][0] is the original, and changes[x][1] is new
func (Specs) Difference ¶
Difference returns a list of specs that is not in the receiver.
type URL ¶
URL is an alias of url
func (URL) MarshalJSON ¶
MarshalJSON returns the json representation
func (*URL) UnmarshalJSON ¶
UnmarshalJSON unmarshals the buffer to this struct