11package dynamodb
22
33import (
4+ "fmt"
45 "os"
56
6- "github.com/authorizerdev/authorizer/server/constants"
7- "github.com/authorizerdev/authorizer/server/db/models"
8- "github.com/authorizerdev/authorizer/server/memorystore"
97 "github.com/aws/aws-sdk-go/aws"
108 "github.com/aws/aws-sdk-go/aws/credentials"
119 "github.com/aws/aws-sdk-go/aws/session"
1210 "github.com/guregu/dynamo"
1311 log "github.com/sirupsen/logrus"
12+
13+ "github.com/authorizerdev/authorizer/server/constants"
14+ "github.com/authorizerdev/authorizer/server/db/models"
15+ "github.com/authorizerdev/authorizer/server/memorystore"
1416)
1517
1618type provider struct {
@@ -21,8 +23,8 @@ type provider struct {
2123func NewProvider () (* provider , error ) {
2224 dbURL := memorystore .RequiredEnvStoreObj .GetRequiredEnv ().DatabaseURL
2325 awsRegion := os .Getenv (constants .EnvAwsRegion )
24- accessKey := os .Getenv (constants .EnvAwsAccessKey )
25- secretKey := os .Getenv (constants .EnvAwsSecretKey )
26+ accessKey := os .Getenv (constants .EnvAwsAccessKeyID )
27+ secretKey := os .Getenv (constants .EnvAwsSecretAccessKey )
2628
2729 config := aws.Config {
2830 MaxRetries : aws .Int (3 ),
@@ -33,15 +35,23 @@ func NewProvider() (*provider, error) {
3335 config .Region = aws .String (awsRegion )
3436 }
3537
38+ if accessKey == "" {
39+ log .Debugf ("%s not found" , constants .EnvAwsAccessKeyID )
40+ return nil , fmt .Errorf ("invalid aws credentials. %s not found" , constants .EnvAwsAccessKeyID )
41+ }
42+
43+ if secretKey == "" {
44+ log .Debugf ("%s not found" , constants .EnvAwsSecretAccessKey )
45+ return nil , fmt .Errorf ("invalid aws credentials. %s not found" , constants .EnvAwsSecretAccessKey )
46+ }
47+
3648 // custom accessKey, secretkey took first priority, if not then fetch config from aws credentials
3749 if accessKey != "" && secretKey != "" {
3850 config .Credentials = credentials .NewStaticCredentials (accessKey , secretKey , "" )
3951 } else if dbURL != "" {
4052 // static config in case of testing or local-setup
4153 config .Credentials = credentials .NewStaticCredentials ("key" , "key" , "" )
4254 config .Endpoint = aws .String (dbURL )
43- } else {
44- log .Info ("REGION, AWS_ACCESS_KEY and AWS_SECRET_KEY not found in .env, trying to load default profile from aws credentials" )
4555 }
4656
4757 session := session .Must (session .NewSession (& config ))
0 commit comments