auth.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. package v3rpc
  15. import (
  16. "context"
  17. "github.com/coreos/etcd/etcdserver"
  18. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  19. )
  20. type AuthServer struct {
  21. authenticator etcdserver.Authenticator
  22. }
  23. func NewAuthServer(s *etcdserver.EtcdServer) *AuthServer {
  24. return &AuthServer{authenticator: s}
  25. }
  26. func (as *AuthServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) {
  27. resp, err := as.authenticator.AuthEnable(ctx, r)
  28. if err != nil {
  29. return nil, togRPCError(err)
  30. }
  31. return resp, nil
  32. }
  33. func (as *AuthServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) {
  34. resp, err := as.authenticator.AuthDisable(ctx, r)
  35. if err != nil {
  36. return nil, togRPCError(err)
  37. }
  38. return resp, nil
  39. }
  40. func (as *AuthServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) {
  41. resp, err := as.authenticator.Authenticate(ctx, r)
  42. if err != nil {
  43. return nil, togRPCError(err)
  44. }
  45. return resp, nil
  46. }
  47. func (as *AuthServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) {
  48. resp, err := as.authenticator.RoleAdd(ctx, r)
  49. if err != nil {
  50. return nil, togRPCError(err)
  51. }
  52. return resp, nil
  53. }
  54. func (as *AuthServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) {
  55. resp, err := as.authenticator.RoleDelete(ctx, r)
  56. if err != nil {
  57. return nil, togRPCError(err)
  58. }
  59. return resp, nil
  60. }
  61. func (as *AuthServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) {
  62. resp, err := as.authenticator.RoleGet(ctx, r)
  63. if err != nil {
  64. return nil, togRPCError(err)
  65. }
  66. return resp, nil
  67. }
  68. func (as *AuthServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) {
  69. resp, err := as.authenticator.RoleList(ctx, r)
  70. if err != nil {
  71. return nil, togRPCError(err)
  72. }
  73. return resp, nil
  74. }
  75. func (as *AuthServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) {
  76. resp, err := as.authenticator.RoleRevokePermission(ctx, r)
  77. if err != nil {
  78. return nil, togRPCError(err)
  79. }
  80. return resp, nil
  81. }
  82. func (as *AuthServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) {
  83. resp, err := as.authenticator.RoleGrantPermission(ctx, r)
  84. if err != nil {
  85. return nil, togRPCError(err)
  86. }
  87. return resp, nil
  88. }
  89. func (as *AuthServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) {
  90. resp, err := as.authenticator.UserAdd(ctx, r)
  91. if err != nil {
  92. return nil, togRPCError(err)
  93. }
  94. return resp, nil
  95. }
  96. func (as *AuthServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) {
  97. resp, err := as.authenticator.UserDelete(ctx, r)
  98. if err != nil {
  99. return nil, togRPCError(err)
  100. }
  101. return resp, nil
  102. }
  103. func (as *AuthServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) {
  104. resp, err := as.authenticator.UserGet(ctx, r)
  105. if err != nil {
  106. return nil, togRPCError(err)
  107. }
  108. return resp, nil
  109. }
  110. func (as *AuthServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) {
  111. resp, err := as.authenticator.UserList(ctx, r)
  112. if err != nil {
  113. return nil, togRPCError(err)
  114. }
  115. return resp, nil
  116. }
  117. func (as *AuthServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) {
  118. resp, err := as.authenticator.UserGrantRole(ctx, r)
  119. if err != nil {
  120. return nil, togRPCError(err)
  121. }
  122. return resp, nil
  123. }
  124. func (as *AuthServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) {
  125. resp, err := as.authenticator.UserRevokeRole(ctx, r)
  126. if err != nil {
  127. return nil, togRPCError(err)
  128. }
  129. return resp, nil
  130. }
  131. func (as *AuthServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) {
  132. resp, err := as.authenticator.UserChangePassword(ctx, r)
  133. if err != nil {
  134. return nil, togRPCError(err)
  135. }
  136. return resp, nil
  137. }