github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/environs/configstore/interface.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package configstore
     5  
     6  import (
     7  	"errors"
     8  )
     9  
    10  // DefaultAdminUsername is used as the username to connect as in the
    11  // absense of any explicit username being defined in the config store.
    12  var DefaultAdminUsername = "admin"
    13  
    14  var ErrEnvironInfoAlreadyExists = errors.New("environment info already exists")
    15  
    16  // APIEndpoint holds information about an API endpoint.
    17  type APIEndpoint struct {
    18  	// APIAddress holds a list of API addresses. It may not be
    19  	// current, and it will be empty if the environment has not been
    20  	// bootstrapped.
    21  	Addresses []string
    22  
    23  	// Hostnames holds a list of API addresses which may contain
    24  	// unresolved hostnames. It's used to compare more recent API
    25  	// addresses before resolving hostnames to determine if the cached
    26  	// addresses have changed and therefore perform (a possibly slow)
    27  	// local DNS resolution before comparing them against Addresses.
    28  	Hostnames []string
    29  
    30  	// CACert holds the CA certificate that
    31  	// signed the API server's key.
    32  	CACert string
    33  
    34  	// EnvironUUID holds the UUID for the environment we are connecting to.
    35  	// This may be empty if the environment has not been bootstrapped.
    36  	EnvironUUID string
    37  }
    38  
    39  // APICredentials hold credentials for connecting to an API endpoint.
    40  type APICredentials struct {
    41  	// User holds the name of the user to connect as.
    42  	User     string
    43  	Password string
    44  }
    45  
    46  // Storage stores environment configuration data.
    47  type Storage interface {
    48  	// ReadInfo reads information associated with
    49  	// the environment with the given name.
    50  	// If there is no such information, it will
    51  	// return an errors.NotFound error.
    52  	ReadInfo(envName string) (EnvironInfo, error)
    53  
    54  	// CreateInfo creates some uninitialized information associated
    55  	// with the environment with the given name.
    56  	CreateInfo(envName string) EnvironInfo
    57  
    58  	// List returns a slice of existing environment names that the Storage
    59  	// knows about.
    60  	List() ([]string, error)
    61  }
    62  
    63  // EnvironInfo holds information associated with an environment.
    64  type EnvironInfo interface {
    65  	// Initialized returns whether the environment information has
    66  	// been initialized. It will return true for EnvironInfo instances
    67  	// that have been created but not written.
    68  	Initialized() bool
    69  
    70  	// BootstrapConfig returns the configuration attributes
    71  	// that an environment will be bootstrapped with.
    72  	BootstrapConfig() map[string]interface{}
    73  
    74  	// APIEndpoint returns the current API endpoint information.
    75  	APIEndpoint() APIEndpoint
    76  
    77  	// APICredentials returns the current API credentials.
    78  	APICredentials() APICredentials
    79  
    80  	// SetBootstrapConfig sets the configuration attributes
    81  	// to be used for bootstrapping.
    82  	// This method may only be called on an EnvironInfo
    83  	// obtained using ConfigStorage.CreateInfo.
    84  	SetBootstrapConfig(map[string]interface{})
    85  
    86  	// SetAPIEndpoint sets the API endpoint information
    87  	// currently associated with the environment.
    88  	SetAPIEndpoint(APIEndpoint)
    89  
    90  	// SetAPICreds sets the API credentials currently
    91  	// associated with the environment.
    92  	SetAPICredentials(APICredentials)
    93  
    94  	// Location returns the location of the source of the environment
    95  	// information in a human readable format.
    96  	Location() string
    97  
    98  	// Write writes the current information to persistent storage. A
    99  	// subsequent call to ConfigStorage.ReadInfo can retrieve it. After this
   100  	// call succeeds, Initialized will return true.
   101  	// It return ErrAlreadyExists if the EnvironInfo is not yet Initialized
   102  	// and the EnvironInfo has been written before.
   103  	Write() error
   104  
   105  	// Destroy destroys the information associated with
   106  	// the environment.
   107  	Destroy() error
   108  }