本文整理汇总了Golang中github.com/wallyworld/core/utils.RandomPassword函数的典型用法代码示例。如果您正苦于以下问题:Golang RandomPassword函数的具体用法?Golang RandomPassword怎么用?Golang RandomPassword使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandomPassword函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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
}