Skip to content

Commit

Permalink
command/agent/csi_endpoint: we don't need Put to check id
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Aug 5, 2020
1 parent 057312e commit 0af4735
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions command/agent/csi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func (s *HTTPServer) CSIVolumesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
switch req.Method {
case http.MethodPut, http.MethodPost:
return s.csiVolumePost(resp, req)
return s.csiVolumePut(resp, req)
case http.MethodGet:
default:
return nil, CodedError(405, ErrInvalidMethod)
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s *HTTPServer) csiVolumeGet(id string, resp http.ResponseWriter, req *http
return vol, nil
}

func (s *HTTPServer) csiVolumePost(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
func (s *HTTPServer) csiVolumePut(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
switch req.Method {
case http.MethodPost, http.MethodPut:
default:
Expand All @@ -128,35 +128,6 @@ func (s *HTTPServer) csiVolumePost(resp http.ResponseWriter, req *http.Request)
return nil, nil
}

func (s *HTTPServer) csiVolumePut(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != http.MethodPut {
return nil, CodedError(405, ErrInvalidMethod)
}

args0 := structs.CSIVolumeRegisterRequest{}
if err := decodeBody(req, &args0); err != nil {
return err, CodedError(400, err.Error())
}

if len(args0.Volumes) != 1 || id != args0.Volumes[0].ID {
return nil, CodedError(400, "URL ID does not match Volume body")
}

args := structs.CSIVolumeRegisterRequest{
Volumes: args0.Volumes,
}
s.parseWriteRequest(req, &args.WriteRequest)

var out structs.CSIVolumeRegisterResponse
if err := s.agent.RPC("CSIVolume.Register", &args, &out); err != nil {
return nil, err
}

setMeta(resp, &out.QueryMeta)

return nil, nil
}

func (s *HTTPServer) csiVolumeDelete(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != "DELETE" {
return nil, CodedError(405, ErrInvalidMethod)
Expand Down

0 comments on commit 0af4735

Please sign in to comment.