in scan/dependencies.go [69:117]
func (s *Scanner) NewImageDependencies(img string, runtime string, buildtimes []string) (*image.Dependencies, error) {
var dependencies *image.Dependencies
if len(img) > 0 {
imageReference, err := NewImageReference(util.NormalizeImageTag(img))
if err != nil {
return nil, err
}
dependencies = &image.Dependencies{
Image: imageReference,
}
} else {
// we allow build without pushing image to registry so the image can be empty
dependencies = &image.Dependencies{
Image: nil,
}
}
runtimeDep, err := NewImageReference(util.NormalizeImageTag(runtime))
if err != nil {
return nil, err
}
dependencies.Runtime = runtimeDep
dict := map[string]bool{}
for _, buildtime := range buildtimes {
bt := util.NormalizeImageTag(buildtime)
// If the image is prefixed with "library/", remove it for comparisons.
// "library/" will be added again during image reference generation.
// This prevents duplicate dependencies when reading "library/golang" and
// "golang" from the Dockerfile.
bt = strings.TrimPrefix(bt, "library/")
// If we've already processed the tag after normalization, skip dependency
// generation. I.e., they specify "golang" and "golang:latest"
if dict[bt] {
continue
}
dict[bt] = true
buildtimeDep, err := NewImageReference(bt)
if err != nil {
return nil, err
}
dependencies.Buildtime = append(dependencies.Buildtime, buildtimeDep)
}
return dependencies, nil
}