当前位置: 首页>>代码示例>>Golang>>正文


Golang usermanager.NewClient函数代码示例

本文整理汇总了Golang中github.com/juju/juju/api/usermanager.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewClient函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewUserManagerClient

// NewUserManagerClient returns a usermanager client for the root api endpoint
// that the environment command returns.
func (c *UserCommandBase) NewUserManagerClient() (*usermanager.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return usermanager.NewClient(root), nil
}
开发者ID:Pankov404,项目名称:juju,代码行数:9,代码来源:user.go

示例2: NewUserManagerAPIClient

// NewUserManagerAPIClient returns an API client for the UserManager on the
// current controller using the current credentials.
func (c *ControllerCommandBase) NewUserManagerAPIClient() (*usermanager.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return usermanager.NewClient(root), nil
}
开发者ID:exekias,项目名称:juju,代码行数:9,代码来源:controller.go

示例3: TestCanPostWithLocalLogin

func (s *toolsWithMacaroonsSuite) TestCanPostWithLocalLogin(c *gc.C) {
	// Create a new user, and a local login macaroon for it.
	user := s.Factory.MakeUser(c, &factory.UserParams{Password: "hunter2"})
	conn := s.OpenAPIAs(c, user.Tag(), "hunter2")
	defer conn.Close()
	mac, err := usermanager.NewClient(conn).CreateLocalLoginMacaroon(user.UserTag())
	c.Assert(err, jc.ErrorIsNil)

	checkCount := 0
	s.DischargerLogin = func() string {
		checkCount++
		return user.UserTag().Id()
	}
	do := func(req *http.Request) (*http.Response, error) {
		data, err := json.Marshal(macaroon.Slice{mac})
		if err != nil {
			return nil, err
		}
		req.Header.Add(httpbakery.MacaroonsHeader, base64.StdEncoding.EncodeToString(data))
		return utils.GetNonValidatingHTTPClient().Do(req)
	}
	// send without using bakeryDo, so we don't pass any macaroon cookies
	// along.
	resp := s.sendRequest(c, httpRequestParams{
		method:   "POST",
		url:      s.toolsURI(c, ""),
		tag:      user.UserTag().String(),
		password: "", // no password forces macaroon usage
		do:       do,
	})
	s.assertErrorResponse(c, resp, http.StatusBadRequest, "expected binaryVersion argument")
	c.Assert(checkCount, gc.Equals, 0)
}
开发者ID:makyo,项目名称:juju,代码行数:33,代码来源:tools_test.go

示例4: TestLoginMacaroonInvalidUser

func (s *stateSuite) TestLoginMacaroonInvalidUser(c *gc.C) {
	apistate, tag, _ := s.OpenAPIWithoutLogin(c)
	defer apistate.Close()
	// Use s.APIState, because we can't get at UserManager without logging in.
	mac, err := usermanager.NewClient(s.APIState).CreateLocalLoginMacaroon(tag.(names.UserTag))
	c.Assert(err, jc.ErrorIsNil)
	err = apistate.Login(names.NewUserTag("[email protected]"), "", "", []macaroon.Slice{{mac}})
	c.Assert(err, gc.ErrorMatches, `verification failed: caveat "declared username [email protected]" not satisfied: got username="[email protected]", expected "[email protected]"`)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:9,代码来源:state_test.go

示例5: TestLoginMacaroon

func (s *stateSuite) TestLoginMacaroon(c *gc.C) {
	apistate, tag, _ := s.OpenAPIWithoutLogin(c)
	defer apistate.Close()
	// Use s.APIState, because we can't get at UserManager without logging in.
	mac, err := usermanager.NewClient(s.APIState).CreateLocalLoginMacaroon(tag.(names.UserTag))
	c.Assert(err, jc.ErrorIsNil)
	err = apistate.Login(tag, "", "", []macaroon.Slice{{mac}})
	c.Assert(err, jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:9,代码来源:state_test.go

示例6: NewLoginCommand

// NewLoginCommand returns a new cmd.Command to handle "juju login".
func NewLoginCommand() cmd.Command {
	return modelcmd.WrapController(&loginCommand{
		newLoginAPI: func(args juju.NewAPIConnectionParams) (LoginAPI, ConnectionAPI, error) {
			api, err := juju.NewAPIConnection(args)
			if err != nil {
				return nil, nil, errors.Trace(err)
			}
			return usermanager.NewClient(api), api, nil
		},
	})
}
开发者ID:kat-co,项目名称:juju,代码行数:12,代码来源:login.go

示例7: TestLoginSetsControllerAccess

func (s *stateSuite) TestLoginSetsControllerAccess(c *gc.C) {
	// The default user has admin access.
	c.Assert(s.APIState.ControllerAccess(), gc.Equals, "superuser")

	manager := usermanager.NewClient(s.OpenControllerAPI(c))
	defer manager.Close()
	usertag, _, err := manager.AddUser("ro", "ro", "ro-password")
	c.Assert(err, jc.ErrorIsNil)
	mmanager := modelmanager.NewClient(s.OpenControllerAPI(c))
	defer mmanager.Close()
	modeltag, ok := s.APIState.ModelTag()
	c.Assert(ok, jc.IsTrue)
	err = mmanager.GrantModel(usertag.Id(), "read", modeltag.Id())
	c.Assert(err, jc.ErrorIsNil)
	conn := s.OpenAPIAs(c, usertag, "ro-password")
	c.Assert(conn.ControllerAccess(), gc.Equals, "login")
}
开发者ID:bac,项目名称:juju,代码行数:17,代码来源:state_test.go

示例8: getUserManager

func getUserManager(conn api.Connection) (UserManager, error) {
	return usermanager.NewClient(conn), nil
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:3,代码来源:login.go

示例9: SetUpTest

func (s *usermanagerSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)
	s.usermanager = usermanager.NewClient(s.OpenControllerAPI(c))
	c.Assert(s.usermanager, gc.NotNil)
}
开发者ID:bac,项目名称:juju,代码行数:5,代码来源:client_test.go

示例10: SetUpTest

func (s *usermanagerSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)
	s.usermanager = usermanager.NewClient(s.APIState)
	c.Assert(s.usermanager, gc.NotNil)
}
开发者ID:kapilt,项目名称:juju,代码行数:5,代码来源:client_test.go


注:本文中的github.com/juju/juju/api/usermanager.NewClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。