本文整理汇总了Golang中github.com/juju/names.NewUserTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUserTag函数的具体用法?Golang NewUserTag怎么用?Golang NewUserTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUserTag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestListModelsDenied
func (s *modelManagerSuite) TestListModelsDenied(c *gc.C) {
user := names.NewUserTag("[email protected]")
s.setAPIUser(c, user)
other := names.NewUserTag("[email protected]")
_, err := s.modelmanager.ListModels(params.Entity{other.String()})
c.Assert(err, gc.ErrorMatches, "permission denied")
}
开发者ID:pmatulis,项目名称:juju,代码行数:7,代码来源:modelmanager_test.go
示例2: TestMigration
func (s *Suite) TestMigration(c *gc.C) {
masterClient := newStubMasterClient(s.stub)
w := migrationmaster.New(masterClient)
// Trigger migration.
masterClient.watcher.changes <- migration.TargetInfo{
ControllerTag: names.NewModelTag("uuid"),
Addrs: []string{"1.2.3.4:5"},
CACert: "cert",
AuthTag: names.NewUserTag("admin"),
Password: "secret",
}
// This error is temporary while migrationmaster is a WIP.
runWorkerAndWait(c, w, "migration seen and aborted")
// Observe that the migration was seen, the model exported, an API
// connection to the target controller was made, the model was
// imported and then the migration aborted.
s.stub.CheckCalls(c, []jujutesting.StubCall{
{"masterClient.Watch", nil},
{"masterClient.Export", nil},
{"apiOpen", []interface{}{&api.Info{
Addrs: []string{"1.2.3.4:5"},
CACert: "cert",
Tag: names.NewUserTag("admin"),
Password: "secret",
}, api.DefaultDialOpts()}},
{"APICall:MigrationTarget.Import",
[]interface{}{params.SerializedModel{Bytes: fakeSerializedModel}}},
{"masterClient.SetPhase", []interface{}{migration.ABORT}},
{"Connection.Close", nil},
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:34,代码来源:worker_test.go
示例3: SetUpTest
func (s *ModelMigrationSuite) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
s.clock = coretesting.NewClock(time.Now().Truncate(time.Second))
s.PatchValue(&state.GetClock, func() clock.Clock {
return s.clock
})
// Create a hosted model to migrate.
s.State2 = s.Factory.MakeModel(c, nil)
s.AddCleanup(func(*gc.C) { s.State2.Close() })
targetControllerTag := names.NewModelTag(utils.MustNewUUID().String())
// Plausible migration arguments to test with.
s.stdSpec = state.ModelMigrationSpec{
InitiatedBy: names.NewUserTag("admin"),
TargetInfo: migration.TargetInfo{
ControllerTag: targetControllerTag,
Addrs: []string{"1.2.3.4:5555", "4.3.2.1:6666"},
CACert: "cert",
AuthTag: names.NewUserTag("user"),
Password: "password",
},
}
}
开发者ID:makyo,项目名称:juju,代码行数:25,代码来源:modelmigration_test.go
示例4: TestWatch
func (s *migrationWatcherSuite) TestWatch(c *gc.C) {
// Create a state server
m, password := s.Factory.MakeMachineReturningPassword(c, &factory.MachineParams{
Jobs: []state.MachineJob{state.JobManageModel},
Nonce: "noncey",
})
// Create a model to migrate.
hostedState := s.Factory.MakeModel(c, nil)
// Connect as a state server to the hosted environment.
apiInfo := s.APIInfo(c)
apiInfo.Tag = m.Tag()
apiInfo.Password = password
apiInfo.ModelTag = hostedState.ModelTag()
apiInfo.Nonce = "noncey"
apiConn, err := api.Open(apiInfo, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
defer apiConn.Close()
// Start watching for a migration.
client := migrationmaster.NewClient(apiConn)
w, err := client.Watch()
c.Assert(err, jc.ErrorIsNil)
defer func() {
c.Assert(worker.Stop(w), jc.ErrorIsNil)
}()
// Should be no initial events.
select {
case _, ok := <-w.Changes():
c.Fatalf("watcher sent unexpected change: (_, %v)", ok)
case <-time.After(coretesting.ShortWait):
}
// Now create a migration.
targetInfo := migration.TargetInfo{
ControllerTag: names.NewModelTag(utils.MustNewUUID().String()),
Addrs: []string{"1.2.3.4:5"},
CACert: "trust me I'm an authority",
AuthTag: names.NewUserTag("dog"),
Password: "sekret",
}
_, err = hostedState.CreateModelMigration(state.ModelMigrationSpec{
InitiatedBy: names.NewUserTag("someone"),
TargetInfo: targetInfo,
})
c.Assert(err, jc.ErrorIsNil)
// Event with correct target details should be emitted.
select {
case reportedTargetInfo, ok := <-w.Changes():
c.Assert(ok, jc.IsTrue)
c.Assert(reportedTargetInfo, jc.DeepEquals, targetInfo)
case <-time.After(coretesting.LongWait):
c.Fatalf("watcher didn't emit an event")
}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:59,代码来源:watcher_test.go
示例5: TestCreateEnvUserOpAndDoc
func (s *internalEnvUserSuite) TestCreateEnvUserOpAndDoc(c *gc.C) {
tag := names.NewUserTag("UserName")
op, doc := createEnvUserOpAndDoc("ignored", tag, names.NewUserTag("ignored"), "ignored")
c.Assert(op.Id, gc.Equals, "[email protected]")
c.Assert(doc.ID, gc.Equals, "[email protected]")
c.Assert(doc.UserName, gc.Equals, "[email protected]")
}
开发者ID:Pankov404,项目名称:juju,代码行数:8,代码来源:envuser_internal_test.go
示例6: TestPassesValues
func (s *unshareSuite) TestPassesValues(c *gc.C) {
sam := names.NewUserTag("sam")
ralph := names.NewUserTag("ralph")
_, err := s.run(c, "sam", "ralph")
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.fake.removeUsers, jc.DeepEquals, []names.UserTag{sam, ralph})
}
开发者ID:exekias,项目名称:juju,代码行数:8,代码来源:unshare_test.go
示例7: TestListModelsForSelfLocalUser
func (s *modelManagerSuite) TestListModelsForSelfLocalUser(c *gc.C) {
// When the user's credentials cache stores the simple name, but the
// api server converts it to a fully qualified name.
user := names.NewUserTag("local-user")
s.setAPIUser(c, names.NewUserTag("[email protected]"))
result, err := s.modelmanager.ListModels(params.Entity{user.String()})
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.UserModels, gc.HasLen, 0)
}
开发者ID:pmatulis,项目名称:juju,代码行数:9,代码来源:modelmanager_test.go
示例8: TestGrantToModelNoAccess
func (s *modelManagerSuite) TestGrantToModelNoAccess(c *gc.C) {
apiUser := names.NewUserTag("[email protected]")
s.setAPIUser(c, apiUser)
st := s.Factory.MakeModel(c, nil)
defer st.Close()
other := names.NewUserTag("[email protected]")
err := s.grant(c, other, params.ModelReadAccess, st.ModelTag())
c.Assert(err, gc.ErrorMatches, "permission denied")
}
开发者ID:makyo,项目名称:juju,代码行数:11,代码来源:modelmanager_test.go
示例9: TestInit
func (s *unshareSuite) TestInit(c *gc.C) {
wrappedCommand, unshareCmd := model.NewUnshareCommandForTest(s.fake)
err := testing.InitCommand(wrappedCommand, []string{})
c.Assert(err, gc.ErrorMatches, "no users specified")
err = testing.InitCommand(wrappedCommand, []string{"not valid/0"})
c.Assert(err, gc.ErrorMatches, `invalid username: "not valid/0"`)
err = testing.InitCommand(wrappedCommand, []string{"[email protected]", "sam"})
c.Assert(err, jc.ErrorIsNil)
c.Assert(unshareCmd.Users[0], gc.Equals, names.NewUserTag("[email protected]"))
c.Assert(unshareCmd.Users[1], gc.Equals, names.NewUserTag("sam"))
}
开发者ID:exekias,项目名称:juju,代码行数:14,代码来源:unshare_test.go
示例10: TestInit
func (s *unshareSuite) TestInit(c *gc.C) {
unshareCmd := &environment.UnshareCommand{}
err := testing.InitCommand(unshareCmd, []string{})
c.Assert(err, gc.ErrorMatches, "no users specified")
err = testing.InitCommand(unshareCmd, []string{"not valid/0"})
c.Assert(err, gc.ErrorMatches, `invalid username: "not valid/0"`)
err = testing.InitCommand(unshareCmd, []string{"[email protected]", "sam"})
c.Assert(err, jc.ErrorIsNil)
c.Assert(unshareCmd.Users[0], gc.Equals, names.NewUserTag("[email protected]"))
c.Assert(unshareCmd.Users[1], gc.Equals, names.NewUserTag("sam"))
}
开发者ID:Pankov404,项目名称:juju,代码行数:14,代码来源:unshare_test.go
示例11: TestGrantToModelReadAccess
func (s *modelManagerSuite) TestGrantToModelReadAccess(c *gc.C) {
apiUser := names.NewUserTag("[email protected]")
s.setAPIUser(c, apiUser)
st := s.Factory.MakeModel(c, nil)
defer st.Close()
stFactory := factory.NewFactory(st)
stFactory.MakeModelUser(c, &factory.ModelUserParams{
User: apiUser.Canonical(), Access: state.ModelReadAccess})
other := names.NewUserTag("[email protected]")
err := s.grant(c, other, params.ModelReadAccess, st.ModelTag())
c.Assert(err, gc.ErrorMatches, "permission denied")
}
开发者ID:makyo,项目名称:juju,代码行数:14,代码来源:modelmanager_test.go
示例12: MakeModelUser
// MakeModelUser will create a modelUser with values defined by the params. For
// attributes of ModelUserParams that are the default empty values, some
// meaningful valid values are used instead. If params is not specified,
// defaults are used.
func (factory *Factory) MakeModelUser(c *gc.C, params *ModelUserParams) *state.ModelUser {
if params == nil {
params = &ModelUserParams{}
}
if params.User == "" {
user := factory.MakeUser(c, &UserParams{NoModelUser: true})
params.User = user.UserTag().Canonical()
}
if params.DisplayName == "" {
params.DisplayName = uniqueString("display name")
}
if params.CreatedBy == nil {
env, err := factory.st.Model()
c.Assert(err, jc.ErrorIsNil)
params.CreatedBy = env.Owner()
}
createdByUserTag := params.CreatedBy.(names.UserTag)
modelUser, err := factory.st.AddModelUser(state.ModelUserSpec{
User: names.NewUserTag(params.User),
CreatedBy: createdByUserTag,
DisplayName: params.DisplayName,
ReadOnly: params.ReadOnly,
})
c.Assert(err, jc.ErrorIsNil)
return modelUser
}
开发者ID:pmatulis,项目名称:juju,代码行数:30,代码来源:factory.go
示例13: findMatchingEnvironment
func (c *UseEnvironmentCommand) findMatchingEnvironment(ctx *cmd.Context, client UseEnvironmentAPI, creds configstore.APICredentials) (base.UserEnvironment, error) {
var empty base.UserEnvironment
envs, err := client.ListEnvironments(creds.User)
if err != nil {
return empty, errors.Annotate(err, "cannot list environments")
}
var owner string
if c.Owner != "" {
// The username always contains the provider aspect of the user.
owner = names.NewUserTag(c.Owner).Username()
}
// If we have a UUID, we warn if the owner is different, but accept it.
// We also trust that the environment UUIDs are unique
if c.EnvUUID != "" {
for _, env := range envs {
if env.UUID == c.EnvUUID {
if owner != "" && env.Owner != owner {
ctx.Infof("Specified environment owned by %s, not %s", env.Owner, owner)
}
return env, nil
}
}
return empty, errors.NotFoundf("matching environment")
}
var matches []base.UserEnvironment
for _, env := range envs {
match := env.Name == c.EnvName
if match && owner != "" {
match = env.Owner == owner
}
if match {
matches = append(matches, env)
}
}
// If there is only one match, that's the one.
switch len(matches) {
case 0:
return empty, errors.NotFoundf("matching environment")
case 1:
return matches[0], nil
}
// We are going to return an error, but tell the user what the matches
// were so they can make an informed decision. We are also going to assume
// here that the resulting environment list has only one matching name for
// each user. There are tests creating environments that enforce this.
ctx.Infof("Multiple environments matched name %q:", c.EnvName)
for _, env := range matches {
ctx.Infof(" %s, owned by %s", env.UUID, env.Owner)
}
ctx.Infof("Please specify either the environment UUID or the owner to disambiguate.")
return empty, errors.New("multiple environments matched")
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:60,代码来源:useenvironment.go
示例14: TestNewModelNonExistentLocalUser
func (s *ModelSuite) TestNewModelNonExistentLocalUser(c *gc.C) {
cfg, _ := s.createTestEnvConfig(c)
owner := names.NewUserTag("[email protected]")
_, _, err := s.State.NewModel(state.ModelArgs{Config: cfg, Owner: owner})
c.Assert(err, gc.ErrorMatches, `cannot create model: user "non-existent" not found`)
}
开发者ID:makyo,项目名称:juju,代码行数:7,代码来源:model_test.go
示例15: TestOpenFailsIfUsernameAndUseMacaroon
func (s *apiclientSuite) TestOpenFailsIfUsernameAndUseMacaroon(c *gc.C) {
info := s.APIInfo(c)
info.Tag = names.NewUserTag("foobar")
info.UseMacaroons = true
_, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.ErrorMatches, "open should specifiy UseMacaroons or a username & password. Not both")
}
开发者ID:snailwalker,项目名称:juju,代码行数:7,代码来源:apiclient_test.go
示例16: SetUpTest
func (s *destroyTwoEnvironmentsSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
_, err := s.State.AddUser("jess", "jess", "", "test")
c.Assert(err, jc.ErrorIsNil)
s.otherEnvOwner = names.NewUserTag("jess")
s.otherState = factory.NewFactory(s.State).MakeEnvironment(c, &factory.EnvParams{
Owner: s.otherEnvOwner,
Prepare: true,
ConfigAttrs: jujutesting.Attrs{
"state-server": false,
},
})
s.AddCleanup(func(*gc.C) { s.otherState.Close() })
// get the client for the other environment
auth := apiservertesting.FakeAuthorizer{
Tag: s.otherEnvOwner,
EnvironManager: false,
}
s.otherEnvClient, err = client.NewClient(s.otherState, common.NewResources(), auth)
c.Assert(err, jc.ErrorIsNil)
s.metricSender = &testMetricSender{}
s.PatchValue(common.SendMetrics, s.metricSender.SendMetrics)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:25,代码来源:environdestroy_test.go
示例17: TestListModelsForSelf
func (s *modelManagerSuite) TestListModelsForSelf(c *gc.C) {
user := names.NewUserTag("[email protected]")
s.setAPIUser(c, user)
result, err := s.modelmanager.ListModels(params.Entity{user.String()})
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.UserModels, gc.HasLen, 0)
}
开发者ID:pmatulis,项目名称:juju,代码行数:7,代码来源:modelmanager_test.go
示例18: apiInfoConnect
// apiInfoConnect looks for endpoint on the given environment and
// tries to connect to it, sending the result on the returned channel.
func apiInfoConnect(store configstore.Storage, info configstore.EnvironInfo, apiOpen apiOpenFunc, stop <-chan struct{}) (apiState, error) {
endpoint := info.APIEndpoint()
if info == nil || len(endpoint.Addresses) == 0 {
return nil, &infoConnectError{fmt.Errorf("no cached addresses")}
}
logger.Infof("connecting to API addresses: %v", endpoint.Addresses)
var environTag names.Tag
if endpoint.EnvironUUID != "" {
// Note: we should be validating that EnvironUUID contains a
// valid UUID.
environTag = names.NewEnvironTag(endpoint.EnvironUUID)
}
username := info.APICredentials().User
if username == "" {
username = "admin"
}
apiInfo := &api.Info{
Addrs: endpoint.Addresses,
CACert: endpoint.CACert,
Tag: names.NewUserTag(username),
Password: info.APICredentials().Password,
EnvironTag: environTag,
}
st, err := apiOpen(apiInfo, api.DefaultDialOpts())
if err != nil {
return nil, &infoConnectError{err}
}
return st, nil
}
开发者ID:kapilt,项目名称:juju,代码行数:31,代码来源:api.go
示例19: TestUnshareEnvironmentMissingUser
func (s *clientSuite) TestUnshareEnvironmentMissingUser(c *gc.C) {
client := s.APIState.Client()
user := names.NewUserTag("[email protected]")
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
if users, ok := paramsIn.(params.ModifyEnvironUsers); ok {
c.Assert(users.Changes, gc.HasLen, 1)
c.Logf(string(users.Changes[0].Action), gc.Equals, string(params.RemoveEnvUser))
c.Logf(users.Changes[0].UserTag, gc.Equals, user.String())
} else {
c.Fatalf("wrong input structure")
}
if result, ok := response.(*params.ErrorResults); ok {
err := ¶ms.Error{
Message: "error message",
Code: params.CodeNotFound,
}
*result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}}}
} else {
c.Fatalf("wrong input structure")
}
return nil
},
)
defer cleanup()
err := client.UnshareEnvironment(user)
c.Assert(err, jc.ErrorIsNil)
logMsg := fmt.Sprintf("WARNING juju.api environment was not previously shared with user %s", user.Username())
c.Assert(c.GetTestLog(), jc.Contains, logMsg)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:31,代码来源:client_test.go
示例20: TestUnshareEnvironmentThreeUsers
func (s *clientSuite) TestUnshareEnvironmentThreeUsers(c *gc.C) {
client := s.APIState.Client()
missingUser := s.Factory.MakeEnvUser(c, nil)
localUser := s.Factory.MakeUser(c, nil)
newUserTag := names.NewUserTag("[email protected]")
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
if users, ok := paramsIn.(params.ModifyEnvironUsers); ok {
c.Assert(users.Changes, gc.HasLen, 3)
c.Assert(string(users.Changes[0].Action), gc.Equals, string(params.RemoveEnvUser))
c.Assert(users.Changes[0].UserTag, gc.Equals, missingUser.UserTag().String())
c.Assert(string(users.Changes[1].Action), gc.Equals, string(params.RemoveEnvUser))
c.Assert(users.Changes[1].UserTag, gc.Equals, localUser.UserTag().String())
c.Assert(string(users.Changes[2].Action), gc.Equals, string(params.RemoveEnvUser))
c.Assert(users.Changes[2].UserTag, gc.Equals, newUserTag.String())
} else {
c.Log("wrong input structure")
c.Fail()
}
if result, ok := response.(*params.ErrorResults); ok {
err := ¶ms.Error{Message: "error unsharing user"}
*result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}, {Error: nil}, {Error: nil}}}
} else {
c.Log("wrong output structure")
c.Fail()
}
return nil
},
)
defer cleanup()
err := client.UnshareEnvironment(missingUser.UserTag(), localUser.UserTag(), newUserTag)
c.Assert(err, gc.ErrorMatches, "error unsharing user")
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:34,代码来源:client_test.go
注:本文中的github.com/juju/names.NewUserTag函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论