mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-23 17:52:36 -04:00
Support standard libpq environment variables for the Backend service
Signed-off-by: Fred Heinecke <fred.heinecke@yahoo.com>
This commit is contained in:
parent
5ced62aab3
commit
94fe79bcd1
@ -3,3 +3,18 @@
|
||||
|
||||
# http route prefix (will listen to $KYOO_PREFIX/movie for example)
|
||||
KYOO_PREFIX=""
|
||||
|
||||
# POSTGRES_URL=postgres://user:password@hostname:port/dbname?sslmode=verify-full&sslrootcert=/path/to/server.crt&sslcert=/path/to/client.crt&sslkey=/path/to/client.key
|
||||
# The behavior of the below variables match what is documented here:
|
||||
# https://www.postgresql.org/docs/current/libpq-envars.html
|
||||
PGUSER=kyoo
|
||||
PGPASSWORD=password
|
||||
PGDB=kyooDB
|
||||
PGSERVER=postgres
|
||||
PGPORT=5432
|
||||
# PGOPTIONS=-c search_path=kyoo,public
|
||||
# PGPASSFILE=/my/password # Takes precedence over PGPASSWORD. New line characters are not trimmed.
|
||||
# PGSSLMODE=verify-full
|
||||
# PGSSLROOTCERT=/my/serving.crt
|
||||
# PGSSLCERT=/my/client.crt
|
||||
# PGSSLKEY=/my/client.key
|
||||
|
@ -33,19 +33,46 @@ public static class PostgresModule
|
||||
{
|
||||
public static NpgsqlDataSource CreateDataSource(IConfiguration configuration)
|
||||
{
|
||||
DbConnectionStringBuilder conBuilder =
|
||||
new()
|
||||
// Load the connection string from the environment variable, as well as standard libpq environment variables
|
||||
// (PGUSER, PGPASSWORD, PGHOST, PGPORT, PGDATABASE, etc.)
|
||||
NpgsqlConnectionStringBuilder conBuilder =
|
||||
new(configuration.GetValue<string>("POSTGRES_URL") ?? "")
|
||||
{
|
||||
["USER ID"] = configuration.GetValue("POSTGRES_USER", "KyooUser"),
|
||||
["PASSWORD"] = configuration.GetValue("POSTGRES_PASSWORD", "KyooPassword"),
|
||||
["SERVER"] = configuration.GetValue("POSTGRES_SERVER", "postgres"),
|
||||
["PORT"] = configuration.GetValue("POSTGRES_PORT", "5432"),
|
||||
["DATABASE"] = configuration.GetValue("POSTGRES_DB", "kyooDB"),
|
||||
["POOLING"] = "true",
|
||||
["MAXPOOLSIZE"] = "95",
|
||||
["TIMEOUT"] = "30"
|
||||
Pooling = true,
|
||||
MaxPoolSize = 95,
|
||||
Timeout = 30
|
||||
};
|
||||
|
||||
string? oldVarUsername = configuration.GetValue<string>("POSTGRES_USER");
|
||||
if (!string.IsNullOrEmpty(oldVarUsername))
|
||||
conBuilder.Username = oldVarUsername;
|
||||
if (string.IsNullOrEmpty(conBuilder.Username))
|
||||
conBuilder.Username = "KyooUser";
|
||||
|
||||
string? oldVarPassword = configuration.GetValue<string>("POSTGRES_PASSWORD");
|
||||
if (!string.IsNullOrEmpty(oldVarPassword))
|
||||
conBuilder.Password = oldVarPassword;
|
||||
if (string.IsNullOrEmpty(conBuilder.Password))
|
||||
conBuilder.Password = "KyooPassword";
|
||||
|
||||
string? oldVarHost = configuration.GetValue<string>("POSTGRES_SERVER");
|
||||
if (!string.IsNullOrEmpty(oldVarHost))
|
||||
conBuilder.Host = oldVarHost;
|
||||
if (string.IsNullOrEmpty(conBuilder.Host))
|
||||
conBuilder.Host = "postgres";
|
||||
|
||||
int? oldVarPort = configuration.GetValue<int>("POSTGRES_PORT");
|
||||
if (oldVarPort != null && oldVarPort != 0)
|
||||
conBuilder.Port = oldVarPort.Value;
|
||||
if (conBuilder.Port == 0)
|
||||
conBuilder.Port = 5432;
|
||||
|
||||
string? oldVarDatabase = configuration.GetValue<string>("POSTGRES_DB");
|
||||
if (!string.IsNullOrEmpty(oldVarDatabase))
|
||||
conBuilder.Database = oldVarDatabase;
|
||||
if (string.IsNullOrEmpty(conBuilder.Database))
|
||||
conBuilder.Database = "kyooDB";
|
||||
|
||||
NpgsqlDataSourceBuilder dsBuilder = new(conBuilder.ConnectionString);
|
||||
dsBuilder.MapEnum<Status>();
|
||||
dsBuilder.MapEnum<Genre>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user