juju: github.com/axw/juju/cloud Index | Files

package cloud

import "github.com/axw/juju/cloud"

Package cloud provides functionality to parse information describing clouds, including regions, supported auth types etc.


Package Files

clouds.go credentials.go fallback_public_cloud.go personalclouds.go


const DefaultLXD = "localhost"

DefaultLXD is the name of the default lxd cloud.


var BuiltInClouds = map[string]Cloud{
    DefaultLXD: {
        Type:      lxdnames.ProviderType,
        AuthTypes: []AuthType{EmptyAuthType},
        Regions:   []Region{{Name: lxdnames.DefaultRegion}},

BuiltInClouds work out of the box.

func IsSameCloudMetadata Uses

func IsSameCloudMetadata(meta1, meta2 map[string]Cloud) (bool, error)

IsSameCloudMetadata returns true if both meta and meta2 contain the same cloud metadata.

func JujuPersonalCloudsPath Uses

func JujuPersonalCloudsPath() string

JujuPersonalCloudsPath is the location where personal cloud information is expected to be found. Requires JUJU_HOME to be set.

func JujuPublicCloudsPath Uses

func JujuPublicCloudsPath() string

JujuPublicCloudsPath is the location where public cloud information is expected to be found. Requires JUJU_HOME to be set.

func MarshalCloud Uses

func MarshalCloud(cloud Cloud) ([]byte, error)

MarshalCloud marshals a Cloud to an opaque byte array.

func ParseCloudMetadata Uses

func ParseCloudMetadata(data []byte) (map[string]Cloud, error)

ParseCloudMetadata parses the given yaml bytes into Clouds metadata.

func ParseCloudMetadataFile Uses

func ParseCloudMetadataFile(file string) (map[string]Cloud, error)

ParseCloudMetadataFile loads any cloud metadata defined in the specified file.

func ParseCredentials Uses

func ParseCredentials(data []byte) (map[string]CloudCredential, error)

ParseCredentials parses the given yaml bytes into Credentials, but does not validate the credential attributes.

func PersonalCloudMetadata Uses

func PersonalCloudMetadata() (map[string]Cloud, error)

PersonalCloudMetadata loads any personal cloud metadata defined in the Juju Home directory. If not cloud metadata is found, that is not an error; nil is returned.

func PublicCloudMetadata Uses

func PublicCloudMetadata(searchPath ...string) (result map[string]Cloud, fallbackUsed bool, err error)

PublicCloudMetadata looks in searchPath for cloud metadata files and if none are found, returns the fallback public cloud metadata.

func RegionNames Uses

func RegionNames(regions []Region) []string

RegionNames returns a sorted list of the names of the given regions.

func RegisterStructTags Uses

func RegisterStructTags(vals ...interface{})

RegisterStructTags ensures the yaml tags for the given structs are able to be used when parsing cloud metadata.

func ValidateFileAttrValue Uses

func ValidateFileAttrValue(path string) (string, error)

ValidateFileAttrValue returns the normalised file path, so long as the specified path is valid and not a directory.

func WritePersonalCloudMetadata Uses

func WritePersonalCloudMetadata(cloudsMap map[string]Cloud) error

WritePersonalCloudMetadata marshals to YAMl and writes the cloud metadata to the personal cloud file.

func WritePublicCloudMetadata Uses

func WritePublicCloudMetadata(cloudsMap map[string]Cloud) error

WritePublicCloudMetadata marshals to YAML and writes the cloud metadata to the public cloud file.

type Attrs Uses

type Attrs map[string]interface{}

Attrs serves as a map to hold regions specific configuration attributes. This serves to reduce confusion over having a nested map, i.e. map[string]map[string]interface{}

type AuthType Uses

type AuthType string

AuthType is the type of authentication used by the cloud.

const (
    // AccessKeyAuthType is an authentication type using a key and secret.
    AccessKeyAuthType AuthType = "access-key"

    // UserPassAuthType is an authentication type using a username and password.
    UserPassAuthType AuthType = "userpass"

    // OAuth1AuthType is an authentication type using oauth1.
    OAuth1AuthType AuthType = "oauth1"

    // OAuth2AuthType is an authentication type using oauth2.
    OAuth2AuthType AuthType = "oauth2"

    // JSONFileAuthType is an authentication type that takes a path to
    // a JSON file.
    JSONFileAuthType AuthType = "jsonfile"

    // CertificateAuthType is an authentication type using certificates.
    CertificateAuthType AuthType = "certificate"

    // EmptyAuthType is the authentication type used for providers
    // that require no credentials, e.g. "lxd", and "manual".
    EmptyAuthType AuthType = "empty"

type AuthTypes Uses

type AuthTypes []AuthType

AuthTypes is defined to allow sorting AuthType slices.

func (AuthTypes) Len Uses

func (a AuthTypes) Len() int

func (AuthTypes) Less Uses

func (a AuthTypes) Less(i, j int) bool

func (AuthTypes) Swap Uses

func (a AuthTypes) Swap(i, j int)

type Cloud Uses

type Cloud struct {
    // Type is the type of cloud, eg ec2, openstack etc.
    // This is one of the provider names registered with
    // environs.RegisterProvider.
    Type string

    // AuthTypes are the authentication modes supported by the cloud.
    AuthTypes AuthTypes

    // Endpoint is the default endpoint for the cloud regions, may be
    // overridden by a region.
    Endpoint string

    // IdentityEndpoint is the default identity endpoint for the cloud
    // regions, may be overridden by a region.
    IdentityEndpoint string

    // StorageEndpoint is the default storage endpoint for the cloud
    // regions, may be overridden by a region.
    StorageEndpoint string

    // Regions are the regions available in the cloud.
    // Regions is a slice, and not a map, because order is important.
    // The first region in the slice is the default region for the
    // cloud.
    Regions []Region

    // Config contains optional cloud-specific configuration to use
    // when bootstrapping Juju in this cloud. The cloud configuration
    // will be combined with Juju-generated, and user-supplied values;
    // user-supplied values taking precedence.
    Config map[string]interface{}

    // RegionConfig contains optional region specific configuration.
    // Like Config above, this will be combined with Juju-generated and user
    // supplied values; with user supplied values taking precedence.
    RegionConfig RegionConfig

Cloud is a cloud definition.

func CloudByName Uses

func CloudByName(name string) (*Cloud, error)

CloudByName returns the cloud with the specified name. If there exists no cloud with the specified name, an error satisfying errors.IsNotFound will be returned.

TODO(axw) write unit tests for this.

func UnmarshalCloud Uses

func UnmarshalCloud(in []byte) (Cloud, error)

UnmarshalCloud unmarshals a Cloud from a byte array produced by MarshalCloud.

type CloudCredential Uses

type CloudCredential struct {
    // DefaultCredential is the named credential to use by default.
    DefaultCredential string `yaml:"default-credential,omitempty"`

    // DefaultRegion is the cloud region to use by default.
    DefaultRegion string `yaml:"default-region,omitempty"`

    // AuthCredentials is the credentials for a cloud, keyed on name.
    AuthCredentials map[string]Credential `yaml:",omitempty,inline"`

CloudCredential contains attributes used to define credentials for a cloud.

func NewEmptyCloudCredential Uses

func NewEmptyCloudCredential() *CloudCredential

NewEmptyCloudCredential returns a new CloudCredential with an empty default credential.

type Credential Uses

type Credential struct {

    // Revoked is true if the credential has been revoked.
    Revoked bool

    // Label is optionally set to describe the credentials to a user.
    Label string
    // contains filtered or unexported fields

Credential instances represent cloud credentials.

func FinalizeCredential Uses

func FinalizeCredential(
    credential Credential,
    schemas map[AuthType]CredentialSchema,
    readFile func(string) ([]byte, error),
) (*Credential, error)

FinalizeCredential finalizes a credential by matching it with one of the provided credential schemas, and reading any file attributes into their corresponding non-file attributes. This will also validate the credential.

If there is no schema with the matching auth-type, and error satisfying errors.IsNotSupported will be returned.

func NewCredential Uses

func NewCredential(authType AuthType, attributes map[string]string) Credential

NewCredential returns a new, immutable, Credential with the supplied auth-type and attributes.

func NewEmptyCredential Uses

func NewEmptyCredential() Credential

NewEmptyCredential returns a new Credential with the EmptyAuthType auth-type.

func RemoveSecrets Uses

func RemoveSecrets(
    credential Credential,
    schemas map[AuthType]CredentialSchema,
) (*Credential, error)

RemoveSecrets returns a copy of the given credential with secret fields removed.

func (Credential) Attributes Uses

func (c Credential) Attributes() map[string]string

Attributes returns the credential attributes.

func (Credential) AuthType Uses

func (c Credential) AuthType() AuthType

AuthType returns the authentication type.

func (Credential) MarshalYAML Uses

func (c Credential) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*Credential) UnmarshalYAML Uses

func (c *Credential) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Marshaler interface.

type CredentialAttr Uses

type CredentialAttr struct {
    // Description is a human-readable description of the credential
    // attribute.
    Description string

    // Hidden controls whether or not the attribute value will be hidden
    // when being entered interactively. Regardless of this, all credential
    // attributes are provided only to the Juju controllers.
    Hidden bool

    // FileAttr is the name of an attribute that may be specified instead
    // of this one, which points to a file that will be read in and its
    // value used for this attribute.
    FileAttr string

    // FilePath is true is the value of this attribute is a file path. If
    // this is true, then the attribute value will be set to the contents
    // of the file when the credential is "finalized".
    FilePath bool

    // Optional controls whether the attribute is required to have a non-empty
    // value or not. Attributes default to mandatory.
    Optional bool

    // Options, if set, define the allowed values for this field.
    Options []interface{}

CredentialAttr describes the properties of a credential attribute.

type CredentialSchema Uses

type CredentialSchema []NamedCredentialAttr

CredentialSchema describes the schema of a credential. Credential schemas are specific to cloud providers.

func (CredentialSchema) Attribute Uses

func (s CredentialSchema) Attribute(name string) (*CredentialAttr, bool)

Attribute returns the named CredentialAttr value.

func (CredentialSchema) Finalize Uses

func (s CredentialSchema) Finalize(
    attrs map[string]string,
    readFile func(string) ([]byte, error),
) (map[string]string, error)

Finalize finalizes the given credential attributes against the credential schema. If the attributes are invalid, Finalize will return an error.

An updated attribute map will be returned, having any file attributes deleted, and replaced by their non-file counterparts with the values set to the contents of the files.

type NamedCredentialAttr Uses

type NamedCredentialAttr struct {
    // Name is the name of the credential value.
    Name string

    // CredentialAttr holds the properties of the credential value.

NamedCredentialAttr describes the properties of a named credential attribute.

type Region Uses

type Region struct {
    // Name is the name of the region.
    Name string

    // Endpoint is the region's primary endpoint URL.
    Endpoint string

    // IdentityEndpoint is the region's identity endpoint URL.
    // If the cloud/region does not have an identity-specific
    // endpoint URL, this will be empty.
    IdentityEndpoint string

    // StorageEndpoint is the region's storage endpoint URL.
    // If the cloud/region does not have a storage-specific
    // endpoint URL, this will be empty.
    StorageEndpoint string

Region is a cloud region.

func RegionByName Uses

func RegionByName(regions []Region, name string) (*Region, error)

RegionByName finds the region in the given slice with the specified name, with case folding.

type RegionConfig Uses

type RegionConfig map[string]Attrs

RegionConfig holds a map of regions and the attributes that serve as the region specific configuration options. This allows model inheritance to function, providing a place to store configuration for a specific region which is passed down to other models under the same controller.

Package cloud imports 14 packages (graph). Updated 2016-12-02. Refresh now. Tools for package owners.