Skip to content

Commit

Permalink
Refactor errorResponse struct in gcp.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Baruch Odem committed Apr 1, 2024
1 parent d43c3d2 commit af3a200
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions engine/validation/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import (
"github.com/rs/zerolog/log"
)

type ErrorResponse struct {
type errorResponse struct {
Error struct {
Message string `json:"message"`
Details []struct {
Type string `json:"@type"`
Metadata struct {
Consumer string `json:"consumer"`
} `json:"metadata,omitempty"`
} `json:"details"`
} `json:"error"`
}

Expand Down Expand Up @@ -54,14 +60,20 @@ func checkGCPErrorResponse(resp *http.Response) (secrets.ValidationResult, strin
}

// Unmarshal the response body into the ErrorResponse struct
var errorResponse ErrorResponse
var errorResponse errorResponse
err = json.Unmarshal(bodyBytes, &errorResponse)
if err != nil {
return secrets.UnknownResult, "", err
}

if strings.Contains(errorResponse.Error.Message, "YouTube Data API v3 has not been used in project") {
return secrets.ValidResult, "", nil
extra := ""
for _, detail := range errorResponse.Error.Details {
if detail.Type == "type.googleapis.com/google.rpc.ErrorInfo" {
extra = detail.Metadata.Consumer
}
}
return secrets.ValidResult, extra, nil
}

return secrets.UnknownResult, "", nil
Expand Down

0 comments on commit af3a200

Please sign in to comment.