本文整理汇总了Golang中github.com/juju/juju/environs/configstore.APICredentials类的典型用法代码示例。如果您正苦于以下问题:Golang APICredentials类的具体用法?Golang APICredentials怎么用?Golang APICredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了APICredentials类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:imoapps,项目名称:juju,代码行数:61,代码来源:change_password.go
示例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
}
开发者ID:Pankov404,项目名称:juju,代码行数:59,代码来源:change_password.go
示例3: TestWrite
func (s *interfaceSuite) TestWrite(c *gc.C) {
store := s.NewStore(c)
// Create the info.
info := store.CreateInfo("somemodel")
// Set it up with some actual data and write it out.
expectCreds := configstore.APICredentials{
User: "foobie",
Password: "bletch",
}
info.SetAPICredentials(expectCreds)
expectEndpoint := configstore.APIEndpoint{
Addresses: []string{"0.1.2.3"},
Hostnames: []string{"example.invalid"},
CACert: "a cert",
ModelUUID: "dead-beef",
}
info.SetAPIEndpoint(expectEndpoint)
err := info.Write()
c.Assert(err, jc.ErrorIsNil)
c.Assert(info.Initialized(), jc.IsTrue)
// Check we can read the information back
info, err = store.ReadInfo("somemodel")
c.Assert(err, jc.ErrorIsNil)
c.Assert(info.APICredentials(), gc.DeepEquals, expectCreds)
c.Assert(info.APIEndpoint(), gc.DeepEquals, expectEndpoint)
// Change the information and write it again.
expectCreds.User = "arble"
info.SetAPICredentials(expectCreds)
err = info.Write()
c.Assert(err, jc.ErrorIsNil)
// Check we can read the information back
info, err = store.ReadInfo("somemodel")
c.Assert(err, jc.ErrorIsNil)
c.Assert(info.APICredentials(), gc.DeepEquals, expectCreds)
}
开发者ID:pmatulis,项目名称:juju,代码行数:42,代码来源:interface_test.go
注:本文中的github.com/juju/juju/environs/configstore.APICredentials类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论