dynamod db index changes added to the schema
This commit is contained in:
@@ -2,51 +2,49 @@ package dynamodb
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// TODO change following provider to new db provider
|
||||
type provider struct {
|
||||
db *dynamo.DB
|
||||
}
|
||||
|
||||
// NewProvider returns a new SQL provider
|
||||
// TODO change following provider to new db provider
|
||||
// NewProvider returns a new Dynamo provider
|
||||
func NewProvider() (*provider, error) {
|
||||
region := memorystore.RequiredEnvStoreObj.GetRequiredEnv().REGION
|
||||
dbURL := memorystore.RequiredEnvStoreObj.GetRequiredEnv().DatabaseURL
|
||||
accessKey := memorystore.RequiredEnvStoreObj.GetRequiredEnv().AWS_ACCESS_KEY
|
||||
secretKey := memorystore.RequiredEnvStoreObj.GetRequiredEnv().AWS_SECRET_KEY
|
||||
config := aws.Config{
|
||||
Endpoint: aws.String("http://localhost:8000"),
|
||||
Region: aws.String("us-east-1"),
|
||||
Region: aws.String(region),
|
||||
MaxRetries: aws.Int(3),
|
||||
}
|
||||
session := session.Must(session.NewSession())
|
||||
db := dynamo.New(session, &config)
|
||||
|
||||
if err := db.CreateTable(models.Collections.User, models.User{}).Wait(); err != nil {
|
||||
// fmt.Println(" User", err)
|
||||
}
|
||||
if err := db.CreateTable(models.Collections.Session, models.Session{}).Wait(); err != nil {
|
||||
// fmt.Println("Session error", err)
|
||||
}
|
||||
if err := db.CreateTable(models.Collections.EmailTemplate, models.EmailTemplate{}).Wait(); err != nil {
|
||||
// fmt.Println(" EmailTemplate", err)
|
||||
}
|
||||
if err := db.CreateTable(models.Collections.Env, models.Env{}).Wait(); err != nil {
|
||||
// fmt.Println(" Env", err)
|
||||
}
|
||||
if err := db.CreateTable(models.Collections.OTP, models.OTP{}).Wait(); err != nil {
|
||||
// fmt.Println(" OTP", err)
|
||||
}
|
||||
if err := db.CreateTable(models.Collections.VerificationRequest, models.VerificationRequest{}).Wait(); err != nil {
|
||||
// fmt.Println(" VerificationRequest", err)
|
||||
}
|
||||
if err := db.CreateTable(models.Collections.Webhook, models.Webhook{}).Wait(); err != nil {
|
||||
// fmt.Println(" Webhook", err)
|
||||
}
|
||||
if err := db.CreateTable(models.Collections.WebhookLog, models.WebhookLog{}).Wait(); err != nil {
|
||||
// fmt.Println(" WebhookLog", err)
|
||||
// custom accessKey, secretkey took first priority, if not then fetch config from aws credentials
|
||||
if accessKey != "" && secretKey != "" {
|
||||
config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
|
||||
} else if dbURL != "" {
|
||||
// static config in case of testing or local-setup
|
||||
config.Credentials = credentials.NewStaticCredentials("key", "key", "")
|
||||
config.Endpoint = aws.String(dbURL)
|
||||
}
|
||||
|
||||
session := session.Must(session.NewSession(&config))
|
||||
db := dynamo.New(session)
|
||||
|
||||
db.CreateTable(models.Collections.User, models.User{}).Wait()
|
||||
db.CreateTable(models.Collections.Session, models.Session{}).Wait()
|
||||
db.CreateTable(models.Collections.EmailTemplate, models.EmailTemplate{}).Wait()
|
||||
db.CreateTable(models.Collections.Env, models.Env{}).Wait()
|
||||
db.CreateTable(models.Collections.OTP, models.OTP{}).Wait()
|
||||
db.CreateTable(models.Collections.VerificationRequest, models.VerificationRequest{}).Wait()
|
||||
db.CreateTable(models.Collections.Webhook, models.Webhook{}).Wait()
|
||||
db.CreateTable(models.Collections.WebhookLog, models.WebhookLog{}).Wait()
|
||||
|
||||
return &provider{
|
||||
db: db,
|
||||
}, nil
|
||||
|
Reference in New Issue
Block a user