From fe558e9de9542dd72198175eff65c6daa2918357 Mon Sep 17 00:00:00 2001 From: Jesse Geens Date: Fri, 29 Nov 2024 09:55:28 +0100 Subject: [PATCH] Clean up GetPathByID --- pkg/storage/utils/eosfs/eosfs.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 60bc5f6813..70883de876 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -487,26 +487,24 @@ func (fs *eosfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (stri if err != nil { return "", errors.Wrap(err, "eosfs: no user in ctx") } + + var auth eosclient.Authorization if utils.IsLightweightUser(u) { - daemonAuth := utils.GetDaemonAuth() - eosFileInfo, err := fs.c.GetFileInfoByInode(ctx, daemonAuth, fid) + auth = utils.GetDaemonAuth() + } else { + auth, err = fs.getUserAuth(ctx, u, "") if err != nil { - return "", errors.Wrap(err, "eosfs: error getting file info by inode") - } - if perm := fs.permissionSet(ctx, eosFileInfo, nil); perm.GetPath { - return fs.unwrap(ctx, eosFileInfo.File) + return "", err } - return "", errtypes.PermissionDenied("eosfs: getting path for id not allowed") } - userAuth, err := fs.getUserAuth(ctx, u, "") + eosFileInfo, err := fs.c.GetFileInfoByInode(ctx, auth, fid) if err != nil { - return "", err + return "", errors.Wrap(err, "eosfs: error getting file info by inode") } - eosFileInfo, err := fs.c.GetFileInfoByInode(ctx, userAuth, fid) - if err != nil { - return "", errors.Wrap(err, "eosfs: error getting file info by inode") + if perm := fs.permissionSet(ctx, eosFileInfo, nil); !perm.GetPath { + return "", errtypes.PermissionDenied("eosfs: getting path for id not allowed") } return fs.unwrap(ctx, eosFileInfo.File)