diff --git a/deployment/helm/templates/deployment.yaml b/deployment/helm/templates/deployment.yaml index ee3d406630d100a0743c8df9e74ec250b5889e44..bfd0b3842eb48f88f9840b3bd2a1aaea0b7582fd 100644 --- a/deployment/helm/templates/deployment.yaml +++ b/deployment/helm/templates/deployment.yaml @@ -35,6 +35,12 @@ spec: volumeMounts: - mountPath: /app name: config-volume + env: + - name: STATUSLIST_DATABASE_PASSWORD + valueFrom: + secretKeyRef: + name: "{{- .Release.Name }}-postgresql" + key: postgres-password {{- if .Values.resources }} resources: {{ toYaml .Values.resources | indent 10 }} diff --git a/deployment/helm/values.yaml b/deployment/helm/values.yaml index 0045834f6e227d070ab1d03825d34a2adfd60c0c..c79353dbafb9e9af363cce566e8d2b3d2d8ad65f 100644 --- a/deployment/helm/values.yaml +++ b/deployment/helm/values.yaml @@ -33,6 +33,16 @@ config: timeoutInSec: 10 queueGroup: statuslistservice servingPort: 8083 - databaseUrl: postgres://user:pass@localhost:5432/status + database: + username: user + password: pass + host: localhost + port: 5432 + db: status creationTopic: status - blockSizeInBytes: 125000 \ No newline at end of file + blockSizeInBytes: 125000 + +postgresql: + auth: + username: user + database: status diff --git a/internal/config/config.go b/internal/config/config.go index dfa6094a8a4a54c03fdc9368b624517cebce7bf6..7fd339bdd4063a3ed10448cae89d58c60d28820b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,9 +8,15 @@ import ( ) type statusListConfiguration struct { - LogLevel string `mapstructure:"logLevel"` - Port int `mapstructure:"servingPort"` - DatabaseUrl string `mapstructure:"databaseUrl"` + LogLevel string `mapstructure:"logLevel"` + Port int `mapstructure:"servingPort"` + Database struct { + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + Host string `mapstructure:"host"` + Port int `mapstructure:"port"` + Db string `mapstructure:"db"` + } `mapstructure:"database"` CreationTopic string `mapstructure:"creationTopic"` BlockSizeInBytes int `mapstructure:"blockSizeInBytes"` } diff --git a/internal/database/database.go b/internal/database/database.go index 2487a9634d37e7f26196363697b715e24fe33afa..15a0aafe6e2ee7b01a8573c3a674c00e8ffed7e9 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -19,7 +19,7 @@ type Database struct { DbConnection } -func New(databaseUrl string, blockSizeInBytes int) (*Database, error) { - dbConnection, err := newPostgresConnection(databaseUrl, blockSizeInBytes) +func New(username string, password string, host string, port int, db string, blockSizeInBytes int) (*Database, error) { + dbConnection, err := newPostgresConnection(username, password, host, port, db, blockSizeInBytes) return &Database{DbConnection: dbConnection}, err } diff --git a/internal/database/postgres.go b/internal/database/postgres.go index 07699117876e20f1eb416997d6c941eb52ace668..30baa13299bc654b434224f2dc2c7e7c6c63b723 100644 --- a/internal/database/postgres.go +++ b/internal/database/postgres.go @@ -17,8 +17,9 @@ type postgresConnection struct { blockSizeInBytes int } -func newPostgresConnection(url string, blockSizeInBytes int) (DbConnection, error) { - conn, err := pgxpool.New(context.Background(), url) +func newPostgresConnection(username string, password string, host string, port int, db string, blockSizeInBytes int) (DbConnection, error) { + connUrl := fmt.Sprintf("postgres://%s:%s@%s:%d/%s", username, password, host, port, db) + conn, err := pgxpool.New(context.Background(), connUrl) if err != nil { return nil, err } diff --git a/main.go b/main.go index 4e80e13a41705aba442665570ca003b1db257986..6fca49a2cd915a11946650926af0095a824ceeb1 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,15 @@ func main() { } currentConf := &config.CurrentStatusListConfig - db, err := database.New(currentConf.DatabaseUrl, currentConf.BlockSizeInBytes) + dbConf := ¤tConf.Database + db, err := database.New( + dbConf.Username, + dbConf.Password, + dbConf.Host, + dbConf.Port, + dbConf.Db, + currentConf.BlockSizeInBytes, + ) if err != nil { log.Error(err) }