Skip to content

Commit

Permalink
EVEREST-1672 | Unmarshalling proto response should discard unknown fi…
Browse files Browse the repository at this point in the history
…elds (#844)

* fix Unmarshal

Signed-off-by: Mayank Shah <[email protected]>

* linting

Signed-off-by: Mayank Shah <[email protected]>

---------

Signed-off-by: Mayank Shah <[email protected]>
  • Loading branch information
mayankshah1607 authored Nov 19, 2024
1 parent f068cb7 commit bad1674
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/version_service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func New(url string) Interface { //nolint:ireturn
return &versionServiceClient{url: url}
}

//nolint:gochecknoglobals
var defaultUnmarshal = protojson.UnmarshalOptions{
// We must ignore any unknown fields in the response, since new fields
// may be added after this binary has been built and compiled.
// Without this field, unmashalling would always fail if the API is updated.
DiscardUnknown: true,
}

// GetSupportedEngineVersions returns a list of supported versions for a given operator and version.
func (c *versionServiceClient) GetSupportedEngineVersions(ctx context.Context, operator, version string) ([]string, error) {
p, err := url.Parse(c.url)
Expand All @@ -92,7 +100,7 @@ func (c *versionServiceClient) GetSupportedEngineVersions(ctx context.Context, o
if err != nil {
return nil, errors.Join(err, errors.New("could not read version response"))
}
if err := protojson.Unmarshal(b, response); err != nil {
if err := defaultUnmarshal.Unmarshal(b, response); err != nil {
return nil, errors.Join(err, errors.New("could not decode version response"))
}

Expand Down

0 comments on commit bad1674

Please sign in to comment.