Skip to content

Commit

Permalink
Merge branch 'main' into onboarding-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
in-mai-space committed Jun 8, 2024
2 parents 3005c1c + 79e1013 commit cfe4349
Show file tree
Hide file tree
Showing 152 changed files with 6,118 additions and 3,111 deletions.
6 changes: 6 additions & 0 deletions backend/Dockerfile.redis
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM redis:latest

COPY redis_entrypoint.sh /usr/local/bin/redis_entrypoint.sh
RUN chmod +x /usr/local/bin/redis_entrypoint.sh

ENTRYPOINT ["redis_entrypoint.sh"]
File renamed without changes.
52 changes: 0 additions & 52 deletions backend/auth/locals.go

This file was deleted.

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: 5 additions & 2 deletions backend/constants/db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package constants

import "time"

const (
MAX_IDLE_CONNECTIONS int = 10
MAX_OPEN_CONNECTIONS int = 100
MAX_IDLE_CONNECTIONS int = 10
MAX_OPEN_CONNECTIONS int = 100
DB_TIMEOUT time.Duration = 200 * time.Millisecond
)
6 changes: 3 additions & 3 deletions backend/database/store/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func NewStores(limiter LimiterInterface, blacklist BlacklistInterface, activeTok

func ConfigureRedis(settings config.Settings) *Stores {
stores := NewStores(
NewLimiter(NewRedisClient(settings.RedisLimiter.Username, settings.RedisLimiter.Host, settings.RedisLimiter.Port, settings.RedisLimiter.Password, settings.RedisLimiter.DB)),
NewBlacklist(NewRedisClient(settings.RedisBlacklist.Username, settings.RedisBlacklist.Host, settings.RedisBlacklist.Port, settings.RedisBlacklist.Password, settings.RedisBlacklist.DB)),
NewActiveToken(NewRedisClient(settings.RedisActiveTokens.Username, settings.RedisActiveTokens.Host, settings.RedisActiveTokens.Port, settings.RedisActiveTokens.Password, settings.RedisActiveTokens.DB)),
NewLimiter(NewRedisClient(settings.RedisLimiter.Username, settings.RedisLimiter.Password, settings.RedisLimiter.Host, settings.RedisLimiter.Port, settings.RedisLimiter.DB)),
NewBlacklist(NewRedisClient(settings.RedisBlacklist.Username, settings.RedisBlacklist.Password, settings.RedisBlacklist.Host, settings.RedisBlacklist.Port, settings.RedisBlacklist.DB)),
NewActiveToken(NewRedisClient(settings.RedisActiveTokens.Username, settings.RedisActiveTokens.Password, settings.RedisActiveTokens.Host, settings.RedisActiveTokens.Port, settings.RedisActiveTokens.DB)),
)

MustEstablishConn()
Expand Down
Loading

0 comments on commit cfe4349

Please sign in to comment.