From 8d2116dfeb6a8bec12ce0dbec9b79cb7155e355a Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Fri, 4 Nov 2022 03:26:30 +0100 Subject: [PATCH] Fix dev mode for yumrepofs --- peridot/cmd/v1/yumrepofs/main.go | 2 +- utils/aws.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/peridot/cmd/v1/yumrepofs/main.go b/peridot/cmd/v1/yumrepofs/main.go index 4703d64..ba74284 100644 --- a/peridot/cmd/v1/yumrepofs/main.go +++ b/peridot/cmd/v1/yumrepofs/main.go @@ -60,7 +60,7 @@ func init() { } func mn(_ *cobra.Command, _ []string) { - sess, err := utils.NewAwsSession(&aws.Config{}) + sess, err := utils.NewAwsSessionNoLocalStack(&aws.Config{}) if err != nil { logrus.Fatal(err) } diff --git a/utils/aws.go b/utils/aws.go index a5c2c51..6f7a7cc 100644 --- a/utils/aws.go +++ b/utils/aws.go @@ -39,7 +39,7 @@ import ( "github.com/spf13/viper" ) -func NewAwsSession(cfg *aws.Config) (*session.Session, error) { +func awsConfigInternal(cfg *aws.Config) { if accessKey := viper.GetString("s3-access-key"); accessKey != "" { cfg.Credentials = credentials.NewStaticCredentials(accessKey, viper.GetString("s3-secret-key"), "") } @@ -63,7 +63,16 @@ func NewAwsSession(cfg *aws.Config) (*session.Session, error) { if os.Getenv("AWS_REGION") != "" { cfg.Region = aws.String(os.Getenv("AWS_REGION")) } +} +func NewAwsSessionNoLocalStack(cfg *aws.Config) (*session.Session, error) { + awsConfigInternal(cfg) + + return session.NewSession(cfg) +} + +func NewAwsSession(cfg *aws.Config) (*session.Session, error) { + awsConfigInternal(cfg) if os.Getenv("LOCALSTACK_ENDPOINT") != "" && os.Getenv("RESF_ENV") == "dev" { cfg.Endpoint = aws.String(os.Getenv("LOCALSTACK_ENDPOINT")) cfg.Credentials = credentials.NewStaticCredentials("test", "test", "")