From 92b039fa5e3a44e0caa5905be585e9abecfe9f6f Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Wed, 19 Aug 2020 14:52:44 +0300 Subject: [PATCH 1/2] Add unsupported handlers Signed-off-by: Evgeniy Kulikov --- api/handler/api.go | 2 ++ api/handler/not-support.go | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 api/handler/not-support.go diff --git a/api/handler/api.go b/api/handler/api.go index 9499fca1..bdea9147 100644 --- a/api/handler/api.go +++ b/api/handler/api.go @@ -20,6 +20,8 @@ type ( } ) +const notSupported = "Not supported by NeoFS S3 Gate: " + var _ api.Handler = (*handler)(nil) func New(log *zap.Logger, obj layer.Client) (api.Handler, error) { diff --git a/api/handler/not-support.go b/api/handler/not-support.go new file mode 100644 index 00000000..f5795eb0 --- /dev/null +++ b/api/handler/not-support.go @@ -0,0 +1,72 @@ +package handler + +import ( + "net/http" + + "github.com/gorilla/mux" + "github.com/nspcc-dev/neofs-s3-gate/api" +) + +func (h *handler) DeleteBucketHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} + +func (h *handler) DeleteBucketPolicyHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} + +func (h *handler) DeleteBucketLifecycleHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} + +func (h *handler) DeleteBucketEncryptionHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} + +func (h *handler) PutBucketTaggingHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} + +func (h *handler) PutBucketVersioningHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} + +func (h *handler) PutBucketNotificationHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} + +func (h *handler) PutBucketHandler(w http.ResponseWriter, r *http.Request) { + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrBadRequest).Code, + Description: notSupported + mux.CurrentRoute(r).GetName(), + HTTPStatusCode: http.StatusNotImplemented, + }, r.URL) +} From cea8f9d4cacacd9e69b4d6524cbb42e2d1bf373d Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Wed, 19 Aug 2020 14:53:17 +0300 Subject: [PATCH 2/2] Add bucket info handler Signed-off-by: Evgeniy Kulikov --- api/handler/info.go | 40 ++++++++++++++++++++ api/handler/response.go | 6 +++ api/handler/unimplemented.go | 72 ------------------------------------ 3 files changed, 46 insertions(+), 72 deletions(-) create mode 100644 api/handler/info.go diff --git a/api/handler/info.go b/api/handler/info.go new file mode 100644 index 00000000..5d0200ed --- /dev/null +++ b/api/handler/info.go @@ -0,0 +1,40 @@ +package handler + +import ( + "net/http" + + "github.com/gorilla/mux" + "github.com/nspcc-dev/neofs-s3-gate/api" + "go.uber.org/zap" +) + +func (h *handler) GetBucketLocationHandler(w http.ResponseWriter, r *http.Request) { + var ( + bkt = mux.Vars(r)["bucket"] + rid = api.GetRequestID(r.Context()) + ) + + if _, err := h.obj.GetBucketInfo(r.Context(), bkt); err != nil { + h.log.Error("something went wrong", + zap.String("request_id", rid), + zap.Error(err)) + + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrInternalError).Code, + Description: err.Error(), + HTTPStatusCode: http.StatusInternalServerError, + }, r.URL) + + return + } else if err = api.EncodeToResponse(w, LocationResponse{Location: ""}); err != nil { + h.log.Error("could not write response", + zap.String("request_id", rid), + zap.Error(err)) + + api.WriteErrorResponse(r.Context(), w, api.Error{ + Code: api.GetAPIError(api.ErrInternalError).Code, + Description: err.Error(), + HTTPStatusCode: http.StatusInternalServerError, + }, r.URL) + } +} diff --git a/api/handler/response.go b/api/handler/response.go index 07628f87..c178a6d3 100644 --- a/api/handler/response.go +++ b/api/handler/response.go @@ -80,3 +80,9 @@ type Object struct { // StringMap is a map[string]string. type StringMap map[string]string + +// LocationResponse - format for location response. +type LocationResponse struct { + XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint" json:"-"` + Location string `xml:",chardata"` +} diff --git a/api/handler/unimplemented.go b/api/handler/unimplemented.go index 741cefaf..e0a3c619 100644 --- a/api/handler/unimplemented.go +++ b/api/handler/unimplemented.go @@ -175,14 +175,6 @@ func (h *handler) DeleteObjectHandler(w http.ResponseWriter, r *http.Request) { }, r.URL) } -func (h *handler) GetBucketLocationHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - func (h *handler) GetBucketPolicyHandler(w http.ResponseWriter, r *http.Request) { api.WriteErrorResponse(r.Context(), w, api.Error{ Code: "XNeoFSUnimplemented", @@ -391,38 +383,6 @@ func (h *handler) PutBucketObjectLockConfigHandler(w http.ResponseWriter, r *htt }, r.URL) } -func (h *handler) PutBucketTaggingHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - -func (h *handler) PutBucketVersioningHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - -func (h *handler) PutBucketNotificationHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - -func (h *handler) PutBucketHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - func (h *handler) HeadBucketHandler(w http.ResponseWriter, r *http.Request) { api.WriteErrorResponse(r.Context(), w, api.Error{ Code: "XNeoFSUnimplemented", @@ -446,35 +406,3 @@ func (h *handler) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *http.Re HTTPStatusCode: http.StatusNotImplemented, }, r.URL) } - -func (h *handler) DeleteBucketPolicyHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - -func (h *handler) DeleteBucketLifecycleHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - -func (h *handler) DeleteBucketEncryptionHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -} - -func (h *handler) DeleteBucketHandler(w http.ResponseWriter, r *http.Request) { - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: "XNeoFSUnimplemented", - Description: "implement me " + mux.CurrentRoute(r).GetName(), - HTTPStatusCode: http.StatusNotImplemented, - }, r.URL) -}