From baa036099bef12e9975347ca13aea0d4d8347bf8 Mon Sep 17 00:00:00 2001 From: Garrett Ladley <92384606+garrettladley@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:37:21 -0400 Subject: [PATCH] =?UTF-8?q?=E2=98=A2=EF=B8=8F=20bug:=20backend=20config=20?= =?UTF-8?q?(#959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config/auth.go | 8 +++--- backend/config/aws.go | 16 ++++++------ backend/config/calendar.go | 4 +-- backend/config/config.go | 10 +++----- backend/config/database.go | 24 +++++++++--------- backend/config/redis.go | 20 +++++++-------- backend/config/resend.go | 4 +-- backend/config/settings.go | 52 +++++++++++++++++++------------------- backend/config/sudo.go | 4 +-- config/.env.template | 7 +++-- 10 files changed, 73 insertions(+), 76 deletions(-) diff --git a/backend/config/auth.go b/backend/config/auth.go index 0acf2019..e359095c 100644 --- a/backend/config/auth.go +++ b/backend/config/auth.go @@ -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()) } diff --git a/backend/config/aws.go b/backend/config/aws.go index c6effb90..bbdaaae0 100644 --- a/backend/config/aws.go +++ b/backend/config/aws.go @@ -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()) } diff --git a/backend/config/calendar.go b/backend/config/calendar.go index 1489aff7..41dfbb00 100644 --- a/backend/config/calendar.go +++ b/backend/config/calendar.go @@ -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()) } diff --git a/backend/config/config.go b/backend/config/config.go index 3298f094..010b5a55 100644 --- a/backend/config/config.go +++ b/backend/config/config.go @@ -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() } diff --git a/backend/config/database.go b/backend/config/database.go index b507a5e6..2d0f367e 100644 --- a/backend/config/database.go +++ b/backend/config/database.go @@ -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 } diff --git a/backend/config/redis.go b/backend/config/redis.go index 926d72a1..27a12231 100644 --- a/backend/config/redis.go +++ b/backend/config/redis.go @@ -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 } diff --git a/backend/config/resend.go b/backend/config/resend.go index f2292d3e..73c724d3 100644 --- a/backend/config/resend.go +++ b/backend/config/resend.go @@ -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()) } diff --git a/backend/config/settings.go b/backend/config/settings.go index 36c62f77..40e05d21 100644 --- a/backend/config/settings.go +++ b/backend/config/settings.go @@ -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, @@ -106,7 +106,7 @@ func (i *intermediateSettings) into() (*Settings, error) { OutlookOauth: *outlook, AWS: *aws, Resend: *resend, - Search: i.search, + Search: i.Search, }, }, nil } diff --git a/backend/config/sudo.go b/backend/config/sudo.go index d1e4d21e..823f09cd 100644 --- a/backend/config/sudo.go +++ b/backend/config/sudo.go @@ -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()) } diff --git a/config/.env.template b/config/.env.template index 7cf18761..864f6a33 100644 --- a/config/.env.template +++ b/config/.env.template @@ -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" @@ -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" @@ -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" \ No newline at end of file +SAC_SEARCH_URI="http://127.0.0.1:9200" \ No newline at end of file