types

package
v0.0.0-...-a355528 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LinkLabel        = "infrakit-link"
	LinkContextLabel = "infrakit-link-context"
	LinkCreatedLabel = "infrakit-link-created"
)

Link related labels

Variables

View Source
var (
	// NullPath means no path
	NullPath = Path([]string{})

	// Dot means self - this.
	Dot = Path([]string{"."})
)

Functions

func Fingerprint

func Fingerprint(m ...*Any) string

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

func List(path []string, object interface{}) []string

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.

func Put

func Put(path []string, value interface{}, object interface{}) bool

Put sets the attribute of an object at path to the given value

func SortDurations

func SortDurations(d []time.Duration)

SortDurations sorts the durations

func SortPaths

func SortPaths(p []Path)

SortPaths sorts the paths

Types

type Any

type Any json.RawMessage

Any is the raw configuration for the plugin

func AnyBytes

func AnyBytes(data []byte) *Any

AnyBytes returns an Any from the encoded message bytes

func AnyCopy

func AnyCopy(any *Any) *Any

AnyCopy makes a copy of the data in the given ptr.

func AnyString

func AnyString(s string) *Any

AnyString returns an Any from a string that represents the marshaled/encoded data

func AnyValue

func AnyValue(v interface{}) (*Any, error)

AnyValue returns an Any from a value by marshaling / encoding the input

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 AnyYAML

func AnyYAML(y []byte) (*Any, error)

AnyYAML constructs any Any from a yaml

func AnyYAMLMust

func AnyYAMLMust(y []byte) *Any

AnyYAMLMust constructs any Any from a yaml, panics on error

func GetValue

func GetValue(path []string, object interface{}) (*Any, error)

GetValue returns the attribute of the object at path, as serialized blob

func (*Any) Bytes

func (c *Any) Bytes() []byte

Bytes returns the encoded bytes

func (*Any) Decode

func (c *Any) Decode(typed interface{}) error

Decode decodes the any into the input typed struct

func (*Any) MarshalJSON

func (c *Any) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface

func (*Any) MarshalYAML

func (c *Any) MarshalYAML() ([]byte, error)

MarshalYAML marshals to yaml

func (*Any) String

func (c *Any) String() string

String returns the string representation.

func (*Any) UnmarshalJSON

func (c *Any) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json Unmarshaler interface

func (*Any) UnmarshalYAML

func (c *Any) UnmarshalYAML(data []byte) error

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

type Duration time.Duration

Duration is a wrapper for time.Duration that adds JSON parsing

func DurationFromString

func DurationFromString(s string, defaultValue time.Duration) Duration

DurationFromString returns either the parsed duration or a default value.

func FromDuration

func FromDuration(d time.Duration) Duration

FromDuration constructs a Duration from a time.Duration

func MustParseDuration

func MustParseDuration(s string) Duration

MustParseDuration returns a duration from a string, panics if can't parse

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON returns the json representation

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(buff []byte) error

UnmarshalJSON unmarshals the buffer to this struct

type Durations

type Durations []time.Duration

Durations is a wrapper to make Duration sortable

func (Durations) Len

func (d Durations) Len() int

func (Durations) Less

func (d Durations) Less(i, j int) bool

func (Durations) Swap

func (d Durations) Swap(i, j int)

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

func (Identity) Compare

func (i Identity) Compare(other Identity) int

Compare implments comparable

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 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 NewLink() *Link

NewLink creates a link

func NewLinkFromMap

func NewLinkFromMap(m map[string]string) *Link

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) Context

func (l Link) Context() string

Context returns the context of the link

func (Link) Created

func (l Link) Created() time.Time

Created returns the creation time of the link

func (*Link) Equal

func (l *Link) Equal(other *Link) bool

Equal returns true if the links are the same - same value and context

func (*Link) InMap

func (l *Link) InMap(m map[string]string) bool

InMap returns true if the link is contained in the map

func (*Link) KVPairs

func (l *Link) KVPairs() []string

KVPairs returns the link representation as a slice of Key=Value pairs

func (Link) Label

func (l Link) Label() string

Label returns the label to look for the link

func (*Link) Map

func (l *Link) Map() map[string]string

Map returns a representation that is easily converted to JSON or YAML

func (Link) Valid

func (l Link) Valid() bool

Valid returns true if the link value is set

func (Link) Value

func (l Link) Value() string

Value returns the value of the link

func (*Link) WithContext

func (l *Link) WithContext(s string) *Link

WithContext sets a context for this link

func (*Link) WriteMap

func (l *Link) WriteMap(target map[string]string)

WriteMap writes to the target map. This will overwrite values of same key

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

func (m Metadata) AddTagsFromStringSlice(v []string) Metadata

AddTagsFromStringSlice will parse any '=' delimited strings and set the Tags map. It overwrites on duplicate keys.

func (Metadata) Compare

func (m Metadata) Compare(other Metadata) int

Compare implements comparable

func (Metadata) Fingerprint

func (m Metadata) Fingerprint() string

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.

func (Object) Validate

func (o Object) Validate() error

Validate checks the object for validity

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 PathFrom

func PathFrom(a string, b ...string) Path

PathFrom return a single path of the given components

func PathFromString

func PathFromString(path string) Path

PathFromString returns the path components of a / separated path

func RFC6901ToPath

func RFC6901ToPath(path string) Path

RFC6901ToPath takes a path expression in the format of IETF RFC6901 (JSON pointer) and convert it to a Path

func (Path) Base

func (p Path) Base() string

Base returns the base of the path

func (Path) Clean

func (p Path) Clean() Path

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) Dir

func (p Path) Dir() Path

Dir returns the 'dir' of the path

func (Path) Dot

func (p Path) Dot() bool

Dot returns true if this is a .

func (Path) Equal

func (p Path) Equal(other Path) bool

Equal returns true if the path is lexicographically equal to the other

func (Path) Index

func (p Path) Index(i int) *string

Index returns the ith component in the path

func (Path) Join

func (p Path) Join(child Path) Path

Join joins the child to the parent

func (Path) JoinString

func (p Path) JoinString(child string) Path

JoinString joins the input as a child of this path

func (Path) Len

func (p Path) Len() int

Len returns the length of the path

func (Path) Less

func (p Path) Less(other Path) bool

Less return true if the path is lexicographically less than the other

func (Path) MarshalJSON

func (p Path) MarshalJSON() ([]byte, error)

MarshalJSON returns the json representation

func (Path) Rel

func (p Path) Rel(path Path) Path

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

func (p Path) Shift(i int) Path

Shift returns a new path that's shifted i positions to the left -- ith child of the head at index=0

func (Path) String

func (p Path) String() string

String returns the string representation of path

func (*Path) UnmarshalJSON

func (p *Path) UnmarshalJSON(buff []byte) error

UnmarshalJSON unmarshals the buffer to this struct

func (Path) Valid

func (p Path) Valid() bool

Valid returns true if is a valid path

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

func PathsFromStrings(a string, b ...string) Paths

PathsFromStrings returns the path from a list of strings

func (Paths) Len

func (p Paths) Len() int

func (Paths) Less

func (p Paths) Less(i, j int) bool

func (*Paths) Sort

func (p *Paths) Sort()

Sort sorts the paths. This will mutate the ordering of the paths in this slice.

func (Paths) Swap

func (p Paths) Swap(i, j int)

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

func PointerFromPath(p Path) *Pointer

PointerFromPath creates a pointer from the path

func PointerFromString

func PointerFromString(s string) *Pointer

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

func (p Pointer) MarshalJSON() ([]byte, error)

MarshalJSON returns the json representation

func (*Pointer) Set

func (p *Pointer) Set(doc, v interface{}) (updated interface{}, err error)

Set is a non-copy mutation on the input doc, setting the attribute at the pointer to v

func (Pointer) String

func (p Pointer) String() string

String returns the string representation

func (*Pointer) UnmarshalJSON

func (p *Pointer) UnmarshalJSON(buff []byte) error

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 MustSpec

func MustSpec(s Spec, err error) Spec

MustSpec returns the spec or panic if errors

func SpecFromBytes

func SpecFromBytes(b []byte) (Spec, error)

SpecFromBytes parses the input either as YAML or JSON and returns the Specs

func SpecFromString

func SpecFromString(s string) (Spec, error)

SpecFromString returns the Specs from input string as YAML or JSON

func (Spec) Compare

func (s Spec) Compare(other Spec) int

Compare implements the comparable. This implementation will compute a finger print and use that as a comparison. So

func (Spec) Fingerprint

func (s Spec) Fingerprint() string

Fingerprint returns the fingerprint of the spec

func (Spec) Validate

func (s Spec) Validate() error

Validate checks the spec for validity

type Specs

type Specs []Spec

Specs is a collection of Specs

func MustSpecs

func MustSpecs(s Specs, err error) Specs

MustSpecs returns the specs or panic if errors

func SpecsFromBytes

func SpecsFromBytes(b []byte) (Specs, error)

SpecsFromBytes parses the input either as YAML or JSON and returns the Specs

func SpecsFromString

func SpecsFromString(s string) (Specs, error)

SpecsFromString returns the Specs from input string as YAML or JSON

func (Specs) Changes

func (list Specs) Changes(other Specs) Changes

Changes returns the changes applying other will do to the receiver

func (Specs) Delta

func (list Specs) Delta(other Specs) (add Specs, remove Specs, changes [][2]Spec)

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

func (list Specs) Difference(other Specs) Specs

Difference returns a list of specs that is not in the receiver.

func (Specs) Len

func (list Specs) Len() int

Len is part of sort.Interface.

func (Specs) Less

func (list Specs) Less(i, j int) bool

Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.

func (Specs) Slice

func (list Specs) Slice() []Spec

Slice returns the slice

func (Specs) Swap

func (list Specs) Swap(i, j int)

Swap is part of sort.Interface.

type URL

type URL url.URL

URL is an alias of url

func NewURL

func NewURL(s string) (*URL, error)

NewURL creates a new url from string

func (URL) Absolute

func (u URL) Absolute() bool

Absolute returns true if the url is absolute (not relative)

func (URL) Compare

func (u URL) Compare(other URL) int

Compare implements comparable

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON returns the json representation

func (URL) String

func (u URL) String() string

String returns the string representation of the URL

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(buff []byte) error

UnmarshalJSON unmarshals the buffer to this struct

func (URL) Value

func (u URL) Value() *url.URL

Value returns the aliased struct

Jump to

Keyboard shortcuts

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