aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/api.go
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-12-20 15:16:52 +0100
committerTaras Madan <tarasmadan@google.com>2024-12-20 15:26:32 +0000
commitde01e7268bab1e7a0f9752942e38330d0509268f (patch)
tree96ed31e15b98bbfcaf938a96f169d82eea807220 /dashboard/app/api.go
parent9d70ccdc6b50c8c5202b60935d4946b03ea5cde4 (diff)
dashboard/app: gcsPayloadHandler ungzip the gcs content
All API handlers expect input stream to be ungzipped. This handler shouldn't be the exception.
Diffstat (limited to 'dashboard/app/api.go')
-rw-r--r--dashboard/app/api.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/dashboard/app/api.go b/dashboard/app/api.go
index cba7ee43b..13a349431 100644
--- a/dashboard/app/api.go
+++ b/dashboard/app/api.go
@@ -174,6 +174,8 @@ func contextNamespace(c context.Context) string {
return c.Value(&contextKeyNamespace).(string)
}
+// gcsPayloadHandler json.Decode the gcsURL from payload and stream pointed content.
+// This function streams ungzipped content in order to be aligned with other wrappers/handlers.
func gcsPayloadHandler(handler APIHandler) APIHandler {
return func(c context.Context, payload io.Reader) (interface{}, error) {
var gcsURL string
@@ -194,7 +196,15 @@ func gcsPayloadHandler(handler APIHandler) APIHandler {
if err != nil {
return nil, fmt.Errorf("gcsFile.Reader: %w", err)
}
- return handler(c, gcsPayloadReader)
+ gz, err := gzip.NewReader(gcsPayloadReader)
+ if err != nil {
+ return nil, fmt.Errorf("gzip.NewReader: %w", err)
+ }
+ // Close() generates error in case of the corrupted data.
+ // In order to check the data checksum all the data should be read.
+ // We don't guarantee all the data will be read - let's ignore.
+ defer gz.Close()
+ return handler(c, gz)
}
}