Skip to content

Commit

Permalink
remove context from unwrap response
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Jun 18, 2021
1 parent 21f6901 commit a79de7f
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func registerMimeTypes(mimes map[string]string) {
}

func (s *service) SetArbitraryMetadata(ctx context.Context, req *provider.SetArbitraryMetadataRequest) (*provider.SetArbitraryMetadataResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
err := errors.Wrap(err, "storageprovidersvc: error unwrapping path")
return &provider.SetArbitraryMetadataResponse{
Expand Down Expand Up @@ -227,7 +227,7 @@ func (s *service) SetArbitraryMetadata(ctx context.Context, req *provider.SetArb
}

func (s *service) UnsetArbitraryMetadata(ctx context.Context, req *provider.UnsetArbitraryMetadataRequest) (*provider.UnsetArbitraryMetadataResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
err := errors.Wrap(err, "storageprovidersvc: error unwrapping path")
return &provider.UnsetArbitraryMetadataResponse{
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *service) InitiateFileDownload(ctx context.Context, req *provider.Initia
protocol.Protocol = "spaces"
u.Path = path.Join(u.Path, "spaces", req.Ref.ResourceId.StorageId+"!"+req.Ref.ResourceId.OpaqueId, req.Ref.Path)
} else {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.InitiateFileDownloadResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand All @@ -296,7 +296,7 @@ func (s *service) InitiateFileDownload(ctx context.Context, req *provider.Initia
func (s *service) InitiateFileUpload(ctx context.Context, req *provider.InitiateFileUploadRequest) (*provider.InitiateFileUploadResponse, error) {
// TODO(labkode): same considerations as download
log := appctx.GetLogger(ctx)
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
switch err.(type) {
case errtypes.IsNotFound:
Expand Down Expand Up @@ -501,7 +501,7 @@ func (s *service) CreateContainer(ctx context.Context, req *provider.CreateConta
req.Ref.Path = path.Dir(req.Ref.Path)
name = path.Base(req.Ref.Path)
case utils.IsAbsoluteReference(req.Ref):
ctx, ref, err := s.unwrap(ctx, req.Ref)
ref, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.CreateContainerResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -552,7 +552,7 @@ func (s *service) CreateContainer(ctx context.Context, req *provider.CreateConta
}

func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*provider.DeleteResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.DeleteResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -586,13 +586,13 @@ func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro
}

func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provider.MoveResponse, error) {
ctx, sourceRef, err := s.unwrap(ctx, req.Source)
sourceRef, err := s.unwrap(ctx, req.Source)
if err != nil {
return &provider.MoveResponse{
Status: status.NewInternal(ctx, err, "error unwrapping source path"),
}, nil
}
ctx, targetRef, err := s.unwrap(ctx, req.Destination)
targetRef, err := s.unwrap(ctx, req.Destination)
if err != nil {
switch err.(type) {
case errtypes.IsNotFound:
Expand Down Expand Up @@ -633,7 +633,7 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide
trace.StringAttribute("ref", req.Ref.String()),
)

ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
var st *rpc.Status
if err != nil {
switch err.(type) {
Expand Down Expand Up @@ -680,7 +680,7 @@ func (s *service) ListContainerStream(req *provider.ListContainerStreamRequest,
ctx := ss.Context()
log := appctx.GetLogger(ctx)

ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
res := &provider.ListContainerStreamResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -739,7 +739,7 @@ func (s *service) ListContainerStream(req *provider.ListContainerStreamRequest,
}

func (s *service) ListContainer(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.ListContainerResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -780,7 +780,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
}

func (s *service) ListFileVersions(ctx context.Context, req *provider.ListFileVersionsRequest) (*provider.ListFileVersionsResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.ListFileVersionsResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -811,7 +811,7 @@ func (s *service) ListFileVersions(ctx context.Context, req *provider.ListFileVe
}

func (s *service) RestoreFileVersion(ctx context.Context, req *provider.RestoreFileVersionRequest) (*provider.RestoreFileVersionResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.RestoreFileVersionResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -966,7 +966,7 @@ func (s *service) PurgeRecycle(ctx context.Context, req *provider.PurgeRecycleRe
}

func (s *service) ListGrants(ctx context.Context, req *provider.ListGrantsRequest) (*provider.ListGrantsResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.ListGrantsResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -997,7 +997,7 @@ func (s *service) ListGrants(ctx context.Context, req *provider.ListGrantsReques
}

func (s *service) AddGrant(ctx context.Context, req *provider.AddGrantRequest) (*provider.AddGrantResponse, error) {
ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.AddGrantResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -1041,7 +1041,7 @@ func (s *service) UpdateGrant(ctx context.Context, req *provider.UpdateGrantRequ
}, nil
}

ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.UpdateGrantResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func (s *service) RemoveGrant(ctx context.Context, req *provider.RemoveGrantRequ
}, nil
}

ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.RemoveGrantResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -1117,7 +1117,7 @@ func (s *service) CreateReference(ctx context.Context, req *provider.CreateRefer
}, nil
}

ctx, newRef, err := s.unwrap(ctx, req.Ref)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.CreateReferenceResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
Expand Down Expand Up @@ -1183,29 +1183,29 @@ func getFS(c *config) (storage.FS, error) {
return nil, errtypes.NotFound("driver not found: " + c.Driver)
}

func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (context.Context, *provider.Reference, error) {
func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provider.Reference, error) {
// all references with an id can be passed on to the driver
// there are two cases:
// 1. absolute id references (resource_id is set, path is empty)
// 2. relative references (resource_id is set, path starts with a `.`)
if ref.ResourceId != nil {
return ctx, ref, nil
return ref, nil
}

// if the
if !strings.HasPrefix(ref.GetPath(), "/") {
// abort, absolute path references must start with a `/``
return ctx, nil, errtypes.BadRequest("ref is invalid: " + ref.String())
return nil, errtypes.BadRequest("ref is invalid: " + ref.String())
}

// TODO move mount path trimming to the gateway
fn := ref.GetPath()
fsfn, err := s.trimMountPrefix(fn)
if err != nil {
return ctx, nil, err
return nil, err
}

return ctx, &provider.Reference{Path: fsfn}, nil
return &provider.Reference{Path: fsfn}, nil
}

func (s *service) trimMountPrefix(fn string) (string, error) {
Expand Down

0 comments on commit a79de7f

Please sign in to comment.