Skip to content

Commit

Permalink
[nspcc-dev#112] Move getBoxData from handler to layer
Browse files Browse the repository at this point in the history
And made it exported

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
  • Loading branch information
masterSplinter01 committed Jul 28, 2021
1 parent 97a7d16 commit c24fe5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
18 changes: 1 addition & 17 deletions api/handler/put.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handler

import (
"context"
"encoding/xml"
"fmt"
"net/http"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
19 changes: 19 additions & 0 deletions api/layer/util.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package layer

import (
"context"
"fmt"
"os"
"strconv"
"strings"
"time"

"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 (
Expand Down Expand Up @@ -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
}

0 comments on commit c24fe5c

Please sign in to comment.