Skip to content

Commit bc2ed71

Browse files
committed
fix parsing of reference
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
1 parent 4c2d20f commit bc2ed71

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

pkg/attestation/crafter/materials/cyclonedxjson.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ type CyclonedxJSONCrafter struct {
4343
*crafterCommon
4444
}
4545

46+
// mainComponentStruct internal struct to unmarshall the incoming CycloneDX JSON
47+
type mainComponentStruct struct {
48+
Metadata struct {
49+
Component struct {
50+
Name string `json:"name"`
51+
Type string `json:"type"`
52+
Version string `json:"version"`
53+
Properties []struct {
54+
Name string `json:"name"`
55+
Value string `json:"value"`
56+
} `json:"properties"`
57+
} `json:"component"`
58+
} `json:"metadata"`
59+
}
60+
4661
func NewCyclonedxJSONCrafter(materialSchema *schemaapi.CraftingSchema_Material, backend *casclient.CASBackend, l *zerolog.Logger) (*CyclonedxJSONCrafter, error) {
4762
if materialSchema.Type != schemaapi.CraftingSchema_Material_SBOM_CYCLONEDX_JSON {
4863
return nil, fmt.Errorf("material type is not cyclonedx json")
@@ -105,21 +120,6 @@ func (i *CyclonedxJSONCrafter) Craft(ctx context.Context, filePath string) (*api
105120

106121
// extractMainComponent inspects the SBOM and extracts the main component if any and available
107122
func (i *CyclonedxJSONCrafter) extractMainComponent(rawFile []byte) (*SBOMMainComponentInfo, error) {
108-
// Define the structure of the main component in the SBOM locally to perform an unmarshal
109-
type mainComponentStruct struct {
110-
Metadata struct {
111-
Component struct {
112-
Name string `json:"name"`
113-
Type string `json:"type"`
114-
Version string `json:"version"`
115-
Properties []struct {
116-
Name string `json:"name"`
117-
Value string `json:"value"`
118-
} `json:"properties"`
119-
} `json:"component"`
120-
} `json:"metadata"`
121-
}
122-
123123
var mainComponent mainComponentStruct
124124
err := json.Unmarshal(rawFile, &mainComponent)
125125
if err != nil {
@@ -150,13 +150,13 @@ func (i *CyclonedxJSONCrafter) extractMainComponent(rawFile []byte) (*SBOMMainCo
150150

151151
// Standardize the name to have the full repository name including the registry and
152152
// sanitize the name to remove the possible tag from the repository name
153-
stdName, err := remotename.NewRepository(strings.Split(component.Name, ":")[0])
153+
ref, err := remotename.ParseReference(component.Name)
154154
if err != nil {
155155
return nil, fmt.Errorf("couldn't parse OCI image repository name: %w", err)
156156
}
157157

158158
return &SBOMMainComponentInfo{
159-
name: stdName.String(),
159+
name: ref.Context().RepositoryStr(),
160160
kind: component.Type,
161161
version: component.Version,
162162
}, nil

0 commit comments

Comments
 (0)