@@ -42,14 +42,14 @@ type ImageIndexResult struct {
4242 Error error
4343}
4444
45- func indexImageAsync (wg * sync.WaitGroup , image string , cli command. Cli , resultChan chan <- ImageIndexResult ) {
45+ func indexImageAsync (wg * sync.WaitGroup , image string , options IndexOptions , resultChan chan <- ImageIndexResult ) {
4646 defer wg .Done ()
4747 var (
4848 sbom * types.Sbom
4949 cves * types.VulnerabilitiesByPurls
5050 err error
5151 )
52- sbom , err = IndexImage (image , cli )
52+ sbom , err = IndexImage (image , options )
5353 if err == nil {
5454 cves , err = query .ForVulnerabilitiesInGraphQL (sbom )
5555 if err == nil {
@@ -63,6 +63,13 @@ func indexImageAsync(wg *sync.WaitGroup, image string, cli command.Cli, resultCh
6363 }
6464}
6565
66+ type IndexOptions struct {
67+ Username string
68+ Password string
69+
70+ Cli command.Cli
71+ }
72+
6673func IndexPath (path string , name string , cli command.Cli ) (* types.Sbom , error ) {
6774 cache , err := registry .ReadImage (name , path )
6875 if err != nil {
@@ -71,19 +78,19 @@ func IndexPath(path string, name string, cli command.Cli) (*types.Sbom, error) {
7178 return indexImage (cache , cli )
7279}
7380
74- func IndexImage (image string , cli command. Cli ) (* types.Sbom , error ) {
81+ func IndexImage (image string , options IndexOptions ) (* types.Sbom , error ) {
7582 if strings .HasPrefix (image , "sha256:" ) {
76- configFilePath := cli .ConfigFile ().Filename
83+ configFilePath := options . Cli .ConfigFile ().Filename
7784 sbomFilePath := filepath .Join (filepath .Dir (configFilePath ), "sbom" , "sha256" , image [7 :], "sbom.json" )
7885 if sbom := cachedSbom (sbomFilePath ); sbom != nil {
7986 return sbom , nil
8087 }
8188 }
82- cache , err := registry .SaveImage (image , cli )
89+ cache , err := registry .SaveImage (image , options . Username , options . Password , options . Cli )
8390 if err != nil {
8491 return nil , errors .Wrap (err , "failed to copy image" )
8592 }
86- return indexImage (cache , cli )
93+ return indexImage (cache , options . Cli )
8794}
8895
8996func indexImage (cache * registry.ImageCache , cli command.Cli ) (* types.Sbom , error ) {
0 commit comments