package module
Version: v1.0.1 Latest Latest

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

Go to latest
Published: Oct 27, 2020 License: LGPL-3.0 Imports: 11 Imported by: 137


Environ schema

This package allows the specification of Juju environment config schema.



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



This section is empty.


This section is empty.


func SampleYAML

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

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

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

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"

	// Tlist represents an list of strings. Its canonical Go type is []string
	Tlist FieldType = "list"

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

type Fields map[string]Attr

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

func (Fields) ExampleYAML

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

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

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.


Path Synopsis
Package form provides ways to create and process forms based on environschema schemas.
Package form provides ways to create and process forms based on environschema schemas.

Jump to

Keyboard shortcuts

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