本文整理匯總了Golang中github.com/juju/juju/jujuclient.ClientStore.AccountDetails方法的典型用法代碼示例。如果您正苦於以下問題:Golang ClientStore.AccountDetails方法的具體用法?Golang ClientStore.AccountDetails怎麽用?Golang ClientStore.AccountDetails使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/jujuclient.ClientStore
的用法示例。
在下文中一共展示了ClientStore.AccountDetails方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RefreshModels
// RefreshModels refreshes the local models cache for the current user
// on the specified controller.
func (c *JujuCommandBase) RefreshModels(store jujuclient.ClientStore, controllerName string) error {
modelManager, err := c.modelAPI(store, controllerName)
if err != nil {
return errors.Trace(err)
}
defer modelManager.Close()
accountDetails, err := store.AccountDetails(controllerName)
if err != nil {
return errors.Trace(err)
}
models, err := modelManager.ListModels(accountDetails.User)
if err != nil {
return errors.Trace(err)
}
for _, model := range models {
modelDetails := jujuclient.ModelDetails{model.UUID}
owner := names.NewUserTag(model.Owner)
modelName := jujuclient.JoinOwnerModelName(owner, model.Name)
if err := store.UpdateModel(controllerName, modelName, modelDetails); err != nil {
return errors.Trace(err)
}
}
return nil
}
示例2: NewAPIRoot
// NewAPIRoot returns a new connection to the API server for the given
// model or controller.
func (c *JujuCommandBase) NewAPIRoot(
store jujuclient.ClientStore,
controllerName, modelName string,
) (api.Connection, error) {
accountDetails, err := store.AccountDetails(controllerName)
if err != nil && !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
// If there are no account details or there's no logged-in
// user or the user is external, then trigger macaroon authentication
// by using an empty AccountDetails.
if accountDetails == nil || accountDetails.User == "" {
accountDetails = &jujuclient.AccountDetails{}
} else {
u := names.NewUserTag(accountDetails.User)
if !u.IsLocal() {
accountDetails = &jujuclient.AccountDetails{}
}
}
param, err := c.NewAPIConnectionParams(
store, controllerName, modelName, accountDetails,
)
if err != nil {
return nil, errors.Trace(err)
}
conn, err := juju.NewAPIConnection(param)
if modelName != "" && params.ErrCode(err) == params.CodeModelNotFound {
return nil, c.missingModelError(store, controllerName, modelName)
}
return conn, err
}
示例3: logout
func (c *logoutCommand) logout(store jujuclient.ClientStore, controllerName string) error {
accountDetails, err := store.AccountDetails(controllerName)
if errors.IsNotFound(err) {
// Not logged in; nothing else to do.
return nil
} else if err != nil {
return errors.Trace(err)
}
// We first ensure that the user has a macaroon, which implies
// they know their password. If they have just bootstrapped,
// they will have a randomly generated password which they will
// be unaware of.
if accountDetails.Password != "" && !c.Force {
return errors.New(`preventing account loss
It appears that you have not changed the password for
your account. If this is the case, change the password
first before logging out, so that you can log in again
afterwards. To change your password, run the command
"juju change-user-password".
If you are sure you want to log out, and it is safe to
clear the credentials from the client, then you can run
this command again with the "--force" flag.
`)
}
// Remove the account credentials.
if err := store.RemoveAccount(controllerName); err != nil {
return errors.Annotate(err, "failed to clear credentials")
}
return nil
}
示例4: newCacheStore
func newCacheStore(store jujuclient.ClientStore) (*cacheStore, error) {
controllers, err := store.AllControllers()
if err != nil {
return nil, errors.Trace(err)
}
accounts := make(map[string]jujuclient.AccountDetails)
for controller := range controllers {
acct, err := store.AccountDetails(controller)
if err != nil {
if !errors.IsNotFound(err) {
return nil, errors.Annotatef(err, "cannot get account details for %q", controller)
}
} else {
accounts[controller] = *acct
}
}
return &cacheStore{
accounts: accounts,
origStore: store,
controllers: controllers,
updatedAccounts: make(map[string]bool),
}, nil
}
示例5: newAPIConnectionFromNames
func newAPIConnectionFromNames(
c *gc.C,
controller, model string,
store jujuclient.ClientStore,
apiOpen api.OpenFunc,
) (api.Connection, error) {
params := juju.NewAPIConnectionParams{
Store: store,
ControllerName: controller,
DialOpts: api.DefaultDialOpts(),
OpenAPI: apiOpen,
}
accountDetails, err := store.AccountDetails(controller)
if !errors.IsNotFound(err) {
c.Assert(err, jc.ErrorIsNil)
params.AccountDetails = accountDetails
}
if model != "" {
modelDetails, err := store.ModelByName(controller, model)
c.Assert(err, jc.ErrorIsNil)
params.ModelUUID = modelDetails.ModelUUID
}
return juju.NewAPIConnection(params)
}