Documentation ¶
Index ¶
- Variables
- func BootstrapContext(cmdContext *cmd.Context) environs.BootstrapContext
- func BootstrapContextNoVerify(cmdContext *cmd.Context) environs.BootstrapContext
- func DetectCredential(cloudName string, provider environs.EnvironProvider) (*cloud.CloudCredential, error)
- func GetCredentials(ctx *cmd.Context, store jujuclient.CredentialGetter, args GetCredentialsParams) (_ *cloud.Credential, chosenCredentialName, regionName string, _ error)
- func GetCurrentModel(store jujuclient.ClientStore) (string, error)
- func JoinModelName(controller, model string) string
- func NewGetBootstrapConfigParamsFunc(ctx *cmd.Context, store jujuclient.ClientStore, ...) ...
- func SplitModelName(name string) (controller, model string)
- func Wrap(c ModelCommand, options ...WrapOption) cmd.Command
- func WrapBase(c CommandBase) cmd.Command
- func WrapController(c ControllerCommand, options ...WrapControllerOption) cmd.Command
- type APIContext
- type APIOpener
- type AuthOpts
- type CommandBase
- type ControllerCommand
- type ControllerCommandBase
- func (c *ControllerCommandBase) ClientStore() jujuclient.ClientStore
- func (c *ControllerCommandBase) ControllerName() string
- func (c *ControllerCommandBase) ModelUUIDs(modelNames []string) ([]string, error)
- func (c *ControllerCommandBase) NewAPIRoot() (api.Connection, error)
- func (c *ControllerCommandBase) NewControllerAPIClient() (*controller.Client, error)
- func (c *ControllerCommandBase) NewModelAPIRoot(modelName string) (api.Connection, error)
- func (c *ControllerCommandBase) NewModelManagerAPIClient() (*modelmanager.Client, error)
- func (c *ControllerCommandBase) NewUserManagerAPIClient() (*usermanager.Client, error)
- func (c *ControllerCommandBase) SetAPIOpener(opener APIOpener)
- func (c *ControllerCommandBase) SetClientStore(store jujuclient.ClientStore)
- func (c *ControllerCommandBase) SetControllerName(controllerName string, allowDefault bool) error
- type GetCredentialsParams
- type JujuCommandBase
- func (c *JujuCommandBase) APIContext() (*APIContext, error)
- func (c *JujuCommandBase) APIOpen(info *api.Info, opts api.DialOpts) (api.Connection, error)
- func (c *JujuCommandBase) BakeryClient() (*httpbakery.Client, error)
- func (c *JujuCommandBase) ClearControllerMacaroons(endpoints []string) error
- func (c *JujuCommandBase) HTTPClient() (*http.Client, error)
- func (c *JujuCommandBase) NewAPIConnectionParams(store jujuclient.ClientStore, controllerName, modelName string, ...) (juju.NewAPIConnectionParams, error)
- func (c *JujuCommandBase) NewAPIRoot(store jujuclient.ClientStore, controllerName, modelName string) (api.Connection, error)
- func (c *JujuCommandBase) RefreshModels(store jujuclient.ClientStore, controllerName string) error
- func (c *JujuCommandBase) SetAPIOpen(apiOpen api.OpenFunc)
- func (c *JujuCommandBase) SetFlags(f *gnuflag.FlagSet)
- func (c *JujuCommandBase) SetModelAPI(api ModelAPI)
- type ModelAPI
- type ModelCommand
- type ModelCommandBase
- func (c *ModelCommandBase) ClientStore() jujuclient.ClientStore
- func (c *ModelCommandBase) ConnectionName() string
- func (c *ModelCommandBase) ControllerName() string
- func (c *ModelCommandBase) ModelName() string
- func (c *ModelCommandBase) NewAPIClient() (*api.Client, error)
- func (c *ModelCommandBase) NewAPIRoot() (api.Connection, error)
- func (c *ModelCommandBase) NewControllerAPIRoot() (api.Connection, error)
- func (c *ModelCommandBase) SetAPIOpener(opener APIOpener)
- func (c *ModelCommandBase) SetClientStore(store jujuclient.ClientStore)
- func (c *ModelCommandBase) SetModelName(modelName string) error
- type OpenFunc
- type QualifyingClientStore
- func (s QualifyingClientStore) ModelByName(controllerName, modelName string) (*jujuclient.ModelDetails, error)
- func (s QualifyingClientStore) QualifiedModelName(controllerName, modelName string) (string, error)
- func (s QualifyingClientStore) RemoveModel(controllerName, modelName string) error
- func (s QualifyingClientStore) SetCurrentModel(controllerName, modelName string) error
- func (s QualifyingClientStore) UpdateModel(controllerName, modelName string, details jujuclient.ModelDetails) error
- type WrapControllerOption
- type WrapOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoControllersDefined is returned by commands that operate on // a controller if there is no current controller, no controller has been // explicitly specified, and there is no default controller. ErrNoControllersDefined = errors.New(`No controllers registered. Please either create a new controller using "juju bootstrap" or connect to another controller that you have been given access to using "juju register". `) // ErrNoCurrentController is returned by commands that operate on // a controller if there is no current controller, no controller has been // explicitly specified, and there is no default controller but there are // controllers that client knows about. ErrNoCurrentController = errors.New(`No selected controller. Please use "juju switch" to select a controller. `) )
var ErrConnTimedOut = errors.New("open connection timed out")
var ( // ErrMultipleCredentials is the error returned by DetectCredential // if more than one credential is detected. ErrMultipleCredentials = errors.New("more than one credential detected") )
var ErrNoModelSpecified = errors.New(`No model in focus.
Please use "juju models" to see models available to you.
You can set current model by running "juju switch"
or specify any other model on the command line using the "-m" flag.
`)
ErrNoModelSpecified is returned by commands that operate on an environment if there is no current model, no model has been explicitly specified, and there is no default model.
Functions ¶
func BootstrapContext ¶
func BootstrapContext(cmdContext *cmd.Context) environs.BootstrapContext
BootstrapContext returns a new BootstrapContext constructed from a command Context.
func BootstrapContextNoVerify ¶
func BootstrapContextNoVerify(cmdContext *cmd.Context) environs.BootstrapContext
BootstrapContextNoVerify returns a new BootstrapContext constructed from a command Context where the validation of credentials is false.
func DetectCredential ¶
func DetectCredential(cloudName string, provider environs.EnvironProvider) (*cloud.CloudCredential, error)
DetectCredential detects credentials for the specified cloud type, and, if exactly one is detected, returns it.
If no credentials are detected, an error satisfying errors.IsNotFound will be returned. If more than one credential is detected, ErrMultipleCredentials will be returned.
func GetCredentials ¶
func GetCredentials( ctx *cmd.Context, store jujuclient.CredentialGetter, args GetCredentialsParams, ) (_ *cloud.Credential, chosenCredentialName, regionName string, _ error)
GetCredentials returns a curated set of credential values for a given cloud. The credential key values are read from the credentials store and the provider finalises the values to resolve things like json files. If region is not specified, the default credential region is used.
func GetCurrentModel ¶
func GetCurrentModel(store jujuclient.ClientStore) (string, error)
GetCurrentModel returns the name of the current Juju model.
If $JUJU_MODEL is set, use that. Otherwise, get the current controller from controllers.yaml, and then identify the current model for that controller in models.yaml. If there is no current controller, then an empty string is returned. It is not an error to have no current model.
If there is a current controller, but no current model for that controller, then GetCurrentModel will return the string "<controller>:". If there is a current model as well, it will return "<controller>:<model>". Only when $JUJU_MODEL is set, will the result possibly be unqualified.
func JoinModelName ¶
JoinModelName joins a controller and model name into a qualified model name.
func NewGetBootstrapConfigParamsFunc ¶
func NewGetBootstrapConfigParamsFunc( ctx *cmd.Context, store jujuclient.ClientStore, providerRegistry environs.ProviderRegistry, ) func(string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error)
NewGetBootstrapConfigParamsFunc returns a function that, given a controller name, returns the params needed to bootstrap a fresh copy of that controller in the given client store.
func SplitModelName ¶
SplitModelName splits a model name into its controller and model parts. If the model is unqualified, then the returned controller string will be empty, and the returned model string will be identical to the input.
func Wrap ¶
func Wrap(c ModelCommand, options ...WrapOption) cmd.Command
Wrap wraps the specified ModelCommand, returning a Command that proxies to each of the ModelCommand methods. Any provided options are applied to the wrapped command before it is returned.
func WrapBase ¶
func WrapBase(c CommandBase) cmd.Command
WrapBase wraps the specified CommandBase, returning a Command that proxies to each of the CommandBase methods.
func WrapController ¶
func WrapController(c ControllerCommand, options ...WrapControllerOption) cmd.Command
WrapController wraps the specified ControllerCommand, returning a Command that proxies to each of the ControllerCommand methods.
Types ¶
type APIContext ¶
type APIContext struct {
// contains filtered or unexported fields
}
APIContext holds the context required for making connections to APIs used by juju.
func NewAPIContext ¶
func NewAPIContext(ctxt *cmd.Context, opts *AuthOpts) (*APIContext, error)
NewAPIContext returns an API context that will use the given context for user interactions when authorizing. The returned API context must be closed after use.
If ctxt is nil, no command-line authorization will be supported.
This function is provided for use by commands that cannot use JujuCommandBase. Most clients should use that instead.
func (*APIContext) Close ¶
func (ctxt *APIContext) Close() error
Close closes the API context, saving any cookies to the persistent cookie jar.
func (*APIContext) CookieJar ¶
func (ctx *APIContext) CookieJar() http.CookieJar
CookieJar returns the cookie jar used to make HTTP requests.
func (*APIContext) NewBakeryClient ¶
func (ctx *APIContext) NewBakeryClient() *httpbakery.Client
NewBakeryClient returns a new httpbakery.Client, using the API context's persistent cookie jar and web page visitor.
type APIOpener ¶
type APIOpener interface {
Open(store jujuclient.ClientStore, controllerName, modelName string) (api.Connection, error)
}
APIOpener provides a way to open a connection to the Juju API Server through the named connection.
type AuthOpts ¶
type AuthOpts struct { // NoBrowser specifies that web-browser-based auth should // not be used when authenticating. NoBrowser bool }
AuthOpts holds flags relating to authentication.
type CommandBase ¶
CommandBase extends cmd.Command with a closeContext method. It is implicitly implemented by any type that embeds JujuCommandBase.
type ControllerCommand ¶
type ControllerCommand interface { CommandBase // SetClientStore is called prior to the wrapped command's Init method // with the default controller store. It may also be called to override the // default controller store for testing. SetClientStore(jujuclient.ClientStore) // ClientStore returns the controller store that the command is // associated with. ClientStore() jujuclient.ClientStore // SetControllerName sets the value returned by ControllerName. // It returns an error if the controller with the given name // is not found, unless the name is empty and allowDefault is true, // in which case the name of the current controller will be used. SetControllerName(controllerName string, allowDefault bool) error // ControllerName returns the name of the controller // that the command should use. ControllerName() string // SetAPIOpener allows the replacement of the default API opener, // which ends up calling NewAPIRoot SetAPIOpener(opener APIOpener) }
ControllerCommand is intended to be a base for all commands that need to operate on controllers as opposed to models.
type ControllerCommandBase ¶
type ControllerCommandBase struct { JujuCommandBase // contains filtered or unexported fields }
ControllerCommandBase is a convenience type for embedding in commands that wish to implement ControllerCommand.
func (*ControllerCommandBase) ClientStore ¶
func (c *ControllerCommandBase) ClientStore() jujuclient.ClientStore
ClientStore implements the ControllerCommand interface.
func (*ControllerCommandBase) ControllerName ¶
func (c *ControllerCommandBase) ControllerName() string
ControllerName implements the ControllerCommand interface.
func (*ControllerCommandBase) ModelUUIDs ¶
func (c *ControllerCommandBase) ModelUUIDs(modelNames []string) ([]string, error)
ModelUUIDs returns the model UUIDs for the given model names.
func (*ControllerCommandBase) NewAPIRoot ¶
func (c *ControllerCommandBase) NewAPIRoot() (api.Connection, error)
NewAPIRoot returns a restricted API for the current controller using the current credentials. Only the UserManager and ModelManager may be accessed through this API connection.
func (*ControllerCommandBase) NewControllerAPIClient ¶
func (c *ControllerCommandBase) NewControllerAPIClient() (*controller.Client, error)
NewControllerAPIClient returns an API client for the Controller on the current controller using the current credentials.
func (*ControllerCommandBase) NewModelAPIRoot ¶
func (c *ControllerCommandBase) NewModelAPIRoot(modelName string) (api.Connection, error)
NewAPIRoot returns a new connection to the API server for the named model in the specified controller.
func (*ControllerCommandBase) NewModelManagerAPIClient ¶
func (c *ControllerCommandBase) NewModelManagerAPIClient() (*modelmanager.Client, error)
NewModelManagerAPIClient returns an API client for the ModelManager on the current controller using the current credentials.
func (*ControllerCommandBase) NewUserManagerAPIClient ¶
func (c *ControllerCommandBase) NewUserManagerAPIClient() (*usermanager.Client, error)
NewUserManagerAPIClient returns an API client for the UserManager on the current controller using the current credentials.
func (*ControllerCommandBase) SetAPIOpener ¶
func (c *ControllerCommandBase) SetAPIOpener(opener APIOpener)
SetAPIOpener specifies the strategy used by the command to open the API connection.
func (*ControllerCommandBase) SetClientStore ¶
func (c *ControllerCommandBase) SetClientStore(store jujuclient.ClientStore)
SetClientStore implements the ControllerCommand interface.
func (*ControllerCommandBase) SetControllerName ¶
func (c *ControllerCommandBase) SetControllerName(controllerName string, allowDefault bool) error
SetControllerName implements ControllerCommand.SetControllerName.
type GetCredentialsParams ¶
type GetCredentialsParams struct { // Cloud is the cloud definition. Cloud cloud.Cloud // CloudRegion is the name of the region that the user has specified. // If this is empty, then GetCredentials will determine the default // region, and return that. The default region is the one set by the // user in credentials.yaml, or if there is none set, the first region // in the cloud's list. CloudRegion string // CredentialName is the name of the credential to get. CredentialName string }
GetCredentialsParams contains parameters for the GetCredentials function.
type JujuCommandBase ¶
type JujuCommandBase struct { cmd.CommandBase // contains filtered or unexported fields }
JujuCommandBase is a convenience type for embedding that need an API connection.
func (*JujuCommandBase) APIContext ¶
func (c *JujuCommandBase) APIContext() (*APIContext, error)
APIContext returns the API context used by the command. It should only be called while the Run method is being called.
The returned APIContext should not be closed (it will be closed when the Run method completes).
func (*JujuCommandBase) APIOpen ¶
func (c *JujuCommandBase) APIOpen(info *api.Info, opts api.DialOpts) (api.Connection, error)
APIOpen establishes a connection to the API server using the the given api.Info and api.DialOpts.
func (*JujuCommandBase) BakeryClient ¶
func (c *JujuCommandBase) BakeryClient() (*httpbakery.Client, error)
BakeryClient returns a macaroon bakery client that uses the same HTTP client returned by HTTPClient.
func (*JujuCommandBase) ClearControllerMacaroons ¶
func (c *JujuCommandBase) ClearControllerMacaroons(endpoints []string) error
ClearControllerMacaroons will remove all macaroons stored for the controller from the persistent cookie jar. This is called both from 'juju logout' and a failed 'juju register'.
func (*JujuCommandBase) HTTPClient ¶
func (c *JujuCommandBase) HTTPClient() (*http.Client, error)
HTTPClient returns an http.Client that contains the loaded persistent cookie jar. Note that this client is not good for connecting to the Juju API itself because it does not have the correct TLS setup - use api.Connection.HTTPClient for that.
func (*JujuCommandBase) NewAPIConnectionParams ¶
func (c *JujuCommandBase) NewAPIConnectionParams( store jujuclient.ClientStore, controllerName, modelName string, accountDetails *jujuclient.AccountDetails, ) (juju.NewAPIConnectionParams, error)
NewAPIConnectionParams returns a juju.NewAPIConnectionParams with the given arguments such that a call to juju.NewAPIConnection with the result behaves the same as a call to JujuCommandBase.NewAPIRoot with the same arguments.
func (*JujuCommandBase) NewAPIRoot ¶
func (c *JujuCommandBase) NewAPIRoot( store jujuclient.ClientStore, controllerName, modelName string, ) (api.Connection, error)
NewAPIRoot returns a new connection to the API server for the given model or controller.
func (*JujuCommandBase) RefreshModels ¶
func (c *JujuCommandBase) RefreshModels(store jujuclient.ClientStore, controllerName string) error
RefreshModels refreshes the local models cache for the current user on the specified controller.
func (*JujuCommandBase) SetAPIOpen ¶
func (c *JujuCommandBase) SetAPIOpen(apiOpen api.OpenFunc)
SetAPIOpen sets the function used for opening an API connection.
func (*JujuCommandBase) SetFlags ¶
func (c *JujuCommandBase) SetFlags(f *gnuflag.FlagSet)
SetFlags implements cmd.Command.SetFlags.
func (*JujuCommandBase) SetModelAPI ¶
func (c *JujuCommandBase) SetModelAPI(api ModelAPI)
SetModelAPI sets the api used to access model information.
type ModelCommand ¶
type ModelCommand interface { CommandBase // SetClientStore is called prior to the wrapped command's Init method // with the default controller store. It may also be called to override the // default controller store for testing. SetClientStore(jujuclient.ClientStore) // ClientStore returns the controller store that the command is // associated with. ClientStore() jujuclient.ClientStore // SetModelName sets the model name for this command. Setting the model // name will also set the related controller name. The model name can // be qualified with a controller name (controller:model), or // unqualified, in which case it will be assumed to be within the // current controller. // // SetModelName is called prior to the wrapped command's Init method // with the active model name. The model name is guaranteed // to be non-empty at entry of Init. SetModelName(modelName string) error // ModelName returns the name of the model. ModelName() string // ControllerName returns the name of the controller that contains // the model returned by ModelName(). ControllerName() string // SetAPIOpener allows the replacement of the default API opener, // which ends up calling NewAPIRoot SetAPIOpener(opener APIOpener) }
ModelCommand extends cmd.Command with a SetModelName method.
type ModelCommandBase ¶
type ModelCommandBase struct { JujuCommandBase // contains filtered or unexported fields }
ModelCommandBase is a convenience type for embedding in commands that wish to implement ModelCommand.
func (*ModelCommandBase) ClientStore ¶
func (c *ModelCommandBase) ClientStore() jujuclient.ClientStore
ClientStore implements the ModelCommand interface.
func (*ModelCommandBase) ConnectionName ¶
func (c *ModelCommandBase) ConnectionName() string
ConnectionName returns the name of the connection if there is one. It is possible that the name of the connection is empty if the connection information is supplied through command line arguments or environment variables.
func (*ModelCommandBase) ControllerName ¶
func (c *ModelCommandBase) ControllerName() string
ControllerName implements the ModelCommand interface.
func (*ModelCommandBase) ModelName ¶
func (c *ModelCommandBase) ModelName() string
ModelName implements the ModelCommand interface.
func (*ModelCommandBase) NewAPIClient ¶
func (c *ModelCommandBase) NewAPIClient() (*api.Client, error)
func (*ModelCommandBase) NewAPIRoot ¶
func (c *ModelCommandBase) NewAPIRoot() (api.Connection, error)
NewAPIRoot returns a new connection to the API server for the environment directed to the model specified on the command line.
func (*ModelCommandBase) NewControllerAPIRoot ¶
func (c *ModelCommandBase) NewControllerAPIRoot() (api.Connection, error)
NewControllerAPIRoot returns a new connection to the API server for the environment directed to the controller specified on the command line. This is for the use of model-centered commands that still want to talk to controller-only APIs.
func (*ModelCommandBase) SetAPIOpener ¶
func (c *ModelCommandBase) SetAPIOpener(opener APIOpener)
SetAPIOpener specifies the strategy used by the command to open the API connection.
func (*ModelCommandBase) SetClientStore ¶
func (c *ModelCommandBase) SetClientStore(store jujuclient.ClientStore)
SetClientStore implements the ModelCommand interface.
func (*ModelCommandBase) SetModelName ¶
func (c *ModelCommandBase) SetModelName(modelName string) error
SetModelName implements the ModelCommand interface.
type OpenFunc ¶
type OpenFunc func(jujuclient.ClientStore, string, string) (api.Connection, error)
func (OpenFunc) Open ¶
func (f OpenFunc) Open(store jujuclient.ClientStore, controllerName, modelName string) (api.Connection, error)
type QualifyingClientStore ¶
type QualifyingClientStore struct {
jujuclient.ClientStore
}
QualifyingClientStore wraps a jujuclient.ClientStore, modifying model-related methods such that they accept unqualified model names, and automatically qualify them with the logged-in user name as necessary.
func (QualifyingClientStore) ModelByName ¶
func (s QualifyingClientStore) ModelByName(controllerName, modelName string) (*jujuclient.ModelDetails, error)
Implements jujuclient.ModelGetter.
func (QualifyingClientStore) QualifiedModelName ¶
func (s QualifyingClientStore) QualifiedModelName(controllerName, modelName string) (string, error)
QualifiedModelName returns a Qualified model name, given either an unqualified or qualified model name. If the input is a fully qualified name, it is returned untouched; otherwise it is return qualified with the logged-in user name.
func (QualifyingClientStore) RemoveModel ¶
func (s QualifyingClientStore) RemoveModel(controllerName, modelName string) error
Implements jujuclient.ModelRemover.
func (QualifyingClientStore) SetCurrentModel ¶
func (s QualifyingClientStore) SetCurrentModel(controllerName, modelName string) error
Implements jujuclient.ModelUpdater.
func (QualifyingClientStore) UpdateModel ¶
func (s QualifyingClientStore) UpdateModel(controllerName, modelName string, details jujuclient.ModelDetails) error
Implements jujuclient.ModelUpdater.
type WrapControllerOption ¶
type WrapControllerOption func(*sysCommandWrapper)
WrapControllerOption specifies an option to the WrapController function.
var ( // WrapControllerSkipControllerFlags specifies that the -c // and --controller flag flags should not be defined. WrapControllerSkipControllerFlags WrapControllerOption = wrapControllerSkipControllerFlags // WrapSkipDefaultModel specifies that no default controller should // be used. WrapControllerSkipDefaultController WrapControllerOption = wrapControllerSkipDefaultController )
Options for the WrapController call.
func WrapControllerAPIOpener ¶
func WrapControllerAPIOpener(opener APIOpener) WrapControllerOption
WrapControllerAPIOpener specifies that the given APIOpener should should be used to open the API connection when NewAPIRoot or NewControllerAPIRoot are called.
type WrapOption ¶
type WrapOption func(*modelCommandWrapper)
WrapOption specifies an option to the Wrap function.
var ( // WrapSkipModelFlags specifies that the -m and --model flags // should not be defined. WrapSkipModelFlags WrapOption = wrapSkipModelFlags // WrapSkipDefaultModel specifies that no default model should // be used. WrapSkipDefaultModel WrapOption = wrapSkipDefaultModel )
Options for the Wrap function.