Skip to content

Commit

Permalink
Merge pull request #890 from hashicorp/b-fs-panic
Browse files Browse the repository at this point in the history
Guard client/ api to ensure the client is running
  • Loading branch information
dadgar committed Mar 7, 2016
2 parents 4aeb482 + 6454d7b commit 171eff7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 19 additions & 0 deletions command/agent/fs_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,27 @@ import (
var (
allocIDNotPresentErr = fmt.Errorf("must provide a valid alloc id")
fileNameNotPresentErr = fmt.Errorf("must provide a file name")
clientNotRunning = fmt.Errorf("node is not running a Nomad Client")
)

func (s *HTTPServer) FsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if s.agent.client == nil {
return nil, clientNotRunning
}

path := strings.TrimPrefix(req.URL.Path, "/v1/client/fs/")
switch {
case strings.HasPrefix(path, "ls/"):
return s.DirectoryListRequest(resp, req)
case strings.HasPrefix(path, "stat/"):
return s.FileStatRequest(resp, req)
case strings.HasPrefix(path, "readat/"):
return s.FileReadAtRequest(resp, req)
default:
return nil, CodedError(404, ErrInvalidMethod)
}
}

func (s *HTTPServer) DirectoryListRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
var allocID, path string

Expand Down
4 changes: 1 addition & 3 deletions command/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
s.mux.HandleFunc("/v1/evaluations", s.wrap(s.EvalsRequest))
s.mux.HandleFunc("/v1/evaluation/", s.wrap(s.EvalSpecificRequest))

s.mux.HandleFunc("/v1/client/fs/ls/", s.wrap(s.DirectoryListRequest))
s.mux.HandleFunc("/v1/client/fs/stat/", s.wrap(s.FileStatRequest))
s.mux.HandleFunc("/v1/client/fs/readat/", s.wrap(s.FileReadAtRequest))
s.mux.HandleFunc("/v1/client/fs/", s.wrap(s.FsRequest))

s.mux.HandleFunc("/v1/agent/self", s.wrap(s.AgentSelfRequest))
s.mux.HandleFunc("/v1/agent/join", s.wrap(s.AgentJoinRequest))
Expand Down

0 comments on commit 171eff7

Please sign in to comment.