Return info for DiskInfo when the disk is unformatted (#14427)

In a distributed setup, a DiskInfo REST call to an unformatted disk
returns an error with no disk information, such as the disk endpoint
URL, which is unexpected.
This commit is contained in:
Anis Elleuch 2022-03-02 00:06:47 +01:00 committed by GitHub
parent b030ef1aca
commit 4a15bd8ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,7 +109,7 @@ func storageServerRequestValidate(r *http.Request) error {
} }
// IsValid - To authenticate and verify the time difference. // IsValid - To authenticate and verify the time difference.
func (s *storageRESTServer) IsValid(w http.ResponseWriter, r *http.Request) bool { func (s *storageRESTServer) IsAuthValid(w http.ResponseWriter, r *http.Request) bool {
if s.storage == nil { if s.storage == nil {
s.writeErrorResponse(w, errDiskNotFound) s.writeErrorResponse(w, errDiskNotFound)
return false return false
@ -120,6 +120,15 @@ func (s *storageRESTServer) IsValid(w http.ResponseWriter, r *http.Request) bool
return false return false
} }
return true
}
// IsValid - To authenticate and check if the disk-id in the request corresponds to the underlying disk.
func (s *storageRESTServer) IsValid(w http.ResponseWriter, r *http.Request) bool {
if !s.IsAuthValid(w, r) {
return false
}
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
s.writeErrorResponse(w, err) s.writeErrorResponse(w, err)
return false return false
@ -155,7 +164,7 @@ func (s *storageRESTServer) HealthHandler(w http.ResponseWriter, r *http.Request
// DiskInfoHandler - returns disk info. // DiskInfoHandler - returns disk info.
func (s *storageRESTServer) DiskInfoHandler(w http.ResponseWriter, r *http.Request) { func (s *storageRESTServer) DiskInfoHandler(w http.ResponseWriter, r *http.Request) {
if !s.IsValid(w, r) { if !s.IsAuthValid(w, r) {
return return
} }
info, err := s.storage.DiskInfo(r.Context()) info, err := s.storage.DiskInfo(r.Context())