Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVEREST-1672 | Unmarshalling proto response should discard unknown fields #844

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading