From 4588e9bd23003ada14f1f4af2bfe532f49deef70 Mon Sep 17 00:00:00 2001 From: garrettladley Date: Tue, 28 May 2024 18:20:14 -0400 Subject: [PATCH] config redirect uri | private intermediate structs and their fields --- backend/config/auth.go | 8 +++--- backend/config/aws.go | 20 ++++++------- backend/config/calendar.go | 4 +-- backend/config/database.go | 24 ++++++++-------- backend/config/oauth_google.go | 13 +++++---- backend/config/oauth_outlook.go | 13 +++++---- backend/config/redis.go | 20 ++++++------- backend/config/resend.go | 4 +-- backend/config/settings.go | 48 +++++++++++++++---------------- backend/integrations/file/file.go | 2 +- config/.env.template | 15 +++++----- 11 files changed, 87 insertions(+), 84 deletions(-) diff --git a/backend/config/auth.go b/backend/config/auth.go index e359095c..0acf2019 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 0f52b2e1..c6effb90 100644 --- a/backend/config/aws.go +++ b/backend/config/aws.go @@ -8,42 +8,42 @@ import ( type AWSSettings struct { BucketName *m.Secret[string] - Id *m.Secret[string] + ID *m.Secret[string] Secret *m.Secret[string] Region *m.Secret[string] } 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()) } return &AWSSettings{ BucketName: bucketName, - Id: id, + ID: id, Secret: secret, Region: region, }, nil diff --git a/backend/config/calendar.go b/backend/config/calendar.go index 41dfbb00..1489aff7 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/database.go b/backend/config/database.go index 2d0f367e..b507a5e6 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/oauth_google.go b/backend/config/oauth_google.go index 3c9662a0..a26101ab 100644 --- a/backend/config/oauth_google.go +++ b/backend/config/oauth_google.go @@ -6,13 +6,14 @@ import ( m "github.com/garrettladley/mattress" ) -type GoogleOAuthSettings struct { - ClientId string `env:"GOOGLE_OAUTH_CLIENT_ID"` - ClientSecret string `env:"GOOGLE_OAUTH_CLIENT_SECRET"` +type intermediateGoogleOAuthSettings struct { + ClientID string `env:"CLIENT_ID"` + ClientSecret string `env:"CLIENT_SECRET"` + RedirectURI string `env:"REDIRECT_URI"` } -func (i *GoogleOAuthSettings) into() (*OAuthSettings, error) { - secretClientID, err := m.NewSecret(i.ClientId) +func (i *intermediateGoogleOAuthSettings) into() (*OAuthSettings, error) { + secretClientID, err := m.NewSecret(i.ClientID) if err != nil { return nil, fmt.Errorf("failed to create secret from client ID: %s", err.Error()) } @@ -29,7 +30,7 @@ func (i *GoogleOAuthSettings) into() (*OAuthSettings, error) { ClientSecret: secretClientSecret, Scopes: "https://www.googleapis.com/auth/calendar.events https://www.googleapis.com/auth/calendar.readonly", ResponseType: "code", - RedirectURI: "http://127.0.0.1:3000", + RedirectURI: i.RedirectURI, IncludeGrantedScopes: "true", AccessType: "offline", Prompt: "consent", diff --git a/backend/config/oauth_outlook.go b/backend/config/oauth_outlook.go index 24b5448b..ce0cb11c 100644 --- a/backend/config/oauth_outlook.go +++ b/backend/config/oauth_outlook.go @@ -6,13 +6,14 @@ import ( m "github.com/garrettladley/mattress" ) -type OutlookOAuthSettings struct { - ClientId string `env:"OUTLOOK_OAUTH_CLIENT_ID"` - ClientSecret string `env:"OUTLOOK_OAUTH_CLIENT_SECRET"` +type intermdeiateOutlookOAuthSettings struct { + ClientID string `env:"CLIENT_ID"` + ClientSecret string `env:"CLIENT_SECRET"` + RedirectURI string `env:"REDIRECT_URI"` } -func (i *OutlookOAuthSettings) into() (*OAuthSettings, error) { - secretClientID, err := m.NewSecret(i.ClientId) +func (i *intermdeiateOutlookOAuthSettings) into() (*OAuthSettings, error) { + secretClientID, err := m.NewSecret(i.ClientID) if err != nil { return nil, fmt.Errorf("failed to create secret from client ID: %s", err.Error()) } @@ -29,7 +30,7 @@ func (i *OutlookOAuthSettings) into() (*OAuthSettings, error) { ClientSecret: secretClientSecret, Scopes: "offline_access user.read calendars.readwrite", ResponseType: "code", - RedirectURI: "http://127.0.0.1:3000", + RedirectURI: i.RedirectURI, ResponseMode: "query", Prompt: "consent", }, nil diff --git a/backend/config/redis.go b/backend/config/redis.go index 27a12231..926d72a1 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 73c724d3..f2292d3e 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 c4856b8a..8a3f234e 100644 --- a/backend/config/settings.go +++ b/backend/config/settings.go @@ -16,78 +16,78 @@ type Settings 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 GoogleOAuthSettings `envPrefix:"SAC_GOOGLE_OAUTH"` - OutlookSettings OutlookOAuthSettings `envPrefix:"SAC_OUTLOOK_OAUTH"` + 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"` } 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, diff --git a/backend/integrations/file/file.go b/backend/integrations/file/file.go index f2514772..c5c58726 100644 --- a/backend/integrations/file/file.go +++ b/backend/integrations/file/file.go @@ -45,7 +45,7 @@ type AWSClient struct { func NewAWSProvider(settings config.AWSSettings) FileClientInterface { sess, err := session.NewSession(&aws.Config{ Region: aws.String(settings.Region.Expose()), - Credentials: credentials.NewStaticCredentials(settings.Id.Expose(), settings.Secret.Expose(), ""), + Credentials: credentials.NewStaticCredentials(settings.ID.Expose(), settings.Secret.Expose(), ""), }) if err != nil { return nil diff --git a/config/.env.template b/config/.env.template index 3d49343e..dda0d2df 100644 --- a/config/.env.template +++ b/config/.env.template @@ -47,10 +47,11 @@ SAC_RESEND_API_KEY="SAC_RESEND_API_KEY" SAC_CALENDAR_MAX_TERMINATION_DATE="12-31-2024" -GOOGLE_OAUTH_CLIENT_ID=GOOGLE_OAUTH_CLIENT_ID -GOOGLE_OAUTH_CLIENT_SECRET=GOOGLE_OAUTH_CLIENT_SECRET -GOOGLE_API_KEY=GOOGLE_API_KEY - -OUTLOOK_OAUTH_CLIENT_ID=test -OUTLOOK_OAUTH_CLIENT_SECRET=test - +SAC_GOOGLE_OAUTH_CLIENT_ID=GOOGLE_OAUTH_CLIENT_ID +SAC_GOOGLE_OAUTH_CLIENT_SECRET=GOOGLE_OAUTH_CLIENT_SECRET +SAC_GOOGLE_API_KEY=GOOGLE_API_KEY +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