auth.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 grpcproxy
  15. import (
  16. "golang.org/x/net/context"
  17. "github.com/coreos/etcd/clientv3"
  18. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  19. )
  20. type AuthProxy struct {
  21. client *clientv3.Client
  22. }
  23. func NewAuthProxy(c *clientv3.Client) pb.AuthServer {
  24. return &AuthProxy{client: c}
  25. }
  26. func (ap *AuthProxy) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) {
  27. conn := ap.client.ActiveConnection()
  28. return pb.NewAuthClient(conn).AuthEnable(ctx, r)
  29. }
  30. func (ap *AuthProxy) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) {
  31. conn := ap.client.ActiveConnection()
  32. return pb.NewAuthClient(conn).AuthDisable(ctx, r)
  33. }
  34. func (ap *AuthProxy) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) {
  35. conn := ap.client.ActiveConnection()
  36. return pb.NewAuthClient(conn).Authenticate(ctx, r)
  37. }
  38. func (ap *AuthProxy) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) {
  39. conn := ap.client.ActiveConnection()
  40. return pb.NewAuthClient(conn).RoleAdd(ctx, r)
  41. }
  42. func (ap *AuthProxy) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) {
  43. conn := ap.client.ActiveConnection()
  44. return pb.NewAuthClient(conn).RoleDelete(ctx, r)
  45. }
  46. func (ap *AuthProxy) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) {
  47. conn := ap.client.ActiveConnection()
  48. return pb.NewAuthClient(conn).RoleGet(ctx, r)
  49. }
  50. func (ap *AuthProxy) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) {
  51. conn := ap.client.ActiveConnection()
  52. return pb.NewAuthClient(conn).RoleList(ctx, r)
  53. }
  54. func (ap *AuthProxy) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) {
  55. conn := ap.client.ActiveConnection()
  56. return pb.NewAuthClient(conn).RoleRevokePermission(ctx, r)
  57. }
  58. func (ap *AuthProxy) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) {
  59. conn := ap.client.ActiveConnection()
  60. return pb.NewAuthClient(conn).RoleGrantPermission(ctx, r)
  61. }
  62. func (ap *AuthProxy) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) {
  63. conn := ap.client.ActiveConnection()
  64. return pb.NewAuthClient(conn).UserAdd(ctx, r)
  65. }
  66. func (ap *AuthProxy) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) {
  67. conn := ap.client.ActiveConnection()
  68. return pb.NewAuthClient(conn).UserDelete(ctx, r)
  69. }
  70. func (ap *AuthProxy) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) {
  71. conn := ap.client.ActiveConnection()
  72. return pb.NewAuthClient(conn).UserGet(ctx, r)
  73. }
  74. func (ap *AuthProxy) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) {
  75. conn := ap.client.ActiveConnection()
  76. return pb.NewAuthClient(conn).UserList(ctx, r)
  77. }
  78. func (ap *AuthProxy) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) {
  79. conn := ap.client.ActiveConnection()
  80. return pb.NewAuthClient(conn).UserGrantRole(ctx, r)
  81. }
  82. func (ap *AuthProxy) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) {
  83. conn := ap.client.ActiveConnection()
  84. return pb.NewAuthClient(conn).UserRevokeRole(ctx, r)
  85. }
  86. func (ap *AuthProxy) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) {
  87. conn := ap.client.ActiveConnection()
  88. return pb.NewAuthClient(conn).UserChangePassword(ctx, r)
  89. }