khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 1 | // Copyright 2016 The etcd Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package v3rpc |
| 16 | |
| 17 | import ( |
| 18 | "context" |
| 19 | |
| 20 | "go.etcd.io/etcd/etcdserver" |
| 21 | pb "go.etcd.io/etcd/etcdserver/etcdserverpb" |
| 22 | ) |
| 23 | |
| 24 | type AuthServer struct { |
| 25 | authenticator etcdserver.Authenticator |
| 26 | } |
| 27 | |
| 28 | func NewAuthServer(s *etcdserver.EtcdServer) *AuthServer { |
| 29 | return &AuthServer{authenticator: s} |
| 30 | } |
| 31 | |
| 32 | func (as *AuthServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { |
| 33 | resp, err := as.authenticator.AuthEnable(ctx, r) |
| 34 | if err != nil { |
| 35 | return nil, togRPCError(err) |
| 36 | } |
| 37 | return resp, nil |
| 38 | } |
| 39 | |
| 40 | func (as *AuthServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { |
| 41 | resp, err := as.authenticator.AuthDisable(ctx, r) |
| 42 | if err != nil { |
| 43 | return nil, togRPCError(err) |
| 44 | } |
| 45 | return resp, nil |
| 46 | } |
| 47 | |
| 48 | func (as *AuthServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { |
| 49 | resp, err := as.authenticator.Authenticate(ctx, r) |
| 50 | if err != nil { |
| 51 | return nil, togRPCError(err) |
| 52 | } |
| 53 | return resp, nil |
| 54 | } |
| 55 | |
| 56 | func (as *AuthServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { |
| 57 | resp, err := as.authenticator.RoleAdd(ctx, r) |
| 58 | if err != nil { |
| 59 | return nil, togRPCError(err) |
| 60 | } |
| 61 | return resp, nil |
| 62 | } |
| 63 | |
| 64 | func (as *AuthServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { |
| 65 | resp, err := as.authenticator.RoleDelete(ctx, r) |
| 66 | if err != nil { |
| 67 | return nil, togRPCError(err) |
| 68 | } |
| 69 | return resp, nil |
| 70 | } |
| 71 | |
| 72 | func (as *AuthServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { |
| 73 | resp, err := as.authenticator.RoleGet(ctx, r) |
| 74 | if err != nil { |
| 75 | return nil, togRPCError(err) |
| 76 | } |
| 77 | return resp, nil |
| 78 | } |
| 79 | |
| 80 | func (as *AuthServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { |
| 81 | resp, err := as.authenticator.RoleList(ctx, r) |
| 82 | if err != nil { |
| 83 | return nil, togRPCError(err) |
| 84 | } |
| 85 | return resp, nil |
| 86 | } |
| 87 | |
| 88 | func (as *AuthServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { |
| 89 | resp, err := as.authenticator.RoleRevokePermission(ctx, r) |
| 90 | if err != nil { |
| 91 | return nil, togRPCError(err) |
| 92 | } |
| 93 | return resp, nil |
| 94 | } |
| 95 | |
| 96 | func (as *AuthServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { |
| 97 | resp, err := as.authenticator.RoleGrantPermission(ctx, r) |
| 98 | if err != nil { |
| 99 | return nil, togRPCError(err) |
| 100 | } |
| 101 | return resp, nil |
| 102 | } |
| 103 | |
| 104 | func (as *AuthServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { |
| 105 | resp, err := as.authenticator.UserAdd(ctx, r) |
| 106 | if err != nil { |
| 107 | return nil, togRPCError(err) |
| 108 | } |
| 109 | return resp, nil |
| 110 | } |
| 111 | |
| 112 | func (as *AuthServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { |
| 113 | resp, err := as.authenticator.UserDelete(ctx, r) |
| 114 | if err != nil { |
| 115 | return nil, togRPCError(err) |
| 116 | } |
| 117 | return resp, nil |
| 118 | } |
| 119 | |
| 120 | func (as *AuthServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { |
| 121 | resp, err := as.authenticator.UserGet(ctx, r) |
| 122 | if err != nil { |
| 123 | return nil, togRPCError(err) |
| 124 | } |
| 125 | return resp, nil |
| 126 | } |
| 127 | |
| 128 | func (as *AuthServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { |
| 129 | resp, err := as.authenticator.UserList(ctx, r) |
| 130 | if err != nil { |
| 131 | return nil, togRPCError(err) |
| 132 | } |
| 133 | return resp, nil |
| 134 | } |
| 135 | |
| 136 | func (as *AuthServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { |
| 137 | resp, err := as.authenticator.UserGrantRole(ctx, r) |
| 138 | if err != nil { |
| 139 | return nil, togRPCError(err) |
| 140 | } |
| 141 | return resp, nil |
| 142 | } |
| 143 | |
| 144 | func (as *AuthServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { |
| 145 | resp, err := as.authenticator.UserRevokeRole(ctx, r) |
| 146 | if err != nil { |
| 147 | return nil, togRPCError(err) |
| 148 | } |
| 149 | return resp, nil |
| 150 | } |
| 151 | |
| 152 | func (as *AuthServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { |
| 153 | resp, err := as.authenticator.UserChangePassword(ctx, r) |
| 154 | if err != nil { |
| 155 | return nil, togRPCError(err) |
| 156 | } |
| 157 | return resp, nil |
| 158 | } |