github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/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 // ServerUUID holds the UUID for the server environment. This may be empty 39 // if the server is old and not sending the server uuid in the login 40 // repsonse. 41 ServerUUID string 42 } 43 44 // APICredentials hold credentials for connecting to an API endpoint. 45 type APICredentials struct { 46 // User holds the name of the user to connect as. 47 User string 48 Password string 49 } 50 51 // Storage stores environment and server configuration data. 52 type Storage interface { 53 // ReadInfo reads information associated with 54 // the environment with the given name. 55 // If there is no such information, it will 56 // return an errors.NotFound error. 57 ReadInfo(envName string) (EnvironInfo, error) 58 59 // CreateInfo creates some uninitialized information associated 60 // with the environment with the given name. 61 CreateInfo(envName string) EnvironInfo 62 63 // List returns a slice of existing environment names that the Storage 64 // knows about. 65 List() ([]string, error) 66 67 // ListSystems returns a slice of existing server names that the Storage 68 // knows about. 69 ListSystems() ([]string, error) 70 } 71 72 // EnvironInfo holds information associated with an environment. 73 type EnvironInfo interface { 74 // Initialized returns whether the environment information has 75 // been initialized. It will return true for EnvironInfo instances 76 // that have been created but not written. 77 Initialized() bool 78 79 // BootstrapConfig returns the configuration attributes 80 // that an environment will be bootstrapped with. 81 BootstrapConfig() map[string]interface{} 82 83 // APIEndpoint returns the current API endpoint information. 84 APIEndpoint() APIEndpoint 85 86 // APICredentials returns the current API credentials. 87 APICredentials() APICredentials 88 89 // SetBootstrapConfig sets the configuration attributes 90 // to be used for bootstrapping. 91 // This method may only be called on an EnvironInfo 92 // obtained using ConfigStorage.CreateInfo. 93 SetBootstrapConfig(map[string]interface{}) 94 95 // SetAPIEndpoint sets the API endpoint information 96 // currently associated with the environment. 97 SetAPIEndpoint(APIEndpoint) 98 99 // SetAPICreds sets the API credentials currently 100 // associated with the environment. 101 SetAPICredentials(APICredentials) 102 103 // Location returns the location of the source of the environment 104 // information in a human readable format. 105 Location() string 106 107 // Write writes the current information to persistent storage. A 108 // subsequent call to ConfigStorage.ReadInfo can retrieve it. After this 109 // call succeeds, Initialized will return true. 110 // It return ErrAlreadyExists if the EnvironInfo is not yet Initialized 111 // and the EnvironInfo has been written before. 112 Write() error 113 114 // Destroy destroys the information associated with 115 // the environment. 116 Destroy() error 117 }