launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/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  
    24  // APICredentials hold credentials for connecting to an API endpoint.
    25  type APICredentials struct {
    26  	// User holds the name of the user to connect as.
    27  	User     string
    28  	Password string
    29  }
    30  
    31  // Storage stores environment configuration data.
    32  type Storage interface {
    33  	// ReadInfo reads information associated with
    34  	// the environment with the given name.
    35  	// If there is no such information, it will
    36  	// return an errors.NotFound error.
    37  	ReadInfo(envName string) (EnvironInfo, error)
    38  
    39  	// CreateInfo creates some uninitialized information associated
    40  	// with the environment with the given name.
    41  	// It return ErrAlreadyExists if the
    42  	// information has already been created.
    43  	CreateInfo(envName string) (EnvironInfo, error)
    44  }
    45  
    46  // EnvironInfo holds information associated with an environment.
    47  type EnvironInfo interface {
    48  	// Initialized returns whether the environment information has
    49  	// been initialized. It will return true for EnvironInfo instances
    50  	// that have been created but not written.
    51  	Initialized() bool
    52  
    53  	// BootstrapConfig returns the configuration attributes
    54  	// that an environment will be bootstrapped with.
    55  	BootstrapConfig() map[string]interface{}
    56  
    57  	// APIEndpoint returns the current API endpoint information.
    58  	APIEndpoint() APIEndpoint
    59  
    60  	// APICredentials returns the current API credentials.
    61  	APICredentials() APICredentials
    62  
    63  	// SetBootstrapConfig sets the configuration attributes
    64  	// to be used for bootstrapping.
    65  	// This method may only be called on an EnvironInfo
    66  	// obtained using ConfigStorage.CreateInfo.
    67  	SetBootstrapConfig(map[string]interface{})
    68  
    69  	// SetAPIEndpoint sets the API endpoint information
    70  	// currently associated with the environment.
    71  	SetAPIEndpoint(APIEndpoint)
    72  
    73  	// SetAPICreds sets the API credentials currently
    74  	// associated with the environment.
    75  	SetAPICredentials(APICredentials)
    76  
    77  	// Write writes the current information to persistent storage.
    78  	// A subsequent call to ConfigStorage.ReadInfo
    79  	// can retrieve it. After this call succeeds, Initialized will return true.
    80  	Write() error
    81  
    82  	// Destroy destroys the information associated with
    83  	// the environment.
    84  	Destroy() error
    85  }