本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/privilege.List类的典型用法代码示例。如果您正苦于以下问题:Golang List类的具体用法?Golang List怎么用?Golang List使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了List类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Revoke
// Revoke removes privileges from this descriptor for a given list of users.
func (p *PrivilegeDescriptor) Revoke(user string, privList privilege.List) {
userPriv, ok := p.findUser(user)
if !ok || userPriv.Privileges == 0 {
// Removing privileges from a user without privileges is a no-op.
return
}
bits := privList.ToBitField()
if isPrivilegeSet(bits, privilege.ALL) {
// Revoking 'ALL' privilege: remove user.
// TODO(marc): the grammar does not allow it, but we should
// check if other privileges are being specified and error out.
p.removeUser(user)
return
}
if isPrivilegeSet(userPriv.Privileges, privilege.ALL) {
// User has 'ALL' privilege. Remove it and set
// all other privileges one.
userPriv.Privileges = 0
for _, v := range privilege.ByValue {
if v != privilege.ALL {
userPriv.Privileges |= v.Mask()
}
}
}
// One doesn't see "AND NOT" very often.
userPriv.Privileges &^= bits
if userPriv.Privileges == 0 {
p.removeUser(user)
}
}
示例2: NewPrivilegeDescriptor
// NewPrivilegeDescriptor returns a privilege descriptor for the given
// user with the specified list of privileges.
func NewPrivilegeDescriptor(user string, priv privilege.List) *PrivilegeDescriptor {
return &PrivilegeDescriptor{
Users: []UserPrivileges{
{
User: user,
Privileges: priv.ToBitField(),
},
},
}
}
示例3: Grant
// Grant adds new privileges to this descriptor for a given list of users.
// TODO(marc): if all privileges other than ALL are set, should we collapse
// them into ALL?
func (p *PrivilegeDescriptor) Grant(user string, privList privilege.List) {
userPriv := p.findOrCreateUser(user)
if isPrivilegeSet(userPriv.Privileges, privilege.ALL) {
// User already has 'ALL' privilege: no-op.
return
}
bits := privList.ToBitField()
if isPrivilegeSet(bits, privilege.ALL) {
// Granting 'ALL' privilege: overwrite.
// TODO(marc): the grammar does not allow it, but we should
// check if other privileges are being specified and error out.
userPriv.Privileges = privilege.ALL.Mask()
return
}
userPriv.Privileges |= bits
}