auth.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. "github.com/coreos/etcd/etcdserver"
  17. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  18. "golang.org/x/net/context"
  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. plog.Info("not implemented yet")
  56. return nil, nil
  57. }
  58. func (as *AuthServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) {
  59. resp, err := as.authenticator.RoleGet(ctx, r)
  60. if err != nil {
  61. return nil, togRPCError(err)
  62. }
  63. return resp, nil
  64. }
  65. func (as *AuthServer) RoleRevoke(ctx context.Context, r *pb.AuthRoleRevokeRequest) (*pb.AuthRoleRevokeResponse, error) {
  66. resp, err := as.authenticator.RoleRevoke(ctx, r)
  67. if err != nil {
  68. return nil, togRPCError(err)
  69. }
  70. return resp, nil
  71. }
  72. func (as *AuthServer) RoleGrant(ctx context.Context, r *pb.AuthRoleGrantRequest) (*pb.AuthRoleGrantResponse, error) {
  73. resp, err := as.authenticator.RoleGrant(ctx, r)
  74. if err != nil {
  75. return nil, togRPCError(err)
  76. }
  77. return resp, nil
  78. }
  79. func (as *AuthServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) {
  80. resp, err := as.authenticator.UserAdd(ctx, r)
  81. if err != nil {
  82. return nil, togRPCError(err)
  83. }
  84. return resp, nil
  85. }
  86. func (as *AuthServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) {
  87. resp, err := as.authenticator.UserDelete(ctx, r)
  88. if err != nil {
  89. return nil, togRPCError(err)
  90. }
  91. return resp, nil
  92. }
  93. func (as *AuthServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) {
  94. resp, err := as.authenticator.UserGet(ctx, r)
  95. if err != nil {
  96. return nil, togRPCError(err)
  97. }
  98. return resp, nil
  99. }
  100. func (as *AuthServer) UserGrant(ctx context.Context, r *pb.AuthUserGrantRequest) (*pb.AuthUserGrantResponse, error) {
  101. resp, err := as.authenticator.UserGrant(ctx, r)
  102. if err != nil {
  103. return nil, togRPCError(err)
  104. }
  105. return resp, nil
  106. }
  107. func (as *AuthServer) UserRevoke(ctx context.Context, r *pb.AuthUserRevokeRequest) (*pb.AuthUserRevokeResponse, error) {
  108. resp, err := as.authenticator.UserRevoke(ctx, r)
  109. if err != nil {
  110. return nil, togRPCError(err)
  111. }
  112. return resp, nil
  113. }
  114. func (as *AuthServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) {
  115. resp, err := as.authenticator.UserChangePassword(ctx, r)
  116. if err != nil {
  117. return nil, togRPCError(err)
  118. }
  119. return resp, nil
  120. }