本文整理匯總了Golang中github.com/juju/juju/jujuclient.ClientStore.CurrentAccount方法的典型用法代碼示例。如果您正苦於以下問題:Golang ClientStore.CurrentAccount方法的具體用法?Golang ClientStore.CurrentAccount怎麽用?Golang ClientStore.CurrentAccount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/jujuclient.ClientStore
的用法示例。
在下文中一共展示了ClientStore.CurrentAccount方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: logout
func (c *logoutCommand) logout(store jujuclient.ClientStore, controllerName string) error {
accountName, err := store.CurrentAccount(controllerName)
if errors.IsNotFound(err) {
// Not logged in; nothing else to do.
return nil
} else if err != nil {
return errors.Trace(err)
}
accountDetails, err := store.AccountByName(controllerName, accountName)
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.Macaroon == "" && 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, accountName); err != nil {
return errors.Annotate(err, "failed to clear credentials")
}
return nil
}