From fbf4229e96c1fd83563adc7f13f7bec5c7f96068 Mon Sep 17 00:00:00 2001 From: nyanotech Date: Mon, 8 Apr 2024 21:39:53 -0700 Subject: [PATCH] accept aws credentials from environment variables --- main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index ea29ab3..3e8e4e1 100644 --- a/main.go +++ b/main.go @@ -30,9 +30,10 @@ var threadCount = flag.Int("threads", 1024, "how many objects to operate on at a func main() { flag.Parse() - cfg, err := config.LoadDefaultConfig(context.TODO(), - // just a placeholder because it needs to be defined - // should be using the one from the endpoint regardless + options := []func(*config.LoadOptions) error{} + + options = append(options, + // TODO: figure out what to do with this config.WithRegion("us-east-1"), config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc( func(service, region string, options ...interface{}) (aws.Endpoint, error) { @@ -41,7 +42,14 @@ func main() { }, nil }, )), - config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(*accessKeyId, *secretAccessKey, "")), + ) + + if *accessKeyId != "" && *secretAccessKey != "" { + options = append(options, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(*accessKeyId, *secretAccessKey, ""))) + } + + cfg, err := config.LoadDefaultConfig(context.TODO(), + options..., ) if err != nil { log.Fatalln("Failed to create AWS config", err)