Skip to content

Commit

Permalink
Refactored handling of the eos "app" tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Aug 13, 2024
1 parent c5a6266 commit e987a60
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
16 changes: 1 addition & 15 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (
"syscall"
"time"

erpc "github.com/cern-eos/go-eosgrpc"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/eosclient"
erpc "github.com/cern-eos/go-eosgrpc"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/storage/utils/acl"
"github.com/google/uuid"
Expand Down Expand Up @@ -1361,20 +1361,6 @@ func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path s
}

return c.httpcl.PUTFile(ctx, u.Username, auth, path, stream, length, app)

// return c.httpcl.PUTFile(ctx, remoteuser, auth, urlpathng, stream)
// return c.WriteFile(ctx, uid, gid, path, fd.Name())
}

// WriteFile writes an existing file to the mgm. Old xrdcp utility.
func (c *Client) WriteFile(ctx context.Context, auth eosclient.Authorization, path, source, app string) error {
log := appctx.GetLogger(ctx)
log.Info().Str("func", "WriteFile").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Str("source", source).Msg("")

xrdPath := fmt.Sprintf("%s//%s", c.opt.URL, path)
cmd := exec.CommandContext(ctx, c.opt.XrdcopyBinary, "--nopbar", "--silent", "-f", source, xrdPath, fmt.Sprintf("-ODeos.ruid=%s&eos.rgid=%s", auth.Role.UID, auth.Role.GID))
_, _, err := c.execute(ctx, cmd)
return err
}

// ListDeletedEntries returns a list of the deleted entries.
Expand Down
2 changes: 2 additions & 0 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ func (c *EOSHTTPClient) GETFile(ctx context.Context, remoteuser string, auth eos
log.Error().Str("func", "GETFile").Str("url", finalurl).Str("err", err.Error()).Msg("can't create request")
return nil, err
}
// similar to eosbinary.go::Read()
req.Header.Set("app", "reva_eosclient::read")

ntries := 0
nredirs := 0
Expand Down
25 changes: 13 additions & 12 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ func (fs *eosfs) UnsetArbitraryMetadata(ctx context.Context, ref *provider.Refer
return nil
}

func (fs *eosfs) EncodeAppName(a string) string {
// this function returns the string to be used as EOS "app" tag, both in uploads and when handling locks
r := strings.NewReplacer(" ", "_")
return "reva_eosclient::app_" + strings.ToLower(r.Replace(a))
}

func (fs *eosfs) getLockPayloads(ctx context.Context, path string) (string, string, error) {
// sys attributes want root auth, buddy
rootauth, err := fs.getRootAuth(ctx)
Expand Down Expand Up @@ -663,7 +669,7 @@ func (fs *eosfs) getLock(ctx context.Context, user *userpb.User, path string, re

if time.Unix(int64(l.Expiration.Seconds), 0).Before(time.Now()) {
// the lock expired
if err := fs.removeLockAttrs(ctx, path, encodeAppName(l.AppName)); err != nil {
if err := fs.removeLockAttrs(ctx, path, fs.EncodeAppName(l.AppName)); err != nil {
return nil, err
}
return nil, errtypes.NotFound("lock not found for ref")
Expand Down Expand Up @@ -704,7 +710,7 @@ func (fs *eosfs) setLock(ctx context.Context, lock *provider.Lock, path string)
return err
}

encodedLock, eosLock, err := encodeLock(lock)
encodedLock, eosLock, err := fs.encodeLock(lock)
if err != nil {
return errors.Wrap(err, "eosfs: error encoding lock")
}
Expand All @@ -714,7 +720,7 @@ func (fs *eosfs) setLock(ctx context.Context, lock *provider.Lock, path string)
Type: SystemAttr,
Key: eosLockKey,
Val: eosLock,
}, false, false, path, encodeAppName(lock.AppName))
}, false, false, path, fs.EncodeAppName(lock.AppName))
switch {
case errors.Is(err, eosclient.FileIsLockedError):
return errtypes.Conflict("resource already locked")
Expand All @@ -727,7 +733,7 @@ func (fs *eosfs) setLock(ctx context.Context, lock *provider.Lock, path string)
Type: SystemAttr,
Key: lockPayloadKey,
Val: encodedLock,
}, false, false, path, encodeAppName(lock.AppName))
}, false, false, path, fs.EncodeAppName(lock.AppName))
if err != nil {
return errors.Wrap(err, "eosfs: error setting lock payload")
}
Expand Down Expand Up @@ -822,20 +828,15 @@ func (fs *eosfs) userHasReadAccess(ctx context.Context, user *userpb.User, ref *
return resInfo.PermissionSet.InitiateFileDownload, nil
}

func encodeAppName(a string) string {
r := strings.NewReplacer(" ", "_")
return "reva_" + strings.ToLower(r.Replace(a))
}

func encodeLock(l *provider.Lock) (string, string, error) {
func (fs *eosfs) encodeLock(l *provider.Lock) (string, string, error) {
data, err := json.Marshal(l)
if err != nil {
return "", "", err
}
var a string
if l.AppName != "" {
// cf. upload implementation
a = encodeAppName(l.AppName)
a = fs.EncodeAppName(l.AppName)
} else {
a = "*"
}
Expand Down Expand Up @@ -976,7 +977,7 @@ func (fs *eosfs) Unlock(ctx context.Context, ref *provider.Reference, lock *prov
}
path = fs.wrap(ctx, path)

return fs.removeLockAttrs(ctx, path, encodeAppName(lock.AppName))
return fs.removeLockAttrs(ctx, path, fs.EncodeAppName(lock.AppName))
}

func (fs *eosfs) AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error {
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/utils/eosfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io"
"os"
"path"
"strings"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/errtypes"
Expand Down Expand Up @@ -81,8 +80,8 @@ func (fs *eosfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadC
if app == "" {
app = "reva_eosclient::write"
} else {
r := strings.NewReplacer(" ", "_")
app = "reva_" + strings.ToLower(r.Replace(app))
// if we have a lock context, the app for EOS must match the lock holder
app = fs.EncodeAppName(app)
}
return fs.c.Write(ctx, auth, fn, r, app)
}
Expand Down

0 comments on commit e987a60

Please sign in to comment.