From 85533a6305bd7b775494fa2ec84cff7e04f838ce Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Thu, 1 Mar 2018 12:48:56 -0800 Subject: [PATCH] api/v3election: error on missing "leader" field Signed-off-by: Gyuho Lee --- etcdserver/api/v3election/election.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/etcdserver/api/v3election/election.go b/etcdserver/api/v3election/election.go index 51e181446..c66d7a382 100644 --- a/etcdserver/api/v3election/election.go +++ b/etcdserver/api/v3election/election.go @@ -16,12 +16,17 @@ package v3election import ( "context" + "errors" "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/clientv3/concurrency" epb "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb" ) +// ErrMissingLeaderKey is returned when election API request +// is missing the "leader" field. +var ErrMissingLeaderKey = errors.New(`"leader" field must be provided`) + type electionServer struct { c *clientv3.Client } @@ -51,6 +56,9 @@ func (es *electionServer) Campaign(ctx context.Context, req *epb.CampaignRequest } func (es *electionServer) Proclaim(ctx context.Context, req *epb.ProclaimRequest) (*epb.ProclaimResponse, error) { + if req.Leader == nil { + return nil, ErrMissingLeaderKey + } s, err := es.session(ctx, req.Leader.Lease) if err != nil { return nil, err @@ -98,6 +106,9 @@ func (es *electionServer) Leader(ctx context.Context, req *epb.LeaderRequest) (* } func (es *electionServer) Resign(ctx context.Context, req *epb.ResignRequest) (*epb.ResignResponse, error) { + if req.Leader == nil { + return nil, ErrMissingLeaderKey + } s, err := es.session(ctx, req.Leader.Lease) if err != nil { return nil, err