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