本文整理汇总了Golang中github.com/wallyworld/core/utils.RandomPassword函数的典型用法代码示例。如果您正苦于以下问题:Golang RandomPassword函数的具体用法?Golang RandomPassword怎么用?Golang RandomPassword使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandomPassword函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMachineLoginStartsPinger
func (s *serverSuite) TestMachineLoginStartsPinger(c *gc.C) {
// This is the same steps as OpenAPIAsNewMachine but we need to assert
// the agent is not alive before we actually open the API.
// Create a new machine to verify "agent alive" behavior.
machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = machine.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = machine.SetPassword(password)
c.Assert(err, gc.IsNil)
// Not alive yet.
s.assertAlive(c, machine, false)
// Login as the machine agent of the created machine.
st := s.OpenAPIAsMachine(c, machine.Tag(), password, "fake_nonce")
// Make sure the pinger has started.
s.assertAlive(c, machine, true)
// Now make sure it stops when connection is closed.
c.Assert(st.Close(), gc.IsNil)
// Sync, then wait for a bit to make sure the state is updated.
s.State.StartSync()
<-time.After(coretesting.ShortWait)
s.State.StartSync()
s.assertAlive(c, machine, false)
}
开发者ID:jameinel,项目名称:core,代码行数:32,代码来源:server_test.go
示例2: SetUpTest
func (s *RelationerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
var err error
s.svc = s.AddTestingService(c, "u", s.AddTestingCharm(c, "riak"))
c.Assert(err, gc.IsNil)
rels, err := s.svc.Relations()
c.Assert(err, gc.IsNil)
c.Assert(rels, gc.HasLen, 1)
s.rel = rels[0]
_, unit := s.AddRelationUnit(c, "u/0")
s.dirPath = c.MkDir()
s.dir, err = relation.ReadStateDir(s.dirPath, s.rel.Id())
c.Assert(err, gc.IsNil)
s.hooks = make(chan hook.Info)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = unit.SetPassword(password)
c.Assert(err, gc.IsNil)
s.st = s.OpenAPIAs(c, unit.Tag(), password)
s.uniter = s.st.Uniter()
c.Assert(s.uniter, gc.NotNil)
apiUnit, err := s.uniter.Unit(unit.Tag())
c.Assert(err, gc.IsNil)
apiRel, err := s.uniter.Relation(s.rel.Tag())
c.Assert(err, gc.IsNil)
s.apiRelUnit, err = apiRel.Unit(apiUnit)
c.Assert(err, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:30,代码来源:relationer_test.go
示例3: SetUpTest
func (s *ContextRelationSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
ch := s.AddTestingCharm(c, "riak")
var err error
s.svc = s.AddTestingService(c, "u", ch)
rels, err := s.svc.Relations()
c.Assert(err, gc.IsNil)
c.Assert(rels, gc.HasLen, 1)
s.rel = rels[0]
unit, err := s.svc.AddUnit()
c.Assert(err, gc.IsNil)
s.ru, err = s.rel.Unit(unit)
c.Assert(err, gc.IsNil)
err = s.ru.EnterScope(nil)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = unit.SetPassword(password)
c.Assert(err, gc.IsNil)
s.st = s.OpenAPIAs(c, unit.Tag(), password)
s.uniter = s.st.Uniter()
c.Assert(s.uniter, gc.NotNil)
apiRel, err := s.uniter.Relation(s.rel.Tag())
c.Assert(err, gc.IsNil)
apiUnit, err := s.uniter.Unit(unit.Tag())
c.Assert(err, gc.IsNil)
s.apiRelUnit, err = apiRel.Unit(apiUnit)
c.Assert(err, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:31,代码来源:context_test.go
示例4: Run
func (c *AddUserCommand) Run(ctx *cmd.Context) error {
store, err := configstore.Default()
if err != nil {
return fmt.Errorf("cannot open environment info storage: %v", err)
}
storeInfo, err := store.ReadInfo(c.EnvName)
if err != nil {
return err
}
client, err := juju.NewUserManagerClient(c.EnvName)
if err != nil {
return err
}
defer client.Close()
if c.GeneratePassword {
c.Password, err = utils.RandomPassword()
if err != nil {
return fmt.Errorf("Failed to generate password: %v", err)
}
}
outputInfo := configstore.EnvironInfoData{}
outputInfo.User = c.User
outputInfo.Password = c.Password
outputInfo.StateServers = storeInfo.APIEndpoint().Addresses
outputInfo.CACert = storeInfo.APIEndpoint().CACert
err = c.out.Write(ctx, outputInfo)
if err != nil {
return err
}
return client.AddUser(c.User, c.Password)
}
开发者ID:jameinel,项目名称:core,代码行数:31,代码来源:adduser.go
示例5: TestUnitLoginStartsPinger
func (s *serverSuite) TestUnitLoginStartsPinger(c *gc.C) {
// Create a new service and unit to verify "agent alive" behavior.
service := s.AddTestingService(c, "wordpress", s.AddTestingCharm(c, "wordpress"))
unit, err := service.AddUnit()
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = unit.SetPassword(password)
c.Assert(err, gc.IsNil)
// Not alive yet.
s.assertAlive(c, unit, false)
// Login as the unit agent of the created unit.
st := s.OpenAPIAs(c, unit.Tag(), password)
// Make sure the pinger has started.
s.assertAlive(c, unit, true)
// Now make sure it stops when connection is closed.
c.Assert(st.Close(), gc.IsNil)
// Sync, then wait for a bit to make sure the state is updated.
s.State.StartSync()
<-time.After(coretesting.ShortWait)
s.State.StartSync()
s.assertAlive(c, unit, false)
}
开发者ID:jameinel,项目名称:core,代码行数:29,代码来源:server_test.go
示例6: TestRandomPassword
func (passwordSuite) TestRandomPassword(c *gc.C) {
p, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
if len(p) < 18 {
c.Errorf("password too short: %q", p)
}
c.Assert(p, gc.Matches, base64Chars)
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:password_test.go
示例7: SetUpTest
func (s *authHttpSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
user, err := s.State.AddUser("joe", password)
c.Assert(err, gc.IsNil)
s.userTag = user.Tag()
s.password = password
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:charms_test.go
示例8: APILogin
func (s *FilterSuite) APILogin(c *gc.C, unit *state.Unit) {
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = unit.SetPassword(password)
c.Assert(err, gc.IsNil)
s.st = s.OpenAPIAs(c, unit.Tag(), password)
s.uniter = s.st.Uniter()
c.Assert(s.uniter, gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:9,代码来源:filter_test.go
示例9: SetUpTest
func (s *unitSuite) SetUpTest(c *gc.C) {
var err error
s.JujuConnSuite.SetUpTest(c)
svc := s.AddTestingService(c, "wordpress", s.AddTestingCharm(c, "wordpress"))
s.unit, err = svc.AddUnit()
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = s.unit.SetPassword(password)
s.st = s.OpenAPIAs(c, s.unit.Tag(), password)
}
开发者ID:jameinel,项目名称:core,代码行数:12,代码来源:unit_test.go
示例10: TestOpenAsMachineErrors
func (s *serverSuite) TestOpenAsMachineErrors(c *gc.C) {
assertNotProvisioned := func(err error) {
c.Assert(err, gc.NotNil)
c.Assert(err, jc.Satisfies, params.IsCodeNotProvisioned)
c.Assert(err, gc.ErrorMatches, `machine \d+ is not provisioned`)
}
stm, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = stm.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = stm.SetPassword(password)
c.Assert(err, gc.IsNil)
// This does almost exactly the same as OpenAPIAsMachine but checks
// for failures instead.
_, info, err := s.APIConn.Environ.StateInfo()
info.Tag = stm.Tag()
info.Password = password
info.Nonce = "invalid-nonce"
st, err := api.Open(info, fastDialOpts)
assertNotProvisioned(err)
c.Assert(st, gc.IsNil)
// Try with empty nonce as well.
info.Nonce = ""
st, err = api.Open(info, fastDialOpts)
assertNotProvisioned(err)
c.Assert(st, gc.IsNil)
// Finally, with the correct one succeeds.
info.Nonce = "fake_nonce"
st, err = api.Open(info, fastDialOpts)
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
st.Close()
// Now add another machine, intentionally unprovisioned.
stm1, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = stm1.SetPassword(password)
c.Assert(err, gc.IsNil)
// Try connecting, it will fail.
info.Tag = stm1.Tag()
info.Nonce = ""
st, err = api.Open(info, fastDialOpts)
assertNotProvisioned(err)
c.Assert(st, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:51,代码来源:server_test.go
示例11: SetUpTest
func (s *unitUpgraderSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.rawMachine, _, _, s.rawUnit = s.addMachineServiceCharmAndUnit(c, "wordpress")
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = s.rawUnit.SetPassword(password)
c.Assert(err, gc.IsNil)
s.stateAPI = s.OpenAPIAs(c, s.rawUnit.Tag(), password)
// Create the upgrader facade.
s.st = s.stateAPI.Upgrader()
c.Assert(s.st, gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:14,代码来源:unitupgrader_test.go
示例12: OpenAPIAsNewMachine
// OpenAPIAsNewMachine creates a new machine entry that lives in system state,
// and then uses that to open the API. The returned *api.State should not be
// closed by the caller as a cleanup function has been registered to do that.
// The machine will run the supplied jobs; if none are given, JobHostUnits is assumed.
func (s *JujuConnSuite) OpenAPIAsNewMachine(c *gc.C, jobs ...state.MachineJob) (*api.State, *state.Machine) {
if len(jobs) == 0 {
jobs = []state.MachineJob{state.JobHostUnits}
}
machine, err := s.State.AddMachine("quantal", jobs...)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = machine.SetPassword(password)
c.Assert(err, gc.IsNil)
err = machine.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
return s.openAPIAs(c, machine.Tag(), password, "fake_nonce"), machine
}
开发者ID:jameinel,项目名称:core,代码行数:18,代码来源:conn.go
示例13: TestStop
func (s *serverSuite) TestStop(c *gc.C) {
// Start our own instance of the server so we have
// a handle on it to stop it.
srv, err := apiserver.NewServer(
s.State, "localhost:0",
[]byte(coretesting.ServerCert), []byte(coretesting.ServerKey),
"", "")
c.Assert(err, gc.IsNil)
defer srv.Stop()
stm, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = stm.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = stm.SetPassword(password)
c.Assert(err, gc.IsNil)
// Note we can't use openAs because we're not connecting to
// s.APIConn.
apiInfo := &api.Info{
Tag: stm.Tag(),
Password: password,
Nonce: "fake_nonce",
Addrs: []string{srv.Addr()},
CACert: coretesting.CACert,
}
st, err := api.Open(apiInfo, fastDialOpts)
c.Assert(err, gc.IsNil)
defer st.Close()
_, err = st.Machiner().Machine(stm.Tag())
c.Assert(err, gc.IsNil)
err = srv.Stop()
c.Assert(err, gc.IsNil)
_, err = st.Machiner().Machine(stm.Tag())
// The client has not necessarily seen the server shutdown yet,
// so there are two possible errors.
if err != rpc.ErrShutdown && err != io.ErrUnexpectedEOF {
c.Fatalf("unexpected error from request: %v", err)
}
// Check it can be stopped twice.
err = srv.Stop()
c.Assert(err, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:49,代码来源:server_test.go
示例14: SetUpTest
func (s *RevisionUpdateSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.CharmSuite.SetUpTest(c)
machine, err := s.State.AddMachine("quantal", state.JobManageEnviron)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = machine.SetPassword(password)
c.Assert(err, gc.IsNil)
err = machine.SetProvisioned("i-manager", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
s.st = s.OpenAPIAsMachine(c, machine.Tag(), password, "fake_nonce")
c.Assert(s.st, gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:15,代码来源:revisionupdater_test.go
示例15: setupMachineAndServer
func (s *loginSuite) setupMachineAndServer(c *gc.C) (*api.Info, func()) {
machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = machine.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = machine.SetPassword(password)
c.Assert(err, gc.IsNil)
info, cleanup := s.setupServer(c)
info.Tag = machine.Tag()
info.Password = password
info.Nonce = "fake_nonce"
return info, cleanup
}
开发者ID:jameinel,项目名称:core,代码行数:15,代码来源:login_test.go
示例16: SetupAuthentication
func (auth *simpleAuth) SetupAuthentication(machine TaggedPasswordChanger) (*state.Info, *api.Info, error) {
password, err := utils.RandomPassword()
if err != nil {
return nil, nil, fmt.Errorf("cannot make password for machine %v: %v", machine, err)
}
if err := machine.SetPassword(password); err != nil {
return nil, nil, fmt.Errorf("cannot set API password for machine %v: %v", machine, err)
}
stateInfo := *auth.stateInfo
stateInfo.Tag = machine.Tag()
stateInfo.Password = password
apiInfo := *auth.apiInfo
apiInfo.Tag = machine.Tag()
apiInfo.Password = password
return &stateInfo, &apiInfo, nil
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:authenticationprovider.go
示例17: TestAgentPasswordHash
func (passwordSuite) TestAgentPasswordHash(c *gc.C) {
seenValues := make(map[string]bool)
for i := 0; i < 1000; i++ {
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
c.Assert(seenValues[password], jc.IsFalse)
seenValues[password] = true
hashed := utils.AgentPasswordHash(password)
c.Assert(hashed, gc.Not(gc.Equals), password)
c.Assert(seenValues[hashed], jc.IsFalse)
seenValues[hashed] = true
c.Assert(len(hashed), gc.Equals, 24)
// check we're not adding base64 padding.
c.Assert(hashed, gc.Matches, base64Chars)
}
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:password_test.go
示例18: APILogin
func (s *CommonProvisionerSuite) APILogin(c *gc.C, machine *state.Machine) {
if s.st != nil {
c.Assert(s.st.Close(), gc.IsNil)
}
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = machine.SetPassword(password)
c.Assert(err, gc.IsNil)
err = machine.SetProvisioned("i-fake", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
s.st = s.OpenAPIAsMachine(c, machine.Tag(), password, "fake_nonce")
c.Assert(s.st, gc.NotNil)
c.Logf("API: login as %q successful", machine.Tag())
s.provisioner = s.st.Provisioner()
c.Assert(s.provisioner, gc.NotNil)
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:provisioner_test.go
示例19: AgentConfigForTag
func (s *JujuConnSuite) AgentConfigForTag(c *gc.C, tag string) agent.Config {
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
config, err := agent.NewAgentConfig(
agent.AgentConfigParams{
DataDir: s.DataDir(),
Tag: tag,
UpgradedToVersion: version.Current.Number,
Password: password,
Nonce: "nonce",
StateAddresses: s.StateInfo(c).Addrs,
APIAddresses: s.APIInfo(c).Addrs,
CACert: testing.CACert,
})
c.Assert(err, gc.IsNil)
return config
}
开发者ID:jameinel,项目名称:core,代码行数:17,代码来源:conn.go
示例20: initBootstrapMachine
// initBootstrapMachine initializes the initial bootstrap machine in state.
func initBootstrapMachine(c ConfigSetter, st *state.State, cfg BootstrapMachineConfig) (*state.Machine, error) {
logger.Infof("initialising bootstrap machine with config: %+v", cfg)
jobs := make([]state.MachineJob, len(cfg.Jobs))
for i, job := range cfg.Jobs {
machineJob, err := state.MachineJobFromParams(job)
if err != nil {
return nil, fmt.Errorf("invalid bootstrap machine job %q: %v", job, err)
}
jobs[i] = machineJob
}
m, err := st.AddOneMachine(state.MachineTemplate{
Addresses: cfg.Addresses,
Series: version.Current.Series,
Nonce: state.BootstrapNonce,
Constraints: cfg.Constraints,
InstanceId: cfg.InstanceId,
HardwareCharacteristics: cfg.Characteristics,
Jobs: jobs,
})
if err != nil {
return nil, fmt.Errorf("cannot create bootstrap machine in state: %v", err)
}
if m.Id() != BootstrapMachineId {
return nil, fmt.Errorf("bootstrap machine expected id 0, got %q", m.Id())
}
// Read the machine agent's password and change it to
// a new password (other agents will change their password
// via the API connection).
logger.Debugf("create new random password for machine %v", m.Id())
newPassword, err := utils.RandomPassword()
if err != nil {
return nil, err
}
if err := m.SetPassword(newPassword); err != nil {
return nil, err
}
if err := m.SetMongoPassword(newPassword); err != nil {
return nil, err
}
c.SetPassword(newPassword)
return m, nil
}
开发者ID:jameinel,项目名称:core,代码行数:45,代码来源:bootstrap.go
注:本文中的github.com/wallyworld/core/utils.RandomPassword函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论