Skip to content

Commit 0d8c1ea

Browse files
authored
fix(backend): Parse JSON and decode base64 in artifact client (#12467)
Signed-off-by: Helber Belmiro <[email protected]>
1 parent ad30461 commit 0d8c1ea

File tree

2 files changed

+434
-3
lines changed

2 files changed

+434
-3
lines changed

backend/src/agent/persistence/client/artifactclient/client.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package artifactclient
1818

1919
import (
2020
"context"
21+
"encoding/base64"
22+
"encoding/json"
2123
"fmt"
2224
"io"
2325
"net/http"
@@ -146,12 +148,27 @@ func (a *client) ReadArtifact(request *ReadArtifactRequest) (*ReadArtifactRespon
146148

147149
switch resp.StatusCode {
148150
case http.StatusOK:
149-
data, err := io.ReadAll(resp.Body)
151+
body, err := io.ReadAll(resp.Body)
150152
if err != nil {
151153
return nil, NewError(ErrorCodePermanent, err,
152-
"Failed to read artifact data: %v", err.Error())
154+
"Failed to read response body: %v", err.Error())
153155
}
154-
return &ReadArtifactResponse{Data: data}, nil
156+
157+
var jsonResponse struct {
158+
Data string `json:"data"`
159+
}
160+
if err := json.Unmarshal(body, &jsonResponse); err != nil {
161+
return nil, NewError(ErrorCodePermanent, err,
162+
"Failed to parse JSON response: %v", err.Error())
163+
}
164+
165+
decodedData, err := base64.StdEncoding.DecodeString(jsonResponse.Data)
166+
if err != nil {
167+
return nil, NewError(ErrorCodePermanent, err,
168+
"Failed to decode base64 data: %v", err.Error())
169+
}
170+
171+
return &ReadArtifactResponse{Data: decodedData}, nil
155172

156173
case http.StatusNotFound:
157174
return nil, nil

0 commit comments

Comments
 (0)