github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/commands/artifact/wire_gen.go (about)

     1  // Code generated by Wire. DO NOT EDIT.
     2  
     3  //go:generate go run github.com/google/wire/cmd/wire
     4  //go:build !wireinject
     5  // +build !wireinject
     6  
     7  package artifact
     8  
     9  import (
    10  	"context"
    11  	"github.com/aquasecurity/trivy-db/pkg/db"
    12  	"github.com/devseccon/trivy/pkg/fanal/applier"
    13  	"github.com/devseccon/trivy/pkg/fanal/artifact"
    14  	image2 "github.com/devseccon/trivy/pkg/fanal/artifact/image"
    15  	local2 "github.com/devseccon/trivy/pkg/fanal/artifact/local"
    16  	"github.com/devseccon/trivy/pkg/fanal/artifact/repo"
    17  	"github.com/devseccon/trivy/pkg/fanal/artifact/sbom"
    18  	"github.com/devseccon/trivy/pkg/fanal/artifact/vm"
    19  	"github.com/devseccon/trivy/pkg/fanal/cache"
    20  	"github.com/devseccon/trivy/pkg/fanal/image"
    21  	"github.com/devseccon/trivy/pkg/fanal/types"
    22  	"github.com/devseccon/trivy/pkg/rpc/client"
    23  	"github.com/devseccon/trivy/pkg/scanner"
    24  	"github.com/devseccon/trivy/pkg/scanner/langpkg"
    25  	"github.com/devseccon/trivy/pkg/scanner/local"
    26  	"github.com/devseccon/trivy/pkg/scanner/ospkg"
    27  	"github.com/devseccon/trivy/pkg/vulnerability"
    28  )
    29  
    30  // Injectors from inject.go:
    31  
    32  // initializeImageScanner is for container image scanning in standalone mode
    33  // e.g. dockerd, container registry, podman, etc.
    34  func initializeImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, imageOpt types.ImageOptions, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
    35  	applierApplier := applier.NewApplier(localArtifactCache)
    36  	ospkgScanner := ospkg.NewScanner()
    37  	langpkgScanner := langpkg.NewScanner()
    38  	config := db.Config{}
    39  	client := vulnerability.NewClient(config)
    40  	localScanner := local.NewScanner(applierApplier, ospkgScanner, langpkgScanner, client)
    41  	typesImage, cleanup, err := image.NewContainerImage(ctx, imageName, imageOpt)
    42  	if err != nil {
    43  		return scanner.Scanner{}, nil, err
    44  	}
    45  	artifactArtifact, err := image2.NewArtifact(typesImage, artifactCache, artifactOption)
    46  	if err != nil {
    47  		cleanup()
    48  		return scanner.Scanner{}, nil, err
    49  	}
    50  	scannerScanner := scanner.NewScanner(localScanner, artifactArtifact)
    51  	return scannerScanner, func() {
    52  		cleanup()
    53  	}, nil
    54  }
    55  
    56  // initializeArchiveScanner is for container image archive scanning in standalone mode
    57  // e.g. docker save -o alpine.tar alpine:3.15
    58  func initializeArchiveScanner(ctx context.Context, filePath string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, artifactOption artifact.Option) (scanner.Scanner, error) {
    59  	applierApplier := applier.NewApplier(localArtifactCache)
    60  	ospkgScanner := ospkg.NewScanner()
    61  	langpkgScanner := langpkg.NewScanner()
    62  	config := db.Config{}
    63  	client := vulnerability.NewClient(config)
    64  	localScanner := local.NewScanner(applierApplier, ospkgScanner, langpkgScanner, client)
    65  	typesImage, err := image.NewArchiveImage(filePath)
    66  	if err != nil {
    67  		return scanner.Scanner{}, err
    68  	}
    69  	artifactArtifact, err := image2.NewArtifact(typesImage, artifactCache, artifactOption)
    70  	if err != nil {
    71  		return scanner.Scanner{}, err
    72  	}
    73  	scannerScanner := scanner.NewScanner(localScanner, artifactArtifact)
    74  	return scannerScanner, nil
    75  }
    76  
    77  // initializeFilesystemScanner is for filesystem scanning in standalone mode
    78  func initializeFilesystemScanner(ctx context.Context, path string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
    79  	applierApplier := applier.NewApplier(localArtifactCache)
    80  	ospkgScanner := ospkg.NewScanner()
    81  	langpkgScanner := langpkg.NewScanner()
    82  	config := db.Config{}
    83  	client := vulnerability.NewClient(config)
    84  	localScanner := local.NewScanner(applierApplier, ospkgScanner, langpkgScanner, client)
    85  	artifactArtifact, err := local2.NewArtifact(path, artifactCache, artifactOption)
    86  	if err != nil {
    87  		return scanner.Scanner{}, nil, err
    88  	}
    89  	scannerScanner := scanner.NewScanner(localScanner, artifactArtifact)
    90  	return scannerScanner, func() {
    91  	}, nil
    92  }
    93  
    94  func initializeRepositoryScanner(ctx context.Context, url string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
    95  	applierApplier := applier.NewApplier(localArtifactCache)
    96  	ospkgScanner := ospkg.NewScanner()
    97  	langpkgScanner := langpkg.NewScanner()
    98  	config := db.Config{}
    99  	client := vulnerability.NewClient(config)
   100  	localScanner := local.NewScanner(applierApplier, ospkgScanner, langpkgScanner, client)
   101  	artifactArtifact, cleanup, err := repo.NewArtifact(url, artifactCache, artifactOption)
   102  	if err != nil {
   103  		return scanner.Scanner{}, nil, err
   104  	}
   105  	scannerScanner := scanner.NewScanner(localScanner, artifactArtifact)
   106  	return scannerScanner, func() {
   107  		cleanup()
   108  	}, nil
   109  }
   110  
   111  func initializeSBOMScanner(ctx context.Context, filePath string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
   112  	applierApplier := applier.NewApplier(localArtifactCache)
   113  	ospkgScanner := ospkg.NewScanner()
   114  	langpkgScanner := langpkg.NewScanner()
   115  	config := db.Config{}
   116  	client := vulnerability.NewClient(config)
   117  	localScanner := local.NewScanner(applierApplier, ospkgScanner, langpkgScanner, client)
   118  	artifactArtifact, err := sbom.NewArtifact(filePath, artifactCache, artifactOption)
   119  	if err != nil {
   120  		return scanner.Scanner{}, nil, err
   121  	}
   122  	scannerScanner := scanner.NewScanner(localScanner, artifactArtifact)
   123  	return scannerScanner, func() {
   124  	}, nil
   125  }
   126  
   127  func initializeVMScanner(ctx context.Context, filePath string, artifactCache cache.ArtifactCache, localArtifactCache cache.LocalArtifactCache, walker vm.Walker, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
   128  	applierApplier := applier.NewApplier(localArtifactCache)
   129  	ospkgScanner := ospkg.NewScanner()
   130  	langpkgScanner := langpkg.NewScanner()
   131  	config := db.Config{}
   132  	client := vulnerability.NewClient(config)
   133  	localScanner := local.NewScanner(applierApplier, ospkgScanner, langpkgScanner, client)
   134  	artifactArtifact, err := vm.NewArtifact(filePath, artifactCache, walker, artifactOption)
   135  	if err != nil {
   136  		return scanner.Scanner{}, nil, err
   137  	}
   138  	scannerScanner := scanner.NewScanner(localScanner, artifactArtifact)
   139  	return scannerScanner, func() {
   140  	}, nil
   141  }
   142  
   143  // initializeRemoteImageScanner is for container image scanning in client/server mode
   144  // e.g. dockerd, container registry, podman, etc.
   145  func initializeRemoteImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, imageOpt types.ImageOptions, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
   146  	v := _wireValue
   147  	clientScanner := client.NewScanner(remoteScanOptions, v...)
   148  	typesImage, cleanup, err := image.NewContainerImage(ctx, imageName, imageOpt)
   149  	if err != nil {
   150  		return scanner.Scanner{}, nil, err
   151  	}
   152  	artifactArtifact, err := image2.NewArtifact(typesImage, artifactCache, artifactOption)
   153  	if err != nil {
   154  		cleanup()
   155  		return scanner.Scanner{}, nil, err
   156  	}
   157  	scannerScanner := scanner.NewScanner(clientScanner, artifactArtifact)
   158  	return scannerScanner, func() {
   159  		cleanup()
   160  	}, nil
   161  }
   162  
   163  var (
   164  	_wireValue = []client.Option(nil)
   165  )
   166  
   167  // initializeRemoteArchiveScanner is for container image archive scanning in client/server mode
   168  // e.g. docker save -o alpine.tar alpine:3.15
   169  func initializeRemoteArchiveScanner(ctx context.Context, filePath string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, artifactOption artifact.Option) (scanner.Scanner, error) {
   170  	v := _wireValue
   171  	clientScanner := client.NewScanner(remoteScanOptions, v...)
   172  	typesImage, err := image.NewArchiveImage(filePath)
   173  	if err != nil {
   174  		return scanner.Scanner{}, err
   175  	}
   176  	artifactArtifact, err := image2.NewArtifact(typesImage, artifactCache, artifactOption)
   177  	if err != nil {
   178  		return scanner.Scanner{}, err
   179  	}
   180  	scannerScanner := scanner.NewScanner(clientScanner, artifactArtifact)
   181  	return scannerScanner, nil
   182  }
   183  
   184  // initializeRemoteFilesystemScanner is for filesystem scanning in client/server mode
   185  func initializeRemoteFilesystemScanner(ctx context.Context, path string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
   186  	v := _wireValue
   187  	clientScanner := client.NewScanner(remoteScanOptions, v...)
   188  	artifactArtifact, err := local2.NewArtifact(path, artifactCache, artifactOption)
   189  	if err != nil {
   190  		return scanner.Scanner{}, nil, err
   191  	}
   192  	scannerScanner := scanner.NewScanner(clientScanner, artifactArtifact)
   193  	return scannerScanner, func() {
   194  	}, nil
   195  }
   196  
   197  // initializeRemoteRepositoryScanner is for repository scanning in client/server mode
   198  func initializeRemoteRepositoryScanner(ctx context.Context, url string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
   199  	v := _wireValue
   200  	clientScanner := client.NewScanner(remoteScanOptions, v...)
   201  	artifactArtifact, cleanup, err := repo.NewArtifact(url, artifactCache, artifactOption)
   202  	if err != nil {
   203  		return scanner.Scanner{}, nil, err
   204  	}
   205  	scannerScanner := scanner.NewScanner(clientScanner, artifactArtifact)
   206  	return scannerScanner, func() {
   207  		cleanup()
   208  	}, nil
   209  }
   210  
   211  // initializeRemoteSBOMScanner is for sbom scanning in client/server mode
   212  func initializeRemoteSBOMScanner(ctx context.Context, path string, artifactCache cache.ArtifactCache, remoteScanOptions client.ScannerOption, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
   213  	v := _wireValue
   214  	clientScanner := client.NewScanner(remoteScanOptions, v...)
   215  	artifactArtifact, err := sbom.NewArtifact(path, artifactCache, artifactOption)
   216  	if err != nil {
   217  		return scanner.Scanner{}, nil, err
   218  	}
   219  	scannerScanner := scanner.NewScanner(clientScanner, artifactArtifact)
   220  	return scannerScanner, func() {
   221  	}, nil
   222  }
   223  
   224  // initializeRemoteVMScanner is for vm scanning in client/server mode
   225  func initializeRemoteVMScanner(ctx context.Context, path string, artifactCache cache.ArtifactCache, walker vm.Walker, remoteScanOptions client.ScannerOption, artifactOption artifact.Option) (scanner.Scanner, func(), error) {
   226  	v := _wireValue
   227  	clientScanner := client.NewScanner(remoteScanOptions, v...)
   228  	artifactArtifact, err := vm.NewArtifact(path, artifactCache, walker, artifactOption)
   229  	if err != nil {
   230  		return scanner.Scanner{}, nil, err
   231  	}
   232  	scannerScanner := scanner.NewScanner(clientScanner, artifactArtifact)
   233  	return scannerScanner, func() {
   234  	}, nil
   235  }