@@ -219,6 +219,7 @@ type CurationAuditCommand struct {
219219 workingDirs []string
220220 OriginPath string
221221 parallelRequests int
222+ dockerImageName string
222223 audit.AuditParamsInterface
223224}
224225
@@ -255,6 +256,15 @@ func (ca *CurationAuditCommand) SetParallelRequests(threads int) *CurationAuditC
255256 return ca
256257}
257258
259+ func (ca * CurationAuditCommand ) DockerImageName () string {
260+ return ca .dockerImageName
261+ }
262+
263+ func (ca * CurationAuditCommand ) SetDockerImageName (dockerImageName string ) * CurationAuditCommand {
264+ ca .dockerImageName = dockerImageName
265+ return ca
266+ }
267+
258268func (ca * CurationAuditCommand ) Run () (err error ) {
259269 rootDir , err := os .Getwd ()
260270 if err != nil {
@@ -353,6 +363,7 @@ func getPolicyAndConditionId(policy, condition string) string {
353363func (ca * CurationAuditCommand ) doCurateAudit (results map [string ]* CurationReport ) error {
354364 techs := techutils .DetectedTechnologiesList ()
355365 if ca .DockerImageName () != "" {
366+ log .Debug (fmt .Sprintf ("Docker image name '%s' was provided, running Docker curation audit." , ca .DockerImageName ()))
356367 techs = []string {techutils .Docker .String ()}
357368 }
358369 for _ , tech := range techs {
@@ -968,7 +979,8 @@ func getUrlNameAndVersionByTech(tech techutils.Technology, node *xrayUtils.Graph
968979 downloadUrls , name , version = getNugetNameScopeAndVersion (node .Id , artiUrl , repo )
969980 return
970981 case techutils .Docker :
971- return getDockerNameScopeAndVersion (node .Id , artiUrl , repo )
982+ downloadUrls , name , version = getDockerNameAndVersion (node .Id , artiUrl , repo )
983+ return
972984 }
973985 return
974986}
@@ -1153,20 +1165,27 @@ func buildNpmDownloadUrl(url, repo, name, scope, version string) []string {
11531165 return []string {packageUrl }
11541166}
11551167
1156- func getDockerNameScopeAndVersion (id , artiUrl , repo string ) (downloadUrls []string , name , scope , version string ) {
1168+ func getDockerNameAndVersion (id , artiUrl , repo string ) (downloadUrls []string , name , version string ) {
11571169 if id == "" {
11581170 return
11591171 }
11601172
11611173 id = strings .TrimPrefix (id , "docker://" )
11621174
1163- if idx := strings .Index (id , ":sha256:" ); idx > 0 {
1164- name = id [:idx ]
1165- version = id [idx + 1 :]
1166- } else if idx := strings .LastIndex (id , ":" ); idx > 0 {
1167- name = id [:idx ]
1168- version = id [idx + 1 :]
1169- } else {
1175+ sha256Idx := strings .Index (id , ":sha256:" )
1176+ tagIdx := strings .LastIndex (id , ":" )
1177+
1178+ switch {
1179+ // Example: docker://nginx:sha256:abc123def456
1180+ case sha256Idx > 0 :
1181+ name = id [:sha256Idx ]
1182+ version = id [sha256Idx + 1 :]
1183+ // Example: docker://nginx:1.21
1184+ case tagIdx > 0 :
1185+ name = id [:tagIdx ]
1186+ version = id [tagIdx + 1 :]
1187+ // Example: docker://nginx (no tag specified, defaults to "latest")
1188+ default :
11701189 name = id
11711190 version = "latest"
11721191 }
@@ -1176,7 +1195,7 @@ func getDockerNameScopeAndVersion(id, artiUrl, repo string) (downloadUrls []stri
11761195 strings .TrimSuffix (artiUrl , "/" ), repo , name , version )}
11771196 }
11781197
1179- return downloadUrls , name , scope , version
1198+ return
11801199}
11811200
11821201func GetCurationOutputFormat (formatFlagVal string ) (format outFormat.OutputFormat , err error ) {
0 commit comments