Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Oct 29, 2021
1 parent 2268169 commit f871bc2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 104 deletions.
80 changes: 0 additions & 80 deletions internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package gateway

import (
"context"
"fmt"
"path"

rtrace "github.com/cs3org/reva/pkg/trace"
Expand Down Expand Up @@ -378,85 +377,6 @@ func (s *svc) removeReference(ctx context.Context, resourceID *provider.Resource
return status.NewOK(ctx)
}

func (s *svc) createReference(ctx context.Context, resourceID *provider.ResourceId) *rpc.Status {
ref := &provider.Reference{
ResourceId: resourceID,
}
log := appctx.GetLogger(ctx)

// get the metadata about the share
c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found")
}
return status.NewInternal(ctx, err, "error finding storage provider")
}

statReq := &provider.StatRequest{
Ref: ref,
}

statRes, err := c.Stat(ctx, statReq)
if err != nil {
return status.NewInternal(ctx, err, "gateway: error calling Stat for the share resource id: "+resourceID.String())
}

if statRes.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(statRes.Status.GetCode(), "gateway")
log.Err(err).Msg("gateway: Stat failed on the share resource id: " + resourceID.String())
return status.NewInternal(ctx, err, "error updating received share")
}

homeRes, err := s.GetHome(ctx, &provider.GetHomeRequest{})
if err != nil {
err := errors.Wrap(err, "gateway: error calling GetHome")
return status.NewInternal(ctx, err, "error updating received share")
}

// reference path is the home path + some name
// CreateReferene(cs3://home/MyShares/x)
// that can end up in the storage provider like:
// /eos/user/.shadow/g/gonzalhu/MyShares/x
// A reference can point to any place, for that reason the namespace starts with cs3://
// For example, a reference can point also to a dropbox resource:
// CreateReference(dropbox://x/y/z)
// It is the responsibility of the gateway to resolve these references and merge the response back
// from the main request.
// TODO(labkode): the name of the share should be the filename it points to by default.
refPath := path.Join(homeRes.Path, s.c.ShareFolder, path.Base(statRes.Info.Path))
log.Info().Msg("mount path will be:" + refPath)

createRefReq := &provider.CreateReferenceRequest{
Ref: &provider.Reference{Path: refPath},
// cs3 is the Scheme and %s/%s is the Opaque parts of a net.URL.
TargetUri: fmt.Sprintf("cs3:%s/%s", resourceID.GetStorageId(), resourceID.GetOpaqueId()),
}

c, err = s.findByPath(ctx, homeRes.Path)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found")
}
return status.NewInternal(ctx, err, "error finding storage provider")
}

createRefRes, err := c.CreateReference(ctx, createRefReq)
if err != nil {
log.Err(err).Msg("gateway: error calling GetHome")
return &rpc.Status{
Code: rpc.Code_CODE_INTERNAL,
}
}

if createRefRes.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(createRefRes.Status.GetCode(), "gateway")
return status.NewInternal(ctx, err, "error updating received share")
}

return status.NewOK(ctx)
}

func (s *svc) denyGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee) (*rpc.Status, error) {
ref := &provider.Reference{
ResourceId: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ var _ = Describe("The ocs API", func() {
})

Describe("AcceptReceivedShare", func() {
type responseShare struct {
ID string `xml:"id"`
}
type listSharesData struct {
Shares []responseShare `xml:"element"`
}
type listSharesResponse struct {
Data listSharesData `xml:"data"`
}

var (
resID = &provider.ResourceId{
StorageId: "share1-storageid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func (h *Handler) CreateShare(w http.ResponseWriter, r *http.Request) {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "machine authentication failed", nil)
return
}
//granteeCtx = revactx.ContextSetToken(granteeCtx, authRes.Token)
granteeCtx = metadata.AppendToOutgoingContext(granteeCtx, revactx.TokenHeader, authRes.Token)

lrs, ocsResponse := getSharesList(granteeCtx, client)
Expand Down Expand Up @@ -370,12 +369,11 @@ func (h *Handler) extractPermissions(w http.ResponseWriter, r *http.Request, ri
Message: err.Error(),
Error: err,
}
} else {
return nil, nil, &ocsError{
Code: response.MetaBadRequest.StatusCode,
Message: err.Error(),
Error: err,
}
}
return nil, nil, &ocsError{
Code: response.MetaBadRequest.StatusCode,
Message: err.Error(),
Error: err,
}
}
role = conversions.RoleFromOCSPermissions(perm)
Expand Down
5 changes: 1 addition & 4 deletions pkg/share/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,7 @@ func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.F
// to the same resource. Leave the more explicit and hide the more explicit. In this case we hide the group shares
// and return the user share to the user.
filtered := make([]*collaboration.ReceivedShare, 0)

for _, s := range rss {
filtered = append(filtered, s)
}
filtered = append(filtered, rss...)

for i := range rss {
for j := range rss {
Expand Down
2 changes: 2 additions & 0 deletions pkg/share/manager/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ var _ = Describe("SQL manager", func() {
31, // permissions,
0, // accepted
)
Expect(err).ToNot(HaveOccurred())

shares, err := mgr.ListReceivedShares(ctx, []*collaboration.Filter{})
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -436,6 +437,7 @@ var _ = Describe("SQL manager", func() {
31, // permissions,
0, // accepted
)
Expect(err).ToNot(HaveOccurred())
parentRef := &collaboration.ShareReference{Spec: &collaboration.ShareReference_Id{
Id: &collaboration.ShareId{
OpaqueId: strconv.Itoa(parentID),
Expand Down
9 changes: 6 additions & 3 deletions pkg/user/manager/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (m *manager) GetUser(ctx context.Context, uid *userpb.UserId) (*userpb.User
}
defer l.Close()

userEntry, err := m.getLDAPUserById(ctx, l, uid)
userEntry, err := m.getLDAPUserByID(ctx, l, uid)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -350,11 +350,14 @@ func (m *manager) GetUserGroups(ctx context.Context, uid *userpb.UserId) ([]stri
}
defer l.Close()

userEntry, err := m.getLDAPUserById(ctx, l, uid)
userEntry, err := m.getLDAPUserByID(ctx, l, uid)
if err != nil {
return []string{}, err
}
return m.getLDAPUserGroups(ctx, l, userEntry)
}

func (m *manager) getLDAPUserById(ctx context.Context, conn *ldap.Conn, uid *userpb.UserId) (*ldap.Entry, error) {
func (m *manager) getLDAPUserByID(ctx context.Context, conn *ldap.Conn, uid *userpb.UserId) (*ldap.Entry, error) {
log := appctx.GetLogger(ctx)
// Search for the given clientID, use a sizeLimit of 1 to be able
// to error out early when the userid is not unique
Expand Down

0 comments on commit f871bc2

Please sign in to comment.