當前位置: 首頁>>代碼示例>>Golang>>正文


Golang User.AddRole方法代碼示例

本文整理匯總了Golang中github.com/tsuru/tsuru/auth.User.AddRole方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.AddRole方法的具體用法?Golang User.AddRole怎麽用?Golang User.AddRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/tsuru/tsuru/auth.User的用法示例。


在下文中一共展示了User.AddRole方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createTokenForUser

func createTokenForUser(user *auth.User, perm, contextType, contextValue string, c *check.C) auth.Token {
	token, err := nativeScheme.Login(map[string]string{"email": user.Email, "password": "123456"})
	c.Assert(err, check.IsNil)
	role, err := permission.NewRole("provisioner-docker-"+user.Email+perm, contextType, "")
	c.Assert(err, check.IsNil)
	err = role.AddPermissions(perm)
	c.Assert(err, check.IsNil)
	err = user.AddRole(role.Name, contextValue)
	c.Assert(err, check.IsNil)
	return token
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:11,代碼來源:handlers_test.go

示例2: addSuperRole

func addSuperRole(u *auth.User) error {
	defaultRoleName := "AllowAll"
	r, err := permission.FindRole(defaultRoleName)
	if err != nil {
		r, err = permission.NewRole(defaultRoleName, string(permission.CtxGlobal), "")
		if err != nil {
			return err
		}
	}
	err = r.AddPermissions("*")
	if err != nil {
		return err
	}
	return u.AddRole(defaultRoleName, "")
}
開發者ID:pedrosnk,項目名稱:tsuru,代碼行數:15,代碼來源:token.go

示例3: TestSync

func (s *GandalfSuite) TestSync(c *check.C) {
	var buf bytes.Buffer
	conn, err := db.Conn()
	c.Assert(err, check.IsNil)
	defer conn.Close()
	defer dbtest.ClearAllCollections(conn.Apps().Database)
	var manager gandalfManager
	user1 := auth.User{Email: "[email protected]"}
	user2 := auth.User{Email: "[email protected]"}
	err = conn.Users().Insert(user1, user2)
	c.Assert(err, check.IsNil)
	role, err := permission.NewRole("deployRole", string(permission.CtxTeam), "")
	c.Assert(err, check.IsNil)
	err = role.AddPermissions("app.deploy")
	c.Assert(err, check.IsNil)
	err = user1.AddRole(role.Name, "superteam")
	c.Assert(err, check.IsNil)
	err = user2.AddRole(role.Name, "superteam")
	c.Assert(err, check.IsNil)
	err = manager.CreateUser(user1.Email)
	c.Assert(err, check.IsNil)
	team := auth.Team{Name: "superteam"}
	err = conn.Teams().Insert(team)
	c.Assert(err, check.IsNil)
	app1 := app.App{Name: "myapp", Teams: []string{team.Name}}
	app2 := app.App{Name: "yourapp", Teams: []string{team.Name}}
	app3 := app.App{Name: "hisapp", Teams: []string{team.Name}}
	err = conn.Apps().Insert(app1, app2, app3)
	c.Assert(err, check.IsNil)
	err = manager.CreateRepository(app2.Name, []string{user1.Email})
	c.Assert(err, check.IsNil)
	err = Sync(&buf)
	c.Assert(err, check.IsNil)
	c.Assert(s.server.Users(), check.DeepEquals, []string{user1.Email, user2.Email})
	expectedRepos := []gandalftest.Repository{
		{
			Name:         "yourapp",
			Users:        []string{user1.Email, user2.Email},
			ReadWriteURL: "[email protected]:yourapp.git",
			IsPublic:     true,
		},
		{
			Name:         "myapp",
			Users:        []string{user1.Email, user2.Email},
			ReadWriteURL: "[email protected]:myapp.git",
			IsPublic:     true,
		},
		{
			Name:         "hisapp",
			Users:        []string{user1.Email, user2.Email},
			ReadWriteURL: "[email protected]:hisapp.git",
			IsPublic:     true,
		},
	}
	repositories := s.server.Repositories()
	for i, repo := range repositories {
		repo.Diffs = nil
		repo.ReadOnlyURL = ""
		repositories[i] = repo
	}
	c.Assert(repositories, check.DeepEquals, expectedRepos)
	expected := `Syncing user "[email protected]"... already present in Gandalf
Syncing user "[email protected]"... OK
Syncing app "myapp"... OK
Syncing app "yourapp"... already present in Gandalf
Syncing app "hisapp"... OK
`
	c.Assert(buf.String(), check.Equals, expected)
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:69,代碼來源:gandalf_test.go


注:本文中的github.com/tsuru/tsuru/auth.User.AddRole方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。