fix: make env vars name more persistent
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
package dynamodb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
"github.com/authorizerdev/authorizer/server/memorystore"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/guregu/dynamo"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
"github.com/authorizerdev/authorizer/server/memorystore"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
@@ -21,8 +23,8 @@ type provider struct {
|
||||
func NewProvider() (*provider, error) {
|
||||
dbURL := memorystore.RequiredEnvStoreObj.GetRequiredEnv().DatabaseURL
|
||||
awsRegion := os.Getenv(constants.EnvAwsRegion)
|
||||
accessKey := os.Getenv(constants.EnvAwsAccessKey)
|
||||
secretKey := os.Getenv(constants.EnvAwsSecretKey)
|
||||
accessKey := os.Getenv(constants.EnvAwsAccessKeyID)
|
||||
secretKey := os.Getenv(constants.EnvAwsSecretAccessKey)
|
||||
|
||||
config := aws.Config{
|
||||
MaxRetries: aws.Int(3),
|
||||
@@ -33,6 +35,16 @@ func NewProvider() (*provider, error) {
|
||||
config.Region = aws.String(awsRegion)
|
||||
}
|
||||
|
||||
if accessKey == "" {
|
||||
log.Debugf("%s not found", constants.EnvAwsAccessKeyID)
|
||||
return nil, fmt.Errorf("invalid aws credentials. %s not found", constants.EnvAwsAccessKeyID)
|
||||
}
|
||||
|
||||
if secretKey == "" {
|
||||
log.Debugf("%s not found", constants.EnvAwsSecretAccessKey)
|
||||
return nil, fmt.Errorf("invalid aws credentials. %s not found", constants.EnvAwsSecretAccessKey)
|
||||
}
|
||||
|
||||
// custom accessKey, secretkey took first priority, if not then fetch config from aws credentials
|
||||
if accessKey != "" && secretKey != "" {
|
||||
config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
|
||||
@@ -40,8 +52,6 @@ func NewProvider() (*provider, error) {
|
||||
// static config in case of testing or local-setup
|
||||
config.Credentials = credentials.NewStaticCredentials("key", "key", "")
|
||||
config.Endpoint = aws.String(dbURL)
|
||||
} else {
|
||||
log.Info("REGION, AWS_ACCESS_KEY and AWS_SECRET_KEY not found in .env, trying to load default profile from aws credentials")
|
||||
}
|
||||
|
||||
session := session.Must(session.NewSession(&config))
|
||||
|
Reference in New Issue
Block a user