From 9e7f4487ad895afa7717e5c7780298d368b6cdbe Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Wed, 14 May 2025 12:38:57 +0200 Subject: [PATCH] fix wrong pointer Signed-off-by: Christian Richter --- pkg/systemstorageclient/systemstorageclient.go | 13 +++++++++---- services/graph/pkg/service/v0/photo.go | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/systemstorageclient/systemstorageclient.go b/pkg/systemstorageclient/systemstorageclient.go index 826e722683..87c9e6f254 100644 --- a/pkg/systemstorageclient/systemstorageclient.go +++ b/pkg/systemstorageclient/systemstorageclient.go @@ -9,7 +9,7 @@ import ( ) type SystemDataStorageClient struct { - mds *metadata.Storage + mds metadata.Storage } func (s SystemDataStorageClient) SimpleDownload(ctx context.Context, userID, identifier string) ([]byte, error) { @@ -18,7 +18,7 @@ func (s SystemDataStorageClient) SimpleDownload(ctx context.Context, userID, ide } func (s SystemDataStorageClient) SimpleUpload(ctx context.Context, userID, identifier string, content []byte) error { - fmt.Println(content) + s.mds.SimpleUpload(ctx, fmt.Sprintf("%s/%s", userID, identifier), content) return nil } @@ -43,15 +43,20 @@ func (s SystemDataStorageClient) Init(ctx context.Context, userID, identifier st } // NewProfileStorageClient creates a new ProfileStorageClient -func NewSystemStorageClient(nameSpace string, +func NewSystemStorageClient(scope, nameSpace string, logger *log.Logger, gatewayAddress, storageAddress, systemUserID, systemUserIDP, systemUserAPIKey string) SystemDataStorageClient { + + // scope: the scope the data should be persistet in (e.g. user) + // namespace: the namespace the data should be persistet in (e.g. profilephoto) + // results in the following path: //*//* + sdsci := SystemDataStorageClient{} logger.Debug().Msg("NewSystemStorageClient called") sdsc, err := metadata.NewCS3Storage(gatewayAddress, storageAddress, systemUserID, systemUserIDP, systemUserAPIKey) if err != nil { logger.Fatal().Err(err).Msg("could not create profile storage client") } - sdsci.mds = &sdsc + sdsci.mds = sdsc return sdsci } diff --git a/services/graph/pkg/service/v0/photo.go b/services/graph/pkg/service/v0/photo.go index 21d003376a..cbb814a972 100644 --- a/services/graph/pkg/service/v0/photo.go +++ b/services/graph/pkg/service/v0/photo.go @@ -14,6 +14,7 @@ import ( var ( namespace = "profilephoto" + scope = "user" identifier = "profilephoto" ) @@ -90,6 +91,7 @@ func (g Graph) UpdatePhoto(w http.ResponseWriter, r *http.Request) { func (g Graph) updatePhoto(w http.ResponseWriter, r *http.Request, u *userpb.UserId) { logger := g.logger.SubloggerWithRequestID(r.Context()) logger.Debug().Msg("UpdatePhoto called") + g.getSystemStorageClient() content, err := io.ReadAll(r.Body) if err != nil { logger.Debug().Err(err).Msg("could not read body") @@ -101,7 +103,6 @@ func (g Graph) updatePhoto(w http.ResponseWriter, r *http.Request, u *userpb.Use errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "empty body") return } - g.getSystemStorageClient() err = g.sdsc.SimpleUpload(r.Context(), u.GetOpaqueId(), identifier, content) if err != nil { logger.Debug().Err(err).Msg("could not upload photo") @@ -115,6 +116,7 @@ func (g Graph) updatePhoto(w http.ResponseWriter, r *http.Request, u *userpb.Use func (g Graph) getSystemStorageClient() systemstorageclient.SystemDataStorageClient { // TODO: this needs a check if the client is already initialized and if not, initialize it g.sdsc = systemstorageclient.NewSystemStorageClient( + scope, namespace, g.logger, g.config.SystemStorageClient.GatewayAddress,