Skip to content

Commit

Permalink
variety of fixes | comment out broken redis
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Jun 1, 2024
1 parent 45dcbd6 commit 34b6aa8
Show file tree
Hide file tree
Showing 33 changed files with 481 additions and 282 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
6 changes: 3 additions & 3 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ func GetConfiguration(path string) (*Settings, error) {
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())
}

return intermediateSettings.into()
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 `envPrefix:"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
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
2 changes: 1 addition & 1 deletion backend/database/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RedisClient struct {
client *redis.Client
}

func NewRedisClient(username, host string, port uint, password *m.Secret[string], db int) *RedisClient {
func NewRedisClient(username string, password *m.Secret[string], host string, port uint, db int) *RedisClient {
client := redis.NewClient(&redis.Options{
Username: username,
Addr: fmt.Sprintf("%s:%d", host, port),
Expand Down
13 changes: 1 addition & 12 deletions backend/database/super.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ func SuperClub() models.Club {
Preview: "SAC",
Description: "SAC",
NumMembers: 0,
Recruitment: models.Recruitment{
Cycle: models.Always,
Type: models.RecruitmentTypeApplication,
IsRecruiting: true,
Application: []models.Application{
{
Title: "General Applications",
Link: "generatenu.com/apply",
},
},
},
Logo: "https://aws.amazon.com/s3",
Logo: "https://aws.amazon.com/s3",
}
}
41 changes: 41 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,48 @@ services:
volumes:
- redis-limiter-data:/data

opensearch-node1:
image: opensearchproject/opensearch:latest
container_name: opensearch-node1
environment:
- cluster.name=opensearch-cluster
- node.name=opensearch-node1
- discovery.type=single-node
- bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
- DISABLE_SECURITY_PLUGIN=true #
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
hard: 65536
volumes:
- opensearch-data1:/usr/share/opensearch/data
ports:
- 9200:9200
- 9600:9600 # required for Performance Analyzer
networks:
- opensearch-net
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:latest
container_name: opensearch-dashboards
ports:
- 5601:5601
expose:
- "5601"
environment:
OPENSEARCH_HOSTS: '["http://opensearch-node1:9200"]'
DISABLE_SECURITY_DASHBOARDS_PLUGIN: true
networks:
- opensearch-net

volumes:
redis-active-data:
redis-blacklist-data:
redis-limiter-data:
opensearch-data1:

networks:
opensearch-net:
Loading

0 comments on commit 34b6aa8

Please sign in to comment.