Skip to content

claircore: add JSON marshaling for Alias type#1896

Open
jvdm wants to merge 1 commit into
quay:mainfrom
jvdm:fix-alias-json
Open

claircore: add JSON marshaling for Alias type#1896
jvdm wants to merge 1 commit into
quay:mainfrom
jvdm:fix-alias-json

Conversation

@jvdm
Copy link
Copy Markdown
Contributor

@jvdm jvdm commented May 27, 2026

unique.Handle[string] does not implement json.Marshaler, causing Alias.Space to serialize as {} instead of the actual namespace value. This breaks vulnerability bundle serialization via jsonblob.

Add MarshalJSON and UnmarshalJSON to preserve Space values through JSON round-trips.

@jvdm jvdm requested a review from a team as a code owner May 27, 2026 23:24
@jvdm jvdm requested review from hdonnay and removed request for a team May 27, 2026 23:24
@jvdm jvdm force-pushed the fix-alias-json branch 2 times, most recently from 524d0ad to ff47f30 Compare May 28, 2026 01:38
Comment thread alias.go
}

type aliasJSON struct {
Space string `json:"Space"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want the JSON keys to be capitalized? Seems like everything else is lower

Comment thread alias_test.go
}
want := `{"Space":"","Name":""}`
if got := string(data); got != want {
t.Errorf("marshal: got %s, want %s", got, want)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems like this isn't going to be totally symmetrical, i.e unmarshaling {"Space":"","Name":""} will return something different from Alias{} should. Do you think it's worth calling unmarshal and checking Valid() is false?

@jvdm jvdm force-pushed the fix-alias-json branch from ff47f30 to 1e48ce3 Compare May 28, 2026 19:18
@crozzy
Copy link
Copy Markdown
Contributor

crozzy commented May 28, 2026

blocked by #1891

unique.Handle[string] does not implement json.Marshaler, causing
Alias.Space to serialize as {} instead of the actual namespace value.

Signed-off-by: J. Victor Martins <jvdm@sdf.org>
@jvdm jvdm force-pushed the fix-alias-json branch from 1e48ce3 to c942d87 Compare June 2, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants