forked from dexidp/dex
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ErikBZ/INT-5890-dexidp-dynamodb
Add DynamoDB Storage to DexIDP
- Loading branch information
Showing
6 changed files
with
986 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package dynamodb | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/dynamodb" | ||
"github.com/dexidp/dex/pkg/log" | ||
"github.com/dexidp/dex/storage" | ||
) | ||
|
||
type AWSConfig struct { | ||
ProfileName string | ||
Region string | ||
Table string | ||
} | ||
|
||
type DynamoDB struct { | ||
AWSConfig | ||
} | ||
|
||
func (dbd *DynamoDB) Open(logger log.Logger) (storage.Storage, error) { | ||
conn, err := dbd.open(logger) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return conn, nil | ||
} | ||
|
||
func (dbd *DynamoDB) open(logger log.Logger) (*conn, error) { | ||
var cfg aws.Config | ||
|
||
if dbd.ProfileName != "" { | ||
var err error | ||
cfg, err = config.LoadDefaultConfig( | ||
context.TODO(), | ||
config.WithRegion(dbd.Region), | ||
config.WithSharedConfigProfile(dbd.ProfileName), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
var err error | ||
cfg, err = config.LoadDefaultConfig( | ||
context.TODO(), | ||
config.WithRegion(dbd.Region), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
svc := dynamodb.NewFromConfig(cfg) | ||
|
||
c := &conn{ | ||
db: svc, | ||
logger: logger, | ||
table: dbd.Table, | ||
} | ||
|
||
return c, nil | ||
} |
Oops, something went wrong.