|
|
@ -32,17 +32,23 @@ func validateHandler(conf config.Config, h http.Handler) http.Handler { |
|
|
|
|
|
|
|
|
|
|
|
func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|
|
|
func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|
|
|
accessKey := stripAccessKey(r) |
|
|
|
accessKey := stripAccessKey(r) |
|
|
|
|
|
|
|
acceptsContentType := getContentType(r) |
|
|
|
if accessKey != "" { |
|
|
|
if accessKey != "" { |
|
|
|
if err := h.conf.ReadConfig(); err != nil { |
|
|
|
if err := h.conf.ReadConfig(); err != nil { |
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
error := errorCodeError(InternalError) |
|
|
|
|
|
|
|
errorResponse := getErrorResponse(error, "") |
|
|
|
|
|
|
|
w.WriteHeader(error.HttpStatusCode) |
|
|
|
|
|
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
user := h.conf.GetKey(accessKey) |
|
|
|
user := h.conf.GetKey(accessKey) |
|
|
|
ok, err := signers.ValidateRequest(user, r) |
|
|
|
ok, _ := signers.ValidateRequest(user, r) |
|
|
|
if ok { |
|
|
|
if ok { |
|
|
|
h.handler.ServeHTTP(w, r) |
|
|
|
h.handler.ServeHTTP(w, r) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
|
|
|
error := errorCodeError(AccessDenied) |
|
|
|
w.Write([]byte(err.Error())) |
|
|
|
errorResponse := getErrorResponse(error, "") |
|
|
|
|
|
|
|
w.WriteHeader(error.HttpStatusCode) |
|
|
|
|
|
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -58,8 +64,12 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
|
|
|
|
func ignoreUnimplementedResources(h http.Handler) http.Handler { |
|
|
|
func ignoreUnimplementedResources(h http.Handler) http.Handler { |
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
acceptsContentType := getContentType(r) |
|
|
|
if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) { |
|
|
|
if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) { |
|
|
|
w.WriteHeader(http.StatusNotImplemented) |
|
|
|
error := errorCodeError(NotImplemented) |
|
|
|
|
|
|
|
errorResponse := getErrorResponse(error, "") |
|
|
|
|
|
|
|
w.WriteHeader(error.HttpStatusCode) |
|
|
|
|
|
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
h.ServeHTTP(w, r) |
|
|
|
h.ServeHTTP(w, r) |
|
|
|
} |
|
|
|
} |
|
|
|