Skip to content
Snippets Groups Projects
Commit 4585632c authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Use correct s3 credentials

parent 96de76b4
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ import ( ...@@ -4,6 +4,8 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"github.com/aws/aws-sdk-go/aws/credentials"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/secrets_manager"
"net/url" "net/url"
"os" "os"
"path" "path"
...@@ -87,7 +89,7 @@ type SessionWithHelpers struct { ...@@ -87,7 +89,7 @@ type SessionWithHelpers struct {
S3Session *s3.S3 S3Session *s3.S3
} }
func GetSession(region ...string) *SessionWithHelpers { func GetSession(isDebug bool, region ...string) *SessionWithHelpers {
s3Region := os.Getenv("AWS_REGION") s3Region := os.Getenv("AWS_REGION")
// Set custom region // Set custom region
...@@ -101,9 +103,11 @@ func GetSession(region ...string) *SessionWithHelpers { ...@@ -101,9 +103,11 @@ func GetSession(region ...string) *SessionWithHelpers {
} }
// Setup session // Setup session
s3Credentials := GetS3SessionCredentials(isDebug)
options := session.Options{ options := session.Options{
Config: aws.Config{ Config: aws.Config{
Region: aws.String(s3Region), Region: aws.String(s3Region),
Credentials: s3Credentials,
}, },
} }
...@@ -117,6 +121,15 @@ func GetSession(region ...string) *SessionWithHelpers { ...@@ -117,6 +121,15 @@ func GetSession(region ...string) *SessionWithHelpers {
return s3Session return s3Session
} }
func GetS3SessionCredentials(isDebug bool) *credentials.Credentials {
secretID := os.Getenv("S3_SECRET_ID")
s3Credentials, err := secrets_manager.GetS3UploadCredentials(secretID, isDebug)
if err != nil {
return nil
}
return s3Credentials
}
func NewSession(session *session.Session) *SessionWithHelpers { func NewSession(session *session.Session) *SessionWithHelpers {
return &SessionWithHelpers{ return &SessionWithHelpers{
S3Session: s3.New(session), S3Session: s3.New(session),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment