From bb395cf21343ee4c271da0d1137fe2cc19143e2b Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Fri, 8 Mar 2019 16:08:06 -0500 Subject: [PATCH] prevents aws errors when not using aws --- cmd/fluxd/main.go | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 1ebd95bef..3d14299fe 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -334,23 +334,37 @@ func main() { // Wrap the procedure for collecting images to scan { - awsConf := registry.AWSRegistryConfig{ - Regions: *registryAWSRegions, - AccountIDs: *registryAWSAccountIDs, - BlockIDs: *registryAWSBlockAccountIDs, + awsOptions := []string{ + "registry-ecr-region", + "registry-ecr-include-id", + "registry-ecr-exclude-id", } - credsWithAWSAuth, err := registry.ImageCredsWithAWSAuth(imageCreds, log.With(logger, "component", "aws"), awsConf) - if err != nil { - logger.Log("warning", "AWS authorization not used; pre-flight check failed") - } else { - imageCreds = credsWithAWSAuth + usingAWS := false + for _, awsOption := range awsOptions { + if fs.Changed(awsOption) { + usingAWS = true + break + } } - if *dockerConfig != "" { - credsWithDefaults, err := registry.ImageCredsWithDefaults(imageCreds, *dockerConfig) + if usingAWS { + awsConf := registry.AWSRegistryConfig{ + Regions: *registryAWSRegions, + AccountIDs: *registryAWSAccountIDs, + BlockIDs: *registryAWSBlockAccountIDs, + } + credsWithAWSAuth, err := registry.ImageCredsWithAWSAuth(imageCreds, log.With(logger, "component", "aws"), awsConf) if err != nil { - logger.Log("warning", "--docker-config not used; pre-flight check failed", "err", err) + logger.Log("warning", "AWS authorization not used; pre-flight check failed") } else { - imageCreds = credsWithDefaults + imageCreds = credsWithAWSAuth + } + if *dockerConfig != "" { + credsWithDefaults, err := registry.ImageCredsWithDefaults(imageCreds, *dockerConfig) + if err != nil { + logger.Log("warning", "--docker-config not used; pre-flight check failed", "err", err) + } else { + imageCreds = credsWithDefaults + } } } }