auth.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2016 Nippon Telegraph and Telephone Corporation.
  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 clientv3
  15. import (
  16. "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
  17. "github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
  18. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  19. )
  20. type (
  21. AuthEnableResponse pb.AuthEnableResponse
  22. )
  23. type Auth interface {
  24. // AuthEnable enables auth of a etcd cluster.
  25. AuthEnable(ctx context.Context) (*AuthEnableResponse, error)
  26. }
  27. type auth struct {
  28. c *Client
  29. conn *grpc.ClientConn // conn in-use
  30. remote pb.AuthClient
  31. }
  32. func NewAuth(c *Client) Auth {
  33. conn := c.ActiveConnection()
  34. return &auth{
  35. conn: c.ActiveConnection(),
  36. remote: pb.NewAuthClient(conn),
  37. c: c,
  38. }
  39. }
  40. func (auth *auth) AuthEnable(ctx context.Context) (*AuthEnableResponse, error) {
  41. resp, err := auth.remote.AuthEnable(ctx, &pb.AuthEnableRequest{})
  42. return (*AuthEnableResponse)(resp), err
  43. }