*: support getting role in auth v3
This commit implements RoleGet() RPC of etcdserver and adds a new subcommand "role get" to etcdctl v3. It will list up permissions that are granted to a given role. $ ETCDCTL_API=3 bin/etcdctl role get r1 Role r1 KV Read: b d KV Write: a c d
This commit is contained in:

committed by
Hitoshi Mitake

parent
755567cb3d
commit
10ee69b44c
@ -36,6 +36,7 @@ type (
|
||||
AuthUserGetResponse pb.AuthUserGetResponse
|
||||
AuthRoleAddResponse pb.AuthRoleAddResponse
|
||||
AuthRoleGrantResponse pb.AuthRoleGrantResponse
|
||||
AuthRoleGetResponse pb.AuthRoleGetResponse
|
||||
|
||||
PermissionType authpb.Permission_Type
|
||||
)
|
||||
@ -73,6 +74,9 @@ type Auth interface {
|
||||
|
||||
// RoleGrant grants a permission to a role.
|
||||
RoleGrant(ctx context.Context, name string, key string, permType PermissionType) (*AuthRoleGrantResponse, error)
|
||||
|
||||
// RoleGet gets a detailed information of a role.
|
||||
RoleGet(ctx context.Context, role string) (*AuthRoleGetResponse, error)
|
||||
}
|
||||
|
||||
type auth struct {
|
||||
@ -140,6 +144,11 @@ func (auth *auth) RoleGrant(ctx context.Context, name string, key string, permTy
|
||||
return (*AuthRoleGrantResponse)(resp), rpctypes.Error(err)
|
||||
}
|
||||
|
||||
func (auth *auth) RoleGet(ctx context.Context, role string) (*AuthRoleGetResponse, error) {
|
||||
resp, err := auth.remote.RoleGet(ctx, &pb.AuthRoleGetRequest{Role: role})
|
||||
return (*AuthRoleGetResponse)(resp), rpctypes.Error(err)
|
||||
}
|
||||
|
||||
func StrToPermissionType(s string) (PermissionType, error) {
|
||||
val, ok := authpb.Permission_Type_value[strings.ToUpper(s)]
|
||||
if ok {
|
||||
|
Reference in New Issue
Block a user