Merge pull request #1577 from snyk/fix/rm-consumer-specific-errmsg

fix: enumlib: remove a scan-specific error message
main
Craig Furman 2022-08-04 15:00:38 +01:00 committed by GitHub
commit f2a173f3c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -101,12 +101,13 @@ func (p *AWSTerraformProvider) Version() string {
return p.version
}
var AWSCredentialsNotFoundError = errors.New("Could not find a way to authenticate on AWS!\n" +
"Please refer to AWS documentation: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html")
func (p *AWSTerraformProvider) CheckCredentialsExist() error {
_, err := p.session.Config.Credentials.Get()
if err == credentials.ErrNoValidProvidersFoundInChain {
return errors.New("Could not find a way to authenticate on AWS!\n" +
"Please refer to AWS documentation: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html\n\n" +
"To use a different cloud provider, use --to=\"gcp+tf\" for GCP or --to=\"azure+tf\" for Azure.")
return AWSCredentialsNotFoundError
}
if err != nil {
return err

View File

@ -18,6 +18,7 @@ import (
"github.com/snyk/driftctl/build"
"github.com/snyk/driftctl/enumeration/alerter"
"github.com/snyk/driftctl/enumeration/remote"
"github.com/snyk/driftctl/enumeration/remote/aws"
"github.com/snyk/driftctl/enumeration/remote/common"
"github.com/snyk/driftctl/enumeration/terraform"
"github.com/snyk/driftctl/enumeration/terraform/lock"
@ -293,6 +294,12 @@ func scanRun(opts *pkg.ScanOptions) error {
err := remote.Activate(opts.To, opts.ProviderVersion, alerter, providerLibrary, remoteLibrary, scanProgress, resFactory, opts.ConfigDir)
if err != nil {
if err == aws.AWSCredentialsNotFoundError {
// special case command-line advice, because AWS is the default cloud
// provider, and users may be confused by a cloud-specific error out of
// the box
return fmt.Errorf("%s\n\n%s", err, "To use a different cloud provider, use --to=\"gcp+tf\" for GCP or --to=\"azure+tf\" for Azure.")
}
return err
}