From ca9871ab4077ec23a9038fec3255f6319bb79274 Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Fri, 20 Dec 2024 10:29:36 +0100 Subject: [PATCH] dashboard/app: fix parsing bug and accept "gs://" prefixes Bug: payload is a serialized json, not string. --- dashboard/app/api.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dashboard/app/api.go b/dashboard/app/api.go index 4699a9a0d22d..cba7ee43b80b 100644 --- a/dashboard/app/api.go +++ b/dashboard/app/api.go @@ -176,17 +176,17 @@ func contextNamespace(c context.Context) string { func gcsPayloadHandler(handler APIHandler) APIHandler { return func(c context.Context, payload io.Reader) (interface{}, error) { - p, err := io.ReadAll(payload) - if err != nil { - return nil, fmt.Errorf("io.ReadAll: %w", err) + var gcsURL string + if err := json.NewDecoder(payload).Decode(&gcsURL); err != nil { + return nil, fmt.Errorf("json.NewDecoder(payload).Decode(&gcsURL): %w", err) } - payloadURL := string(p) + gcsURL = strings.TrimPrefix(gcsURL, "gs://") clientGCS, err := gcs.NewClient(c) if err != nil { return nil, fmt.Errorf("gcs.NewClient: %w", err) } defer clientGCS.Close() - gcsFile, err := clientGCS.Read(payloadURL) + gcsFile, err := clientGCS.Read(gcsURL) if err != nil { return nil, fmt.Errorf("clientGCS.Read: %w", err) }