本文整理汇总了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
}
示例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, "")
}
示例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)
}