From fc0d5bfca1872341667a0d065fbc6993ca4755a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 25 Sep 2024 14:49:41 +0200 Subject: [PATCH] improve metadata client errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../unreleased/improve-metadata-client-log.md | 5 ++++ pkg/storage/utils/metadata/cs3.go | 25 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/improve-metadata-client-log.md diff --git a/changelog/unreleased/improve-metadata-client-log.md b/changelog/unreleased/improve-metadata-client-log.md new file mode 100644 index 0000000000..64a4d8b35e --- /dev/null +++ b/changelog/unreleased/improve-metadata-client-log.md @@ -0,0 +1,5 @@ +Enhancement: Improve metadata client errors + +We now return a more descripive error message when the metadata client cannot create a space because it already exists. + +https://github.com/cs3org/reva/pull/4868 diff --git a/pkg/storage/utils/metadata/cs3.go b/pkg/storage/utils/metadata/cs3.go index 63cbb463bf..0c2656c9c4 100644 --- a/pkg/storage/utils/metadata/cs3.go +++ b/pkg/storage/utils/metadata/cs3.go @@ -22,6 +22,7 @@ import ( "bytes" "context" "errors" + "fmt" "io" "net/http" "os" @@ -107,6 +108,27 @@ func (cs3 *CS3) Init(ctx context.Context, spaceid string) (err error) { if err != nil { return err } + + lsRes, err := client.ListStorageSpaces(ctx, &provider.ListStorageSpacesRequest{ + Filters: []*provider.ListStorageSpacesRequest_Filter{ + { + Type: provider.ListStorageSpacesRequest_Filter_TYPE_ID, + Term: &provider.ListStorageSpacesRequest_Filter_Id{ + Id: &provider.StorageSpaceId{OpaqueId: spaceid + "!" + spaceid}, + }, + }, + }, + }) + switch { + case err != nil: + return err + case lsRes.Status.Code == rpc.Code_CODE_OK && len(lsRes.StorageSpaces) > 0: + if len(lsRes.StorageSpaces) > 0 { + cs3.SpaceRoot = lsRes.StorageSpaces[0].Root + return nil + } + } + // FIXME change CS3 api to allow sending a space id cssr, err := client.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{ Opaque: &types.Opaque{ @@ -127,8 +149,7 @@ func (cs3 *CS3) Init(ctx context.Context, spaceid string) (err error) { case cssr.Status.Code == rpc.Code_CODE_OK: cs3.SpaceRoot = cssr.StorageSpace.Root case cssr.Status.Code == rpc.Code_CODE_ALREADY_EXISTS: - // TODO make CreateStorageSpace return existing space? - cs3.SpaceRoot = &provider.ResourceId{SpaceId: spaceid, OpaqueId: spaceid} + return errtypes.AlreadyExists(fmt.Sprintf("user %s does not have access to metadata space %s, but it exists", cs3.serviceUser.Id.OpaqueId, spaceid)) default: return errtypes.NewErrtypeFromStatus(cssr.Status) }