mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Pass AWS credentials
This commit is contained in:
@ -8,6 +8,9 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
|
||||
"github.com/mxpv/podsync/pkg/api"
|
||||
"github.com/mxpv/podsync/pkg/builders"
|
||||
"github.com/mxpv/podsync/pkg/config"
|
||||
@ -34,16 +37,28 @@ func main() {
|
||||
log.WithError(err).Fatal("failed to read configuration")
|
||||
}
|
||||
|
||||
database, err := storage.NewPG(cfg.PostgresConnectionURL, true)
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("failed to create pg")
|
||||
}
|
||||
|
||||
statistics, err := stats.NewRedisStats(cfg.RedisURL)
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("failed to create redis")
|
||||
}
|
||||
|
||||
database, err := storage.NewDynamo(&aws.Config{
|
||||
Region: aws.String("us-east-1"),
|
||||
Credentials: credentials.NewStaticCredentials(cfg.AWSAccessKey, cfg.AWSAccessSecret, ""),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("failed to create database")
|
||||
}
|
||||
|
||||
if cfg.DynamoPledgesTableName != "" {
|
||||
database.PledgesTableName = aws.String(cfg.DynamoPledgesTableName)
|
||||
}
|
||||
|
||||
if cfg.DynamoFeedsTableName != "" {
|
||||
database.FeedsTableName = aws.String(cfg.DynamoFeedsTableName)
|
||||
}
|
||||
|
||||
patreon := support.NewPatreon(database)
|
||||
|
||||
// Builders
|
||||
@ -66,7 +81,7 @@ func main() {
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.WithError(err).Fatal("failed to create feed service")
|
||||
}
|
||||
|
||||
srv := http.Server{
|
||||
|
@ -20,6 +20,8 @@ services:
|
||||
- PATREON_WEBHOOKS_SECRET={PATREON_WEBHOOKS_SECRET}
|
||||
- COOKIE_SECRET={COOKIE_SECRET}
|
||||
- GIN_MODE=release
|
||||
- AWS_ACCESS_KEY={AWS_ACCESS_KEY}
|
||||
- AWS_ACCESS_SECRET={AWS_ACCESS_SECRET}
|
||||
- DYNAMO_FEEDS_TABLE_NAME=Prod_Feeds
|
||||
- DYNAMO_PLEDGES_TABLE_NAME=Prod_Pledges
|
||||
volumes:
|
||||
|
@ -20,6 +20,8 @@ type AppConfig struct {
|
||||
CookieSecret string `yaml:"cookieSecret"`
|
||||
AssetsPath string `yaml:"assetsPath"`
|
||||
TemplatesPath string `yaml:"templatesPath"`
|
||||
AWSAccessKey string `yaml:"awsAccessKey"`
|
||||
AWSAccessSecret string `yaml:"awsAccessSecret"`
|
||||
DynamoFeedsTableName string `yaml:"dynamoFeedsTableName"`
|
||||
DynamoPledgesTableName string `yaml:"dynamoPledgesTableName"`
|
||||
}
|
||||
@ -47,6 +49,8 @@ func ReadConfiguration() (cfg *AppConfig, err error) {
|
||||
"cookieSecret": "COOKIE_SECRET",
|
||||
"assetsPath": "ASSETS_PATH",
|
||||
"templatesPath": "TEMPLATES_PATH",
|
||||
"awsAccessKey": "AWS_ACCESS_KEY",
|
||||
"awsAccessSecret": "AWS_ACCESS_SECRET",
|
||||
"dynamoFeedsTableName": "DYNAMO_FEEDS_TABLE_NAME",
|
||||
"dynamoPledgesTableName": "DYNAMO_PLEDGES_TABLE_NAME",
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ templatesPath: "9"
|
||||
patreonWebhooksSecret: "10"
|
||||
dynamoFeedsTableName: "11"
|
||||
dynamoPledgesTableName: "12"
|
||||
awsAccessKey: "13"
|
||||
awsAccessSecret: "14"
|
||||
`
|
||||
|
||||
func TestReadYaml(t *testing.T) {
|
||||
@ -46,6 +48,8 @@ func TestReadYaml(t *testing.T) {
|
||||
require.Equal(t, "10", cfg.PatreonWebhooksSecret)
|
||||
require.Equal(t, "11", cfg.DynamoFeedsTableName)
|
||||
require.Equal(t, "12", cfg.DynamoPledgesTableName)
|
||||
require.Equal(t, "13", cfg.AWSAccessKey)
|
||||
require.Equal(t, "14", cfg.AWSAccessSecret)
|
||||
}
|
||||
|
||||
func TestReadEnv(t *testing.T) {
|
||||
@ -64,6 +68,8 @@ func TestReadEnv(t *testing.T) {
|
||||
os.Setenv("PATREON_WEBHOOKS_SECRET", "1010")
|
||||
os.Setenv("DYNAMO_FEEDS_TABLE_NAME", "1111")
|
||||
os.Setenv("DYNAMO_PLEDGES_TABLE_NAME", "1212")
|
||||
os.Setenv("AWS_ACCESS_KEY", "1313")
|
||||
os.Setenv("AWS_ACCESS_SECRET", "1414")
|
||||
|
||||
cfg, err := ReadConfiguration()
|
||||
require.NoError(t, err)
|
||||
@ -80,4 +86,6 @@ func TestReadEnv(t *testing.T) {
|
||||
require.Equal(t, "1010", cfg.PatreonWebhooksSecret)
|
||||
require.Equal(t, "1111", cfg.DynamoFeedsTableName)
|
||||
require.Equal(t, "1212", cfg.DynamoPledgesTableName)
|
||||
require.Equal(t, "1313", cfg.AWSAccessKey)
|
||||
require.Equal(t, "1414", cfg.AWSAccessSecret)
|
||||
}
|
||||
|
Reference in New Issue
Block a user