forked from TrueCloudLab/frostfs-s3-gw
[#112] Move getBoxData from handler to layer
And made it exported Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
97a7d16f68
commit
c24fe5cc21
2 changed files with 20 additions and 17 deletions
|
@ -1,7 +1,6 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -13,7 +12,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/policy"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -107,7 +105,7 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
p.BoxData, err = getBoxData(r.Context())
|
||||
p.BoxData, err = layer.GetBoxData(r.Context())
|
||||
if err != nil {
|
||||
h.registerAndSendError(w, r, err, "could not get boxData")
|
||||
return
|
||||
|
@ -172,17 +170,3 @@ func parseBasicACL(basicACL string) (uint32, error) {
|
|||
return uint32(value), nil
|
||||
}
|
||||
}
|
||||
|
||||
func getBoxData(ctx context.Context) (*accessbox.Box, error) {
|
||||
var boxData *accessbox.Box
|
||||
data, ok := ctx.Value(api.BoxData).(*accessbox.Box)
|
||||
if !ok || data == nil {
|
||||
return nil, fmt.Errorf("couldn't get box data from context")
|
||||
}
|
||||
|
||||
boxData = data
|
||||
if boxData.Gate == nil {
|
||||
boxData.Gate = &accessbox.GateData{}
|
||||
}
|
||||
return boxData, nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package layer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -8,6 +10,8 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -172,3 +176,18 @@ func (o *ObjectInfo) ID() *object.ID { return o.id }
|
|||
|
||||
// IsDir allows to check if object is a directory.
|
||||
func (o *ObjectInfo) IsDir() bool { return o.isDir }
|
||||
|
||||
// GetBoxData extracts accessbox.Box from context.
|
||||
func GetBoxData(ctx context.Context) (*accessbox.Box, error) {
|
||||
var boxData *accessbox.Box
|
||||
data, ok := ctx.Value(api.BoxData).(*accessbox.Box)
|
||||
if !ok || data == nil {
|
||||
return nil, fmt.Errorf("couldn't get box data from context")
|
||||
}
|
||||
|
||||
boxData = data
|
||||
if boxData.Gate == nil {
|
||||
boxData.Gate = &accessbox.GateData{}
|
||||
}
|
||||
return boxData, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue