本文整理匯總了Golang中github.com/juju/utils.RandomPassword函數的典型用法代碼示例。如果您正苦於以下問題:Golang RandomPassword函數的具體用法?Golang RandomPassword怎麽用?Golang RandomPassword使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RandomPassword函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MakeMachine
// MakeMachine will add a machine with values defined in params. For some
// values in params, if they are missing, some meaningful empty values will be
// set.
// If params is not specified, defaults are used. If more than one
// params struct is passed to the function, it panics.
func (factory *Factory) MakeMachine(c *gc.C, params *MachineParams) *state.Machine {
if params == nil {
params = &MachineParams{}
}
if params.Series == "" {
params.Series = "quantal"
}
if params.Nonce == "" {
params.Nonce = "nonce"
}
if len(params.Jobs) == 0 {
params.Jobs = []state.MachineJob{state.JobHostUnits}
}
if params.InstanceId == "" {
params.InstanceId = instance.Id(factory.UniqueString("id"))
}
if params.Password == "" {
var err error
params.Password, err = utils.RandomPassword()
c.Assert(err, gc.IsNil)
}
machine, err := factory.st.AddMachine(params.Series, params.Jobs...)
c.Assert(err, gc.IsNil)
err = machine.SetProvisioned(params.InstanceId, params.Nonce, params.Characteristics)
c.Assert(err, gc.IsNil)
err = machine.SetPassword(params.Password)
c.Assert(err, gc.IsNil)
return machine
}
示例2: MakeUnitReturningPassword
// MakeUnit creates a service unit with specified params, filling in sane
// defaults for missing values. If params is not specified, defaults are used.
// The unit and its password are returned.
func (factory *Factory) MakeUnitReturningPassword(c *gc.C, params *UnitParams) (*state.Unit, string) {
if params == nil {
params = &UnitParams{}
}
if params.Machine == nil {
params.Machine = factory.MakeMachine(c, nil)
}
if params.Service == nil {
params.Service = factory.MakeService(c, nil)
}
if params.Password == "" {
var err error
params.Password, err = utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
}
unit, err := params.Service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = unit.AssignToMachine(params.Machine)
c.Assert(err, jc.ErrorIsNil)
if params.SetCharmURL {
serviceCharmURL, _ := params.Service.CharmURL()
err = unit.SetCharmURL(serviceCharmURL)
c.Assert(err, jc.ErrorIsNil)
}
err = unit.SetPassword(params.Password)
c.Assert(err, jc.ErrorIsNil)
if params.Status != nil {
err = unit.SetStatus(params.Status.Status, params.Status.Message, params.Status.Data)
c.Assert(err, jc.ErrorIsNil)
}
return unit, params.Password
}
示例3: hostedAPI
func (s *undertakerSuite) hostedAPI(c *gc.C) (*undertaker.Client, *state.State) {
otherState := s.Factory.MakeModel(c, &factory.ModelParams{Name: "hosted_env"})
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
machine := s.Factory.MakeMachine(c, &factory.MachineParams{
Jobs: []state.MachineJob{state.JobManageModel},
Password: password,
Nonce: "fake_nonce",
})
// Connect to hosted environ from controller.
info := s.APIInfo(c)
info.Tag = machine.Tag()
info.Password = password
info.Nonce = "fake_nonce"
info.ModelTag = otherState.ModelTag()
otherAPIState, err := api.Open(info, api.DefaultDialOpts())
c.Assert(err, jc.ErrorIsNil)
undertakerClient := undertaker.NewClient(otherAPIState)
c.Assert(undertakerClient, gc.NotNil)
return undertakerClient, otherState
}
示例4: generateOrReadPassword
func (*changePasswordCommand) generateOrReadPassword(ctx *cmd.Context, generate bool) (string, error) {
if generate {
password, err := utils.RandomPassword()
if err != nil {
return "", errors.Annotate(err, "failed to generate random password")
}
randomPasswordNotify(password)
return password, nil
}
// Don't add the carriage returns before readPassword, but add
// them directly after the readPassword so any errors are output
// on their own lines.
fmt.Fprint(ctx.Stdout, "password: ")
password, err := readPassword()
fmt.Fprint(ctx.Stdout, "\n")
if err != nil {
return "", errors.Trace(err)
}
fmt.Fprint(ctx.Stdout, "type password again: ")
verify, err := readPassword()
fmt.Fprint(ctx.Stdout, "\n")
if err != nil {
return "", errors.Trace(err)
}
if password != verify {
return "", errors.New("Passwords do not match")
}
return password, nil
}
示例5: SetUpTest
func (s *unitMetricBatchesSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.charm = s.Factory.MakeCharm(c, &jujufactory.CharmParams{
Name: "metered",
URL: "cs:quantal/metered",
})
service := s.Factory.MakeService(c, &jujufactory.ServiceParams{
Charm: s.charm,
})
unit := s.Factory.MakeUnit(c, &jujufactory.UnitParams{
Service: service,
SetCharmURL: true,
})
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = unit.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
s.st = s.OpenAPIAs(c, unit.Tag(), password)
// Create the uniter API facade.
s.uniter, err = s.st.Uniter()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.uniter, gc.NotNil)
s.apiUnit, err = s.uniter.Unit(unit.Tag().(names.UnitTag))
c.Assert(err, jc.ErrorIsNil)
}
示例6: generateSigmaComponents
func (c *environClient) generateSigmaComponents(baseName string, constraints *sigmaConstraints, args environs.StartInstanceParams, drv gosigma.Drive, userData []byte) (cc gosigma.Components, err error) {
cc.SetName(baseName)
cc.SetDescription(baseName)
cc.SetSMP(constraints.cores)
cc.SetCPU(constraints.power)
cc.SetMem(constraints.mem)
vncpass, err := utils.RandomPassword()
if err != nil {
err = errors.Errorf("error generating password: %v", err)
return
}
cc.SetVNCPassword(vncpass)
logger.Debugf("Setting ssh key: %s end", c.config.AuthorizedKeys())
cc.SetSSHPublicKey(c.config.AuthorizedKeys())
cc.AttachDrive(1, "0:0", "virtio", drv.UUID())
cc.NetworkDHCP4(gosigma.ModelVirtio)
if multiwatcher.AnyJobNeedsState(args.InstanceConfig.Jobs...) {
cc.SetMeta(jujuMetaInstance, jujuMetaInstanceStateServer)
} else {
cc.SetMeta(jujuMetaInstance, jujuMetaInstanceServer)
}
cc.SetMeta(jujuMetaEnvironment, c.uuid)
cc.SetMeta(jujuMetaCoudInit, string(userData))
cc.SetMeta(jujuMetaBase64, jujuMetaCoudInit)
return cc, nil
}
示例7: 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)
}
示例8: setUpTest
func (s *uniterSuite) setUpTest(c *gc.C, addController bool) {
s.JujuConnSuite.SetUpTest(c)
if addController {
s.controllerMachine = testing.AddControllerMachine(c, s.State)
}
// Bind "db" relation of wordpress to space "internal",
// and the "admin-api" extra-binding to space "public".
bindings := map[string]string{
"db": "internal",
"admin-api": "public",
}
_, err := s.State.AddSpace("internal", "", nil, false)
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.AddSpace("public", "", nil, true)
c.Assert(err, jc.ErrorIsNil)
// Create a machine, a service and add a unit so we can log in as
// its agent.
s.wordpressMachine, s.wordpressService, s.wordpressCharm, s.wordpressUnit = s.addMachineBoundServiceCharmAndUnit(c, "wordpress", bindings)
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = s.wordpressUnit.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
s.st = s.OpenAPIAs(c, s.wordpressUnit.Tag(), password)
// Create the uniter API facade.
s.uniter, err = s.st.Uniter()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.uniter, gc.NotNil)
}
示例9: Run
// Run implements Command.Run.
func (c *addCommand) 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 := utils.RandomPassword()
if err != nil {
return errors.Annotate(err, "failed to generate random password")
}
randomPasswordNotify(password)
if _, err := c.api.AddUser(c.User, c.DisplayName, password); err != nil {
return block.ProcessBlockedError(err, block.BlockChange)
}
displayName := c.User
if c.DisplayName != "" {
displayName = fmt.Sprintf("%s (%s)", c.DisplayName, c.User)
}
ctx.Infof("user %q added", displayName)
return writeServerFile(c, ctx, c.User, password, c.OutPath)
}
示例10: 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)
}
示例11: SetUpTest
func (s *rebootSuite) SetUpTest(c *gc.C) {
var err error
template := state.MachineTemplate{
Series: coretesting.FakeDefaultSeries,
Jobs: []state.MachineJob{state.JobHostUnits},
}
s.JujuConnSuite.SetUpTest(c)
s.stateAPI, s.machine = s.OpenAPIAsNewMachine(c)
s.rebootState, err = s.stateAPI.Reboot()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.rebootState, gc.NotNil)
//Add container
s.ct, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.KVM)
c.Assert(err, jc.ErrorIsNil)
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = s.ct.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
err = s.ct.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, jc.ErrorIsNil)
// Open api as container
ctState := s.OpenAPIAsMachine(c, s.ct.Tag(), password, "fake_nonce")
s.ctRebootState, err = ctState.Reboot()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.ctRebootState, gc.NotNil)
lock, err := fslock.NewLock(c.MkDir(), "fake", fslock.Defaults())
c.Assert(err, jc.ErrorIsNil)
s.lock = lock
}
示例12: paramsFillDefaults
func (factory *Factory) paramsFillDefaults(c *gc.C, params *MachineParams) *MachineParams {
if params == nil {
params = &MachineParams{}
}
if params.Series == "" {
params.Series = "quantal"
}
if params.Nonce == "" {
params.Nonce = "nonce"
}
if len(params.Jobs) == 0 {
params.Jobs = []state.MachineJob{state.JobHostUnits}
}
if params.InstanceId == "" {
params.InstanceId = instance.Id(uniqueString("id"))
}
if params.Password == "" {
var err error
params.Password, err = utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
}
if params.Characteristics == nil {
arch := "amd64"
mem := uint64(64 * 1024 * 1024 * 1024)
hardware := instance.HardwareCharacteristics{
Arch: &arch,
Mem: &mem,
}
params.Characteristics = &hardware
}
return params
}
示例13: SetUpTest
func (s *rebootSuite) SetUpTest(c *gc.C) {
var err error
template := state.MachineTemplate{
Series: series.LatestLts(),
Jobs: []state.MachineJob{state.JobHostUnits},
}
s.JujuConnSuite.SetUpTest(c)
s.stateAPI, s.machine = s.OpenAPIAsNewMachine(c)
s.rebootState, err = s.stateAPI.Reboot()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.rebootState, gc.NotNil)
//Add container
s.ct, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.KVM)
c.Assert(err, jc.ErrorIsNil)
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = s.ct.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
err = s.ct.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, jc.ErrorIsNil)
// Open api as container
ctState := s.OpenAPIAsMachine(c, s.ct.Tag(), password, "fake_nonce")
s.ctRebootState, err = ctState.Reboot()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.ctRebootState, gc.NotNil)
s.clock = &fakeClock{delay: time.Millisecond}
}
示例14: 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)
}
示例15: SetUpTest
func (s *provisionerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
// We're testing with address allocation on by default. There are
// separate tests to check the behavior when the flag is not
// enabled.
s.SetFeatureFlags(feature.AddressAllocation)
var err error
s.machine, err = s.State.AddMachine("quantal", state.JobManageModel)
c.Assert(err, jc.ErrorIsNil)
password, err := utils.RandomPassword()
c.Assert(err, jc.ErrorIsNil)
err = s.machine.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
err = s.machine.SetInstanceInfo("i-manager", "fake_nonce", nil, nil, nil, nil, nil)
c.Assert(err, jc.ErrorIsNil)
s.st = s.OpenAPIAsMachine(c, s.machine.Tag(), password, "fake_nonce")
c.Assert(s.st, gc.NotNil)
err = s.machine.SetProviderAddresses(network.NewAddress("0.1.2.3"))
c.Assert(err, jc.ErrorIsNil)
// Create the provisioner API facade.
s.provisioner = s.st.Provisioner()
c.Assert(s.provisioner, gc.NotNil)
s.ModelWatcherTests = apitesting.NewModelWatcherTests(s.provisioner, s.BackingState, apitesting.HasSecrets)
s.APIAddresserTests = apitesting.NewAPIAddresserTests(s.provisioner, s.BackingState)
}