github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/jujuclient/interface.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package jujuclient
     5  
     6  import "github.com/juju/juju/cloud"
     7  
     8  // ControllerDetails holds the details needed to connect to a controller.
     9  type ControllerDetails struct {
    10  	// UnresolvedAPIEndpoints holds a list of API addresses which may
    11  	// contain unresolved hostnames. It's used to compare more recent
    12  	// API addresses before resolving hostnames to determine if the
    13  	// cached addresses have changed and therefore perform (a possibly
    14  	// slow) local DNS resolution before comparing them against Addresses.
    15  	UnresolvedAPIEndpoints []string `yaml:"unresolved-api-endpoints,flow"`
    16  
    17  	// ControllerUUID is the unique ID for the controller.
    18  	ControllerUUID string `yaml:"uuid"`
    19  
    20  	// APIEndpoints holds a list of API addresses. It may not be
    21  	// current, and it will be empty if the environment has not been
    22  	// bootstrapped.
    23  	APIEndpoints []string `yaml:"api-endpoints,flow"`
    24  
    25  	// CACert is a security certificate for this controller.
    26  	CACert string `yaml:"ca-cert"`
    27  }
    28  
    29  // ModelDetails holds details of a model.
    30  type ModelDetails struct {
    31  	// ModelUUID is the unique ID for the model.
    32  	ModelUUID string `yaml:"uuid"`
    33  }
    34  
    35  // AccountDetails holds details of an account.
    36  type AccountDetails struct {
    37  	// User is the username for the account.
    38  	User string `yaml:"user"`
    39  
    40  	// Password is the password for the account.
    41  	Password string `yaml:"password,omitempty"`
    42  
    43  	// Macaroon is a time-limited macaroon that may be
    44  	// used to log in. This string is the JSON-encoding
    45  	// of a gopkg.in/macaroon.v1.Macaroon.
    46  	Macaroon string `yaml:"macaroon,omitempty"`
    47  }
    48  
    49  // BootstrapConfig holds the configuration used to bootstrap a controller.
    50  //
    51  // This includes all non-sensitive information required to regenerate the
    52  // bootstrap configuration. A reference to the credential used will be
    53  // stored, rather than the credential itself.
    54  type BootstrapConfig struct {
    55  	// Config is the base configuration for the provider. This should
    56  	// be updated with the region, endpoint and credentials.
    57  	Config map[string]interface{} `yaml:"config"`
    58  
    59  	// Credential is the name of the credential used to bootstrap.
    60  	//
    61  	// This will be empty if an auto-detected credential was used.
    62  	Credential string `yaml:"credential,omitempty"`
    63  
    64  	// Cloud is the name of the cloud to create the Juju controller in.
    65  	Cloud string `yaml:"cloud"`
    66  
    67  	// CloudRegion is the name of the region of the cloud to create
    68  	// the Juju controller in. This will be empty for clouds without
    69  	// regions.
    70  	CloudRegion string `yaml:"region,omitempty"`
    71  
    72  	// CloudEndpoint is the location of the primary API endpoint to
    73  	// use when communicating with the cloud.
    74  	CloudEndpoint string `yaml:"endpoint,omitempty"`
    75  
    76  	// CloudStorageEndpoint is the location of the API endpoint to use
    77  	// when communicating with the cloud's storage service. This will
    78  	// be empty for clouds that have no cloud-specific API endpoint.
    79  	CloudStorageEndpoint string `yaml:"storage-endpoint,omitempty"`
    80  }
    81  
    82  // ControllerUpdater stores controller details.
    83  type ControllerUpdater interface {
    84  	// UpdateController adds the given controller to the controller
    85  	// collection.
    86  	//
    87  	// If the controller does not already exist, it will be added.
    88  	// Otherwise, it will be overwritten with the new details.
    89  	UpdateController(controllerName string, details ControllerDetails) error
    90  }
    91  
    92  // ControllerRemover removes controllers.
    93  type ControllerRemover interface {
    94  	// RemoveController removes the controller with the given name from the
    95  	// controllers collection. Any other controllers with matching UUIDs
    96  	// will also be removed.
    97  	//
    98  	// Removing controllers will remove all information related to those
    99  	// controllers (models, accounts, bootstrap config.)
   100  	RemoveController(controllerName string) error
   101  }
   102  
   103  // ControllerGetter gets controllers.
   104  type ControllerGetter interface {
   105  	// AllControllers gets all controllers.
   106  	AllControllers() (map[string]ControllerDetails, error)
   107  
   108  	// ControllerByName returns the controller with the specified name.
   109  	// If there exists no controller with the specified name, an error
   110  	// satisfying errors.IsNotFound will be returned.
   111  	ControllerByName(controllerName string) (*ControllerDetails, error)
   112  }
   113  
   114  // ModelUpdater stores model details.
   115  type ModelUpdater interface {
   116  	// UpdateModel adds the given model to the model collection.
   117  	//
   118  	// If the model does not already exist, it will be added.
   119  	// Otherwise, it will be overwritten with the new details.
   120  	UpdateModel(controllerName, accountName, modelName string, details ModelDetails) error
   121  
   122  	// SetCurrentModel sets the name of the current model for
   123  	// the specified controller and account. If there exists no
   124  	// model with the specified names, an error satisfing
   125  	// errors.IsNotFound will be returned.
   126  	SetCurrentModel(controllerName, accountName, modelName string) error
   127  }
   128  
   129  // ModelRemover removes models.
   130  type ModelRemover interface {
   131  	// RemoveModel removes the model with the given controller, account,
   132  	// and model names from the models collection. If there is no model
   133  	// with the specified names, an errors satisfying errors.IsNotFound
   134  	// will be returned.
   135  	RemoveModel(controllerName, accountName, modelName string) error
   136  }
   137  
   138  // ModelGetter gets models.
   139  type ModelGetter interface {
   140  	// AllModels gets all models for the specified controller and
   141  	// account.
   142  	//
   143  	// If there is no controller or account with the specified
   144  	// names, or no models cached for the controller and account,
   145  	// an error satisfying errors.IsNotFound will be returned.
   146  	AllModels(controllerName, accountName string) (map[string]ModelDetails, error)
   147  
   148  	// CurrentModel returns the name of the current model for
   149  	// the specified controller and account. If there is no current
   150  	// model for the controller and account, an error satisfying
   151  	// errors.IsNotFound is returned.
   152  	CurrentModel(controllerName, accountName string) (string, error)
   153  
   154  	// ModelByName returns the model with the specified controller,
   155  	// account, and model names. If there exists no model with the
   156  	// specified names, an error satisfying errors.IsNotFound will
   157  	// be returned.
   158  	ModelByName(controllerName, accountName, modelName string) (*ModelDetails, error)
   159  }
   160  
   161  // AccountUpdater stores account details.
   162  type AccountUpdater interface {
   163  	// UpdateAccount adds the given account to the account collection.
   164  	//
   165  	// If the account does not already exist, it will be added.
   166  	// Otherwise, it will be overwritten with the new details.
   167  	//
   168  	// It is currently not permitted to create multiple account entries
   169  	// for a controller; doing so will result in an error satisfying
   170  	// errors.IsAlreadyExists.
   171  	UpdateAccount(controllerName, accountName string, details AccountDetails) error
   172  
   173  	// SetCurrentAccount sets the name of the current account for
   174  	// the specified controller. If there exists no account with
   175  	// the specified names, an error satisfing errors.IsNotFound
   176  	// will be returned.
   177  	SetCurrentAccount(controllerName, accountName string) error
   178  }
   179  
   180  // AccountRemover removes accounts.
   181  type AccountRemover interface {
   182  	// RemoveAccount removes the account with the given controller and account
   183  	// names from the accounts collection. If there is no account with the
   184  	// specified names, an errors satisfying errors.IsNotFound will be
   185  	// returned.
   186  	RemoveAccount(controllerName, accountName string) error
   187  }
   188  
   189  // AccountGetter gets accounts.
   190  type AccountGetter interface {
   191  	// AllAccounts gets all accounts for the specified controller.
   192  	//
   193  	// If there is no controller with the specified name, or
   194  	// no accounts cached for the controller, an error satisfying
   195  	// errors.IsNotFound will be returned.
   196  	AllAccounts(controllerName string) (map[string]AccountDetails, error)
   197  
   198  	// CurrentAccount returns the name of the current account for
   199  	// the specified controller. If there is no current account
   200  	// for the controller, an error satisfying errors.IsNotFound
   201  	// is returned.
   202  	CurrentAccount(controllerName string) (string, error)
   203  
   204  	// AccountByName returns the account with the specified controller
   205  	// and account names. If there exists no account with the specified
   206  	// names, an error satisfying errors.IsNotFound will be returned.
   207  	AccountByName(controllerName, accountName string) (*AccountDetails, error)
   208  }
   209  
   210  // CredentialGetter gets credentials.
   211  type CredentialGetter interface {
   212  	// CredentialForCloud gets credentials for the named cloud.
   213  	CredentialForCloud(string) (*cloud.CloudCredential, error)
   214  
   215  	// AllCredentials gets all credentials.
   216  	AllCredentials() (map[string]cloud.CloudCredential, error)
   217  }
   218  
   219  // CredentialUpdater stores credentials.
   220  type CredentialUpdater interface {
   221  	// UpdateCredential adds the given credentials to the credentials
   222  	// collection.
   223  	//
   224  	// If the cloud or credential name does not already exist, it will be added.
   225  	// Otherwise, it will be overwritten with the new details.
   226  	UpdateCredential(cloudName string, details cloud.CloudCredential) error
   227  }
   228  
   229  // BootstrapConfigUpdater stores bootstrap config.
   230  type BootstrapConfigUpdater interface {
   231  	// UpdateBootstrapConfig adds the given bootstrap config to the
   232  	// bootstrap config collection for the controller with the given
   233  	// name.
   234  	//
   235  	// If the bootstrap config does not already exist, it will be added.
   236  	// Otherwise, it will be overwritten with the new value.
   237  	UpdateBootstrapConfig(controller string, cfg BootstrapConfig) error
   238  }
   239  
   240  // BootstrapConfigGetter gets bootstrap config.
   241  type BootstrapConfigGetter interface {
   242  	// BootstrapConfigForController gets bootstrap config for the named
   243  	// controller.
   244  	BootstrapConfigForController(string) (*BootstrapConfig, error)
   245  }
   246  
   247  // ControllerStore is an amalgamation of ControllerUpdater, ControllerRemover,
   248  // and ControllerGetter.
   249  type ControllerStore interface {
   250  	ControllerUpdater
   251  	ControllerRemover
   252  	ControllerGetter
   253  }
   254  
   255  // ModelStore is an amalgamation of ModelUpdater, ModelRemover, and ModelGetter.
   256  type ModelStore interface {
   257  	ModelUpdater
   258  	ModelRemover
   259  	ModelGetter
   260  }
   261  
   262  // AccountStore is an amalgamation of AccountUpdater, AccountRemover, and AccountGetter.
   263  type AccountStore interface {
   264  	AccountUpdater
   265  	AccountRemover
   266  	AccountGetter
   267  }
   268  
   269  // CredentialStore is an amalgamation of CredentialsUpdater, and CredentialsGetter.
   270  type CredentialStore interface {
   271  	CredentialGetter
   272  	CredentialUpdater
   273  }
   274  
   275  // BootstrapConfigStore is an amalgamation of BootstrapConfigUpdater and
   276  // BootstrapConfigGetter.
   277  type BootstrapConfigStore interface {
   278  	BootstrapConfigUpdater
   279  	BootstrapConfigGetter
   280  }
   281  
   282  // ClientStore is an amalgamation of AccountStore, BootstrapConfigStore,
   283  // ControllerStore, CredentialStore, and ModelStore.
   284  type ClientStore interface {
   285  	AccountStore
   286  	BootstrapConfigStore
   287  	ControllerStore
   288  	CredentialStore
   289  	ModelStore
   290  }