Skip to content

Commit

Permalink
☢️ bug: backend config (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Jun 4, 2024
1 parent cd13752 commit baa0360
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 76 deletions.
8 changes: 4 additions & 4 deletions backend/config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ type AuthSettings struct {
}

type intermediateAuthSettings struct {
accessKey string `env:"ACCESS_KEY"`
refreshKey string `env:"REFRESH_KEY"`
AccessKey string `env:"ACCESS_KEY"`
RefreshKey string `env:"REFRESH_KEY"`
}

func (i *intermediateAuthSettings) into() (*AuthSettings, error) {
accessKey, err := m.NewSecret(i.accessKey)
accessKey, err := m.NewSecret(i.AccessKey)
if err != nil {
return nil, fmt.Errorf("failed to create secret from access key: %s", err.Error())
}

refreshKey, err := m.NewSecret(i.refreshKey)
refreshKey, err := m.NewSecret(i.RefreshKey)
if err != nil {
return nil, fmt.Errorf("failed to create secret from refresh key: %s", err.Error())
}
Expand Down
16 changes: 8 additions & 8 deletions backend/config/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ type AWSSettings struct {
}

type intermediateAWSSettings struct {
bucketName string `env:"BUCKET_NAME"`
id string `env:"ID"`
secret string `env:"SECRET"`
region string `env:"REGION"`
BucketName string `env:"BUCKET_NAME"`
ID string `env:"ID"`
Secret string `env:"SECRET"`
Region string `env:"REGION"`
}

func (i *intermediateAWSSettings) into() (*AWSSettings, error) {
bucketName, err := m.NewSecret(i.bucketName)
bucketName, err := m.NewSecret(i.BucketName)
if err != nil {
return nil, fmt.Errorf("failed to create secret from bucket name: %s", err.Error())
}

id, err := m.NewSecret(i.id)
id, err := m.NewSecret(i.ID)
if err != nil {
return nil, fmt.Errorf("failed to create secret from ID: %s", err.Error())
}

secret, err := m.NewSecret(i.secret)
secret, err := m.NewSecret(i.Secret)
if err != nil {
return nil, fmt.Errorf("failed to create secret from secret: %s", err.Error())
}

region, err := m.NewSecret(i.region)
region, err := m.NewSecret(i.Region)
if err != nil {
return nil, fmt.Errorf("failed to create secret from region: %s", err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions backend/config/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type CalendarSettings struct {
}

type intermediateCalendarSettings struct {
maxTerminationDate string `env:"MAX_TERMINATION_DATE"`
MaxTerminationDate string `env:"MAX_TERMINATION_DATE"`
}

func (i *intermediateCalendarSettings) into() (*CalendarSettings, error) {
maxTerminationDate, err := time.Parse("01-02-2006", i.maxTerminationDate)
maxTerminationDate, err := time.Parse("01-02-2006", i.MaxTerminationDate)
if err != nil {
return nil, fmt.Errorf("failed to parse max termination date: %s", err.Error())
}
Expand Down
10 changes: 4 additions & 6 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import (
)

func GetConfiguration(path string) (*Settings, error) {
err := godotenv.Load(path)
if err != nil {
if err := godotenv.Load(path); err != nil {
return nil, fmt.Errorf("failed to load environment variables: %s", err.Error())
}

var intermediateSettings intermediateSettings
if err := env.Parse(&intermediateSettings); err != nil {
intSettings, err := env.ParseAs[intermediateSettings]()
if err != nil {
return nil, fmt.Errorf("failed to parse environment variables: %s", err.Error())
}

settings, err := intermediateSettings.into()
return settings, err
return intSettings.into()
}
24 changes: 12 additions & 12 deletions backend/config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ func (s *DatabaseSettings) PostgresConn() string {
}

type intermediateDatabaseSettings struct {
username string `env:"USERNAME"`
password string `env:"PASSWORD"`
port uint `env:"PORT"`
host string `env:"HOST"`
databaseName string `env:"NAME"`
requireSSL bool `env:"REQUIRE_SSL"`
Username string `env:"USERNAME"`
Password string `env:"PASSWORD"`
Port uint `env:"PORT"`
Host string `env:"HOST"`
DatabaseName string `env:"NAME"`
RequireSSL bool `env:"REQUIRE_SSL"`
}

func (i *intermediateDatabaseSettings) into() (*DatabaseSettings, error) {
password, err := m.NewSecret(i.password)
password, err := m.NewSecret(i.Password)
if err != nil {
return nil, fmt.Errorf("failed to create secret from password: %s", err.Error())
}

return &DatabaseSettings{
Username: i.username,
Username: i.Username,
Password: password,
Port: i.port,
Host: i.host,
DatabaseName: i.databaseName,
RequireSSL: i.requireSSL,
Port: i.Port,
Host: i.Host,
DatabaseName: i.DatabaseName,
RequireSSL: i.RequireSSL,
}, nil
}
20 changes: 10 additions & 10 deletions backend/config/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ type RedisSettings struct {
}

type intermediateRedisSettings struct {
username string `env:"USERNAME"`
password string `env:"PASSWORD"`
host string `env:"HOST"`
port uint `env:"PORT"`
db int `env:"DB"`
Username string `env:"USERNAME"`
Password string `env:"PASSWORD"`
Host string `env:"HOST"`
Port uint `env:"PORT"`
DB int `env:"DB"`
// TLSConfig *intermediateTLSConfig `env:"TLS_CONFIG"`
}

func (i *intermediateRedisSettings) into() (*RedisSettings, error) {
password, err := m.NewSecret(i.password)
password, err := m.NewSecret(i.Password)
if err != nil {
return nil, fmt.Errorf("failed to create secret from password: %s", err.Error())
}

return &RedisSettings{
Username: i.username,
Username: i.Username,
Password: password,
Host: i.host,
Port: i.port,
DB: i.db,
Host: i.Host,
Port: i.Port,
DB: i.DB,
// TLSConfig: i.TLSConfig.into(),
}, nil
}
4 changes: 2 additions & 2 deletions backend/config/resend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ type ResendSettings struct {
}

type intermediateResendSettings struct {
apiKey string `env:"API_KEY"`
APIKey string `env:"API_KEY"`
}

func (i *intermediateResendSettings) into() (*ResendSettings, error) {
apiKey, err := m.NewSecret(i.apiKey)
apiKey, err := m.NewSecret(i.APIKey)
if err != nil {
return nil, fmt.Errorf("failed to create secret from API key: %s", err.Error())
}
Expand Down
52 changes: 26 additions & 26 deletions backend/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,79 +21,79 @@ type Integrations struct {
}

type intermediateSettings struct {
application ApplicationSettings `envPrefix:"SAC_APPLICATION_"`
database intermediateDatabaseSettings `envPrefix:"SAC_DB_"`
redisActiveTokens intermediateRedisSettings `envPrefix:"SAC_REDIS_ACTIVE_TOKENS_"`
redisBlacklist intermediateRedisSettings `envPrefix:"SAC_REDIS_BLACKLIST_"`
redisLimiter intermediateRedisSettings `envPrefix:"SAC_REDIS_LIMITER_"`
superUser intermediateSuperUserSettings `envPrefix:"SAC_SUDO_"`
auth intermediateAuthSettings `envPrefix:"SAC_AUTH_"`
aws intermediateAWSSettings `envPrefix:"SAC_AWS_"`
resend intermediateResendSettings `envPrefix:"SAC_RESEND_"`
calendar intermediateCalendarSettings `envPrefix:"SAC_CALENDAR_"`
googleSettings intermediateGoogleOAuthSettings `envPrefix:"SAC_GOOGLE_OAUTH"`
outlookSettings intermdeiateOutlookOAuthSettings `envPrefix:"SAC_OUTLOOK_OAUTH"`
search SearchSettings `env:"SAC_SEARCH"`
Application ApplicationSettings `envPrefix:"SAC_APPLICATION_"`
Database intermediateDatabaseSettings `envPrefix:"SAC_DB_"`
RedisActiveTokens intermediateRedisSettings `envPrefix:"SAC_REDIS_ACTIVE_TOKENS_"`
RedisBlacklist intermediateRedisSettings `envPrefix:"SAC_REDIS_BLACKLIST_"`
RedisLimiter intermediateRedisSettings `envPrefix:"SAC_REDIS_LIMITER_"`
SuperUser intermediateSuperUserSettings `envPrefix:"SAC_SUDO_"`
Auth intermediateAuthSettings `envPrefix:"SAC_AUTH_"`
AWS intermediateAWSSettings `envPrefix:"SAC_AWS_"`
Resend intermediateResendSettings `envPrefix:"SAC_RESEND_"`
Calendar intermediateCalendarSettings `envPrefix:"SAC_CALENDAR_"`
GoogleSettings intermediateGoogleOAuthSettings `envPrefix:"SAC_GOOGLE_OAUTH_"`
OutlookSettings intermdeiateOutlookOAuthSettings `envPrefix:"SAC_OUTLOOK_OAUTH_"`
Search SearchSettings `envPrefix:"SAC_SEARCH_"`
}

func (i *intermediateSettings) into() (*Settings, error) {
database, err := i.database.into()
database, err := i.Database.into()
if err != nil {
return nil, err
}

redisActiveTokens, err := i.redisActiveTokens.into()
redisActiveTokens, err := i.RedisActiveTokens.into()
if err != nil {
return nil, err
}

redisBlacklist, err := i.redisBlacklist.into()
redisBlacklist, err := i.RedisBlacklist.into()
if err != nil {
return nil, err
}

redisLimiter, err := i.redisLimiter.into()
redisLimiter, err := i.RedisLimiter.into()
if err != nil {
return nil, err
}

superUser, err := i.superUser.into()
superUser, err := i.SuperUser.into()
if err != nil {
return nil, err
}

auth, err := i.auth.into()
auth, err := i.Auth.into()
if err != nil {
return nil, err
}

aws, err := i.aws.into()
aws, err := i.AWS.into()
if err != nil {
return nil, err
}

resend, err := i.resend.into()
resend, err := i.Resend.into()
if err != nil {
return nil, err
}

calendar, err := i.calendar.into()
calendar, err := i.Calendar.into()
if err != nil {
return nil, err
}

google, err := i.googleSettings.into()
google, err := i.GoogleSettings.into()
if err != nil {
return nil, err
}

outlook, err := i.outlookSettings.into()
outlook, err := i.OutlookSettings.into()
if err != nil {
return nil, err
}

return &Settings{
Application: i.application,
Application: i.Application,
Database: *database,
RedisActiveTokens: *redisActiveTokens,
RedisBlacklist: *redisBlacklist,
Expand All @@ -106,7 +106,7 @@ func (i *intermediateSettings) into() (*Settings, error) {
OutlookOauth: *outlook,
AWS: *aws,
Resend: *resend,
Search: i.search,
Search: i.Search,
},
}, nil
}
4 changes: 2 additions & 2 deletions backend/config/sudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type SuperUserSettings struct {
Password *m.Secret[string]
}
type intermediateSuperUserSettings struct {
password string `env:"PASSWORD"`
Password string `env:"PASSWORD"`
}

func (i *intermediateSuperUserSettings) into() (*SuperUserSettings, error) {
password, err := m.NewSecret(i.password)
password, err := m.NewSecret(i.Password)
if err != nil {
return nil, fmt.Errorf("failed to create secret from password: %s", err.Error())
}
Expand Down
7 changes: 3 additions & 4 deletions config/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SAC_DB_NAME="sac"
SAC_DB_REQUIRE_SSL="false"

SAC_REDIS_ACTIVE_TOKENS_USERNAME="redis_active_tokens"
SAC_REDIS_ACTIVE_TOKENS_PASSWORD="redis_active_token!#1"
SAC_REDIS_ACTIVE_TOKENS_PASSWORD="redis_active_tokens!#1"
SAC_REDIS_ACTIVE_TOKENS_HOST="127.0.0.1"
SAC_REDIS_ACTIVE_TOKENS_PORT="6379"
SAC_REDIS_ACTIVE_TOKENS_DB="0"
Expand All @@ -27,7 +27,6 @@ SAC_REDIS_LIMITER_HOST="127.0.0.1"
SAC_REDIS_LIMITER_PORT="6381"
SAC_REDIS_LIMITER_DB="0"


SAC_AWS_BUCKET_NAME="SAC_AWS_BUCKET_NAME"
SAC_AWS_ID="SAC_AWS_ID"
SAC_AWS_SECRET="SAC_AWS_SECRET"
Expand All @@ -54,6 +53,6 @@ SAC_GOOGLE_OAUTH_REDIRECT_URI="http://127.0.0.1:3000"

SAC_OUTLOOK_OAUTH_CLIENT_ID=test
SAC_OUTLOOK_OAUTH_CLIENT_SECRET=test
SAC_OUTLOOK_OAUTH_REDIRECT_URI="http://127.0.0.1:3000
SAC_OUTLOOK_OAUTH_REDIRECT_URI="http://127.0.0.1:3000"

SAC_SEARCH_URI=""http://127.0.0.1:9200"
SAC_SEARCH_URI="http://127.0.0.1:9200"

0 comments on commit baa0360

Please sign in to comment.