From ca20669d5b8bdddfd0ecfa910e8a0b31bd3c9148 Mon Sep 17 00:00:00 2001 From: HeyeOpenSource Date: Wed, 30 Oct 2024 16:47:54 +0100 Subject: [PATCH] - Correction due to integration tests. Signed-off-by: HeyeOpenSource --- cmd/syft/internal/options/dotnet.go | 13 ++++++------ syft/pkg/cataloger/dotnet/config.go | 31 ++++++++++++----------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/cmd/syft/internal/options/dotnet.go b/cmd/syft/internal/options/dotnet.go index af9e98dbea93..222808f980f3 100644 --- a/cmd/syft/internal/options/dotnet.go +++ b/cmd/syft/internal/options/dotnet.go @@ -5,17 +5,18 @@ import ( "strings" "github.com/anchore/clio" + "github.com/anchore/syft/syft/credential" "github.com/anchore/syft/syft/pkg/cataloger/dotnet" ) type dotNetProviderCredentials []dotNetProviderCredential -func (dnpc dotNetProviderCredentials) ToProviderCredentials() []dotnet.ProviderCredential { - result := []dotnet.ProviderCredential{} - for _, credential := range dnpc { - result = append(result, dotnet.ProviderCredential{ - Username: credential.Username.String(), - Password: credential.Password.String(), +func (dnpc dotNetProviderCredentials) ToProviderCredentials() []credential.SimpleCredential { + result := []credential.SimpleCredential{} + for _, _credential := range dnpc { + result = append(result, credential.SimpleCredential{ + Username: _credential.Username.String(), + Password: _credential.Password.String(), }) } diff --git a/syft/pkg/cataloger/dotnet/config.go b/syft/pkg/cataloger/dotnet/config.go index 38cfcbd055fc..d12655e9d92e 100644 --- a/syft/pkg/cataloger/dotnet/config.go +++ b/syft/pkg/cataloger/dotnet/config.go @@ -11,6 +11,8 @@ import ( "strings" "sync" "time" + + "github.com/anchore/syft/syft/credential" ) const ( @@ -26,21 +28,12 @@ var ( defaultProviders = "" ) -type ProviderCredential struct { - Username string `yaml:"username" json:"username" mapstructure:"username"` - Password string `yaml:"password" json:"password" mapstructure:"password"` -} - -func (pc ProviderCredential) Valid() bool { - return pc.Username != "" && pc.Password != "" -} - type CatalogerConfig struct { - SearchLocalLicenses bool `yaml:"search-local-licenses" json:"search-local-licenses" mapstructure:"search-local-licenses"` - LocalCachePaths []string `yaml:"local-cache-paths" json:"local-cache-paths" mapstructure:"local-cache-paths"` - SearchRemoteLicenses bool `yaml:"search-remote-licenses" json:"search-remote-licenses" mapstructure:"search-remote-licenses"` - Providers []string `yaml:"package-providers,omitempty" json:"package-providers,omitempty" mapstructure:"package-providers"` - ProviderCredentials []ProviderCredential `yaml:"package-provider-credentials,omitempty" json:"package-provider-credentials,omitempty" mapstructure:"package-provider-credentials"` + SearchLocalLicenses bool `yaml:"search-local-licenses" json:"search-local-licenses" mapstructure:"search-local-licenses"` + LocalCachePaths []string `yaml:"local-cache-paths" json:"local-cache-paths" mapstructure:"local-cache-paths"` + SearchRemoteLicenses bool `yaml:"search-remote-licenses" json:"search-remote-licenses" mapstructure:"search-remote-licenses"` + Providers []string `yaml:"package-providers,omitempty" json:"package-providers,omitempty" mapstructure:"package-providers"` + ProviderCredentials []credential.SimpleCredential `yaml:"package-provider-credentials,omitempty" json:"package-provider-credentials,omitempty" mapstructure:"package-provider-credentials"` } // DefaultCatalogerConfig create a CatalogerConfig with default options, which includes: @@ -78,14 +71,16 @@ func (g CatalogerConfig) WithProviders(input string) CatalogerConfig { return g } -func (g CatalogerConfig) WithCredentials(input []ProviderCredential) CatalogerConfig { +func (g CatalogerConfig) WithCredentials(input []credential.SimpleCredential) CatalogerConfig { if len(input) == 0 { return g } - for _, credential := range input { - if credential.Valid() { - g.ProviderCredentials = append([]ProviderCredential{}, credential) + g.ProviderCredentials = []credential.SimpleCredential{} + + for _, _credential := range input { + if _credential.Valid() { + g.ProviderCredentials = append(g.ProviderCredentials, _credential) } }