Skip to content

Commit

Permalink
dashboard/app: fix parsing bug and accept "gs://" prefixes
Browse files Browse the repository at this point in the history
Bug: payload is a serialized json, not string.
  • Loading branch information
tarasmadan committed Dec 20, 2024
1 parent 49cfeac commit fbda11f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions dashboard/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit fbda11f

Please sign in to comment.