github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/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 var ErrEnvironInfoAlreadyExists = errors.New("environment info already exists") 11 12 // APIEndpoint holds information about an API endpoint. 13 type APIEndpoint struct { 14 // APIAddress holds a list of API addresses. It may not be 15 // current, and it will be empty if the environment has not been 16 // bootstrapped. 17 Addresses []string 18 19 // CACert holds the CA certificate that 20 // signed the API server's key. 21 CACert string 22 23 // EnvironUUID holds the UUID for the environment we are connecting to. 24 // This may be empty if the environment has not been bootstrapped. 25 EnvironUUID string 26 } 27 28 // APICredentials hold credentials for connecting to an API endpoint. 29 type APICredentials struct { 30 // User holds the name of the user to connect as. 31 User string 32 Password string 33 } 34 35 // Storage stores environment configuration data. 36 type Storage interface { 37 // ReadInfo reads information associated with 38 // the environment with the given name. 39 // If there is no such information, it will 40 // return an errors.NotFound error. 41 ReadInfo(envName string) (EnvironInfo, error) 42 43 // CreateInfo creates some uninitialized information associated 44 // with the environment with the given name. 45 // It return ErrAlreadyExists if the 46 // information has already been created. 47 CreateInfo(envName string) (EnvironInfo, error) 48 } 49 50 // EnvironInfo holds information associated with an environment. 51 type EnvironInfo interface { 52 // Initialized returns whether the environment information has 53 // been initialized. It will return true for EnvironInfo instances 54 // that have been created but not written. 55 Initialized() bool 56 57 // BootstrapConfig returns the configuration attributes 58 // that an environment will be bootstrapped with. 59 BootstrapConfig() map[string]interface{} 60 61 // APIEndpoint returns the current API endpoint information. 62 APIEndpoint() APIEndpoint 63 64 // APICredentials returns the current API credentials. 65 APICredentials() APICredentials 66 67 // SetBootstrapConfig sets the configuration attributes 68 // to be used for bootstrapping. 69 // This method may only be called on an EnvironInfo 70 // obtained using ConfigStorage.CreateInfo. 71 SetBootstrapConfig(map[string]interface{}) 72 73 // SetAPIEndpoint sets the API endpoint information 74 // currently associated with the environment. 75 SetAPIEndpoint(APIEndpoint) 76 77 // SetAPICreds sets the API credentials currently 78 // associated with the environment. 79 SetAPICredentials(APICredentials) 80 81 // Location returns the location of the source of the environment 82 // information in a human readable format. 83 Location() string 84 85 // Write writes the current information to persistent storage. 86 // A subsequent call to ConfigStorage.ReadInfo 87 // can retrieve it. After this call succeeds, Initialized will return true. 88 Write() error 89 90 // Destroy destroys the information associated with 91 // the environment. 92 Destroy() error 93 }