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

feat: Export and json-tag fields of manifest.OciImageManifestResponse{} #82

Merged
merged 1 commit into from
May 17, 2024

Conversation

viccuad
Copy link
Member

@viccuad viccuad commented May 15, 2024

Description

Relates to kubewarden/cel-policy#31

Setting the json tags is needed as we marshal this struct in the cel-policy, kw.oci.getManifest() function to return it as map.

To honour this new contract with the json tags, mark fields as exported.
This also simplifies creating mocks with this type struct without type casting.

Note that API is still backwards compatible as we were using the fields via the getters, which are untouched. Plus, cel-policy seems to be the first consumer of this.

Test

CI, and the followup cel-policy PR.

Additional Information

Tradeoff

Potential improvement

@viccuad viccuad requested a review from a team as a code owner May 15, 2024 12:48
Setting the json tags is needed as we marshal this struct in the
cel-policy, `kw.oci.getManifest()` function to return it as map.

To honour this new contract with the json tags, mark fields as
exported.
This also simplifies creating mocks with this type struct without type
casting.

Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
Co-authored-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
@@ -8,30 +8,30 @@ import (
)

type OciImageManifestResponse struct {
image *specs.Manifest
index *specs.Index
Image *specs.Manifest `json:"image"`
Copy link
Member Author

@viccuad viccuad May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exporting these fields is needed because the json lib cannot see them using reflect unless they are in the same package. A workaround would be to create a new helper unexported type ociImageManifestResponse{} with exported fields, but at this point, why not change it here.

@fabriziosestito fabriziosestito merged commit 06e70a6 into kubewarden:main May 17, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants