@@ -43,6 +43,21 @@ type CyclonedxJSONCrafter struct {
43
43
* crafterCommon
44
44
}
45
45
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
+
46
61
func NewCyclonedxJSONCrafter (materialSchema * schemaapi.CraftingSchema_Material , backend * casclient.CASBackend , l * zerolog.Logger ) (* CyclonedxJSONCrafter , error ) {
47
62
if materialSchema .Type != schemaapi .CraftingSchema_Material_SBOM_CYCLONEDX_JSON {
48
63
return nil , fmt .Errorf ("material type is not cyclonedx json" )
@@ -105,21 +120,6 @@ func (i *CyclonedxJSONCrafter) Craft(ctx context.Context, filePath string) (*api
105
120
106
121
// extractMainComponent inspects the SBOM and extracts the main component if any and available
107
122
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
-
123
123
var mainComponent mainComponentStruct
124
124
err := json .Unmarshal (rawFile , & mainComponent )
125
125
if err != nil {
@@ -150,13 +150,13 @@ func (i *CyclonedxJSONCrafter) extractMainComponent(rawFile []byte) (*SBOMMainCo
150
150
151
151
// Standardize the name to have the full repository name including the registry and
152
152
// 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 )
154
154
if err != nil {
155
155
return nil , fmt .Errorf ("couldn't parse OCI image repository name: %w" , err )
156
156
}
157
157
158
158
return & SBOMMainComponentInfo {
159
- name : stdName . String (),
159
+ name : ref . Context (). RepositoryStr (),
160
160
kind : component .Type ,
161
161
version : component .Version ,
162
162
}, nil
0 commit comments