mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
inspect: parse sbom and provenance into json structs
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@ -46,9 +46,9 @@ type index struct {
|
||||
}
|
||||
|
||||
type asset struct {
|
||||
config *ocispec.Image
|
||||
sbom *sbomStub
|
||||
slsa *slsaStub
|
||||
config *ocispec.Image
|
||||
sbom *sbomStub
|
||||
provenance *provenanceStub
|
||||
}
|
||||
|
||||
type result struct {
|
||||
@ -255,7 +255,7 @@ func (l *loader) scanConfig(ctx context.Context, fetcher remotes.Fetcher, desc o
|
||||
}
|
||||
|
||||
type sbomStub struct {
|
||||
SPDX json.RawMessage `json:",omitempty"`
|
||||
SPDX interface{} `json:",omitempty"`
|
||||
}
|
||||
|
||||
func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
|
||||
@ -275,8 +275,14 @@ func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *resul
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var spdx struct {
|
||||
Predicate interface{} `json:"predicate"`
|
||||
}
|
||||
if err := json.Unmarshal(dt, &spdx); err != nil {
|
||||
return err
|
||||
}
|
||||
as.sbom = &sbomStub{
|
||||
SPDX: dt,
|
||||
SPDX: spdx.Predicate,
|
||||
}
|
||||
break
|
||||
}
|
||||
@ -285,8 +291,8 @@ func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *resul
|
||||
return nil
|
||||
}
|
||||
|
||||
type slsaStub struct {
|
||||
Provenance json.RawMessage `json:",omitempty"`
|
||||
type provenanceStub struct {
|
||||
SLSA interface{} `json:",omitempty"`
|
||||
}
|
||||
|
||||
func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
|
||||
@ -306,8 +312,14 @@ func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
as.slsa = &slsaStub{
|
||||
Provenance: dt,
|
||||
var slsa struct {
|
||||
Predicate interface{} `json:"predicate"`
|
||||
}
|
||||
if err := json.Unmarshal(dt, &slsa); err != nil {
|
||||
return err
|
||||
}
|
||||
as.provenance = &provenanceStub{
|
||||
SLSA: slsa.Predicate,
|
||||
}
|
||||
break
|
||||
}
|
||||
@ -330,16 +342,16 @@ func (r *result) Configs() map[string]*ocispec.Image {
|
||||
return res
|
||||
}
|
||||
|
||||
func (r *result) SLSA() map[string]slsaStub {
|
||||
func (r *result) Provenance() map[string]provenanceStub {
|
||||
if len(r.assets) == 0 {
|
||||
return nil
|
||||
}
|
||||
res := make(map[string]slsaStub)
|
||||
res := make(map[string]provenanceStub)
|
||||
for p, a := range r.assets {
|
||||
if a.slsa == nil {
|
||||
if a.provenance == nil {
|
||||
continue
|
||||
}
|
||||
res[p] = *a.slsa
|
||||
res[p] = *a.provenance
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
Reference in New Issue
Block a user