environschema.v1: gopkg.in/juju/environschema.v1 Index | Files | Directories

package environschema

import "gopkg.in/juju/environschema.v1"

Package environschema implements a way to specify configuration attributes for Juju environments.

Index

Package Files

fields.go sample.go

func SampleYAML Uses

func SampleYAML(w io.Writer, indent int, attrs map[string]interface{}, fields Fields) error

SampleYAML writes YAML output to w, indented by indent spaces that holds the attributes in attrs with descriptions found in the given fields. An entry for any attribute in fields not in attrs will be generated but commented out.

type Attr Uses

type Attr struct {
    // Description holds a human-readable description
    // of the attribute.
    Description string `json:"description"`

    // Type holds the type of the attribute value.
    Type FieldType `json:"type"`

    // Group holds the group that the attribute belongs to.
    // All attributes within a Fields that have the same Group
    // attribute are considered to be part of the same group.
    Group Group `json:"group"`

    // Immutable specifies whether the attribute cannot
    // be changed once set.
    Immutable bool

    // Mandatory specifies whether the attribute
    // must be provided.
    Mandatory bool `json:"mandatory,omitempty"`

    // Secret specifies whether the attribute should be
    // considered secret.
    Secret bool `json:"is-secret,omitempty"`

    // EnvVar holds the environment variable
    // that will be used to obtain the default value
    // if it isn't specified.
    EnvVar string `json:"env-var,omitempty"`

    // EnvVars holds additional environment
    // variables to be used if the value in EnvVar is
    // not available, from highest to lowest priority.
    EnvVars []string `json:"env-vars,omitempty"`

    // Example holds an example value for the attribute
    // that can be used to produce a plausible-looking
    // entry for the attribute without necessarily using
    // it as a default value.
    //
    // TODO if the example holds some special values, use
    // it as a template to generate initial random values
    // (for example for admin-password) ?
    Example interface{} `json:"example,omitempty"`

    // Values holds the set of all possible values of the attribute.
    Values []interface{} `json:"values,omitempty"`
}

func (Attr) Checker Uses

func (attr Attr) Checker() (schema.Checker, error)

Checker returns a checker that can be used to coerce values into the type of the attribute. Specifically, string is always supported for any checker type.

type FieldType Uses

type FieldType string

FieldType describes the type of an attribute value.

const (
    // Tstring represents a string type. Its canonical Go type is string.
    Tstring FieldType = "string"

    // Tbool represents a boolean type. Its canonical Go type is bool.
    Tbool FieldType = "bool"

    // Tint represents an integer type. Its canonical Go type is int.
    Tint FieldType = "int"

    // Tattrs represents an attribute map. Its canonical Go type is map[string]string.
    Tattrs FieldType = "attrs"
)

The following constants are the possible type values. The "canonical Go type" is the type that the will be the result of a successful Coerce call.

type Fields Uses

type Fields map[string]Attr

Fields holds a map from attribute name to information about that attribute.

func (Fields) ExampleYAML Uses

func (s Fields) ExampleYAML() []byte

ExampleYAML returns the fields formatted as a YAML example, with non-mandatory fields commented out, like the providers do currently.

func (Fields) ValidationSchema Uses

func (s Fields) ValidationSchema() (schema.Fields, schema.Defaults, error)

ValidationSchema returns values suitable for passing to schema.FieldMap to create a schema.Checker that will validate the given fields. It will return an error if the fields are invalid.

The Defaults return value will contain entries for all non-mandatory attributes set to schema.Omit. It is the responsibility of the client to set any actual default values as required.

type Group Uses

type Group string

Group describes the grouping of attributes.

const (
    // JujuGroup groups attributes defined by Juju that may
    // not be specified by a user.
    JujuGroup Group = "juju"

    // EnvironGroup groups attributes that are defined across all
    // possible Juju environments.
    EnvironGroup Group = "environ"

    // AccountGroup groups attributes that define a user account
    // used by a provider.
    AccountGroup Group = "account"

    // ProviderGroup groups attributes defined by the provider
    // that are not account credentials. This is also the default
    // group.
    ProviderGroup Group = ""
)

The following constants are the initially defined group values.

Directories

PathSynopsis
formPackage form provides ways to create and process forms based on environschema schemas.

Package environschema imports 11 packages (graph) and is imported by 284 packages. Updated 2019-04-21. Refresh now. Tools for package owners.