本文整理汇总了Golang中github.com/juju/juju/environs/configstore.APICredentials.Password方法的典型用法代码示例。如果您正苦于以下问题:Golang APICredentials.Password方法的具体用法?Golang APICredentials.Password怎么用?Golang APICredentials.Password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/environs/configstore.APICredentials
的用法示例。
在下文中一共展示了APICredentials.Password方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
// Run implements Command.Run.
func (c *changePasswordCommand) Run(ctx *cmd.Context) error {
if c.api == nil {
api, err := c.NewUserManagerAPIClient()
if err != nil {
return errors.Trace(err)
}
c.api = api
defer c.api.Close()
}
password, err := c.generateOrReadPassword(ctx, c.Generate)
if err != nil {
return errors.Trace(err)
}
var writer EnvironInfoCredsWriter
var creds configstore.APICredentials
if c.User == "" {
// We get the creds writer before changing the password just to
// minimise the things that could go wrong after changing the password
// in the server.
if c.writer == nil {
writer, err = c.ConnectionInfo()
if err != nil {
return errors.Trace(err)
}
} else {
writer = c.writer
}
creds = writer.APICredentials()
} else {
creds.User = c.User
}
oldPassword := creds.Password
creds.Password = password
if err = c.api.SetPassword(creds.User, password); err != nil {
return block.ProcessBlockedError(err, block.BlockChange)
}
if c.User != "" {
return writeServerFile(c, ctx, c.User, password, c.OutPath)
}
writer.SetAPICredentials(creds)
if err := writer.Write(); err != nil {
logger.Errorf("updating the cached credentials failed, reverting to original password")
setErr := c.api.SetPassword(creds.User, oldPassword)
if setErr != nil {
logger.Errorf("failed to set password back, you will need to edit your environments file by hand to specify the password: %q", password)
return errors.Annotate(setErr, "failed to set password back")
}
return errors.Annotate(err, "failed to write new password to environments file")
}
ctx.Infof("Your password has been updated.")
return nil
}
示例2: Run
// Run implements Command.Run.
func (c *ChangePasswordCommand) Run(ctx *cmd.Context) error {
var err error
c.Password, err = c.generateOrReadPassword(ctx, c.Generate)
if err != nil {
return errors.Trace(err)
}
var credsWriter EnvironInfoCredsWriter
var creds configstore.APICredentials
if c.User == "" {
// We get the creds writer before changing the password just to
// minimise the things that could go wrong after changing the password
// in the server.
credsWriter, err = getEnvironInfoWriter(c)
if err != nil {
return errors.Trace(err)
}
creds, err = getConnectionCredentials(c)
if err != nil {
return errors.Trace(err)
}
} else {
creds.User = c.User
}
client, err := getChangePasswordAPI(c)
if err != nil {
return err
}
defer client.Close()
oldPassword := creds.Password
creds.Password = c.Password
err = client.SetPassword(creds.User, c.Password)
if err != nil {
return block.ProcessBlockedError(err, block.BlockChange)
}
if c.User != "" {
return c.writeEnvironmentFile(ctx)
}
credsWriter.SetAPICredentials(creds)
if err := credsWriter.Write(); err != nil {
logger.Errorf("updating the environments file failed, reverting to original password")
setErr := client.SetPassword(creds.User, oldPassword)
if setErr != nil {
logger.Errorf("failed to set password back, you will need to edit your environments file by hand to specify the password: %q", c.Password)
return errors.Annotate(setErr, "failed to set password back")
}
return errors.Annotate(err, "failed to write new password to environments file")
}
ctx.Infof("Your password has been updated.")
return nil
}