-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathPostgresEnvironment.cs
More file actions
66 lines (45 loc) · 2.75 KB
/
PostgresEnvironment.cs
File metadata and controls
66 lines (45 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Npgsql;
static class PostgresEnvironment
{
internal static string? User => Environment.GetEnvironmentVariable("PGUSER");
internal static string? Password => Environment.GetEnvironmentVariable("PGPASSWORD");
internal static string? PassFile => Environment.GetEnvironmentVariable("PGPASSFILE");
internal static string? PassFileDefault
=> (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? GetHomePostgresDir() : GetHomeDir()) is string homedir &&
Path.Combine(homedir, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "pgpass.conf" : ".pgpass") is var path &&
File.Exists(path)
? path
: null;
internal static string? SslCert => Environment.GetEnvironmentVariable("PGSSLCERT");
internal static string? SslCertDefault
=> GetHomePostgresDir() is string homedir && Path.Combine(homedir, "postgresql.crt") is var path && File.Exists(path)
? path
: null;
internal static string? SslKey => Environment.GetEnvironmentVariable("PGSSLKEY");
internal static string? SslKeyDefault
=> GetHomePostgresDir() is string homedir && Path.Combine(homedir, "postgresql.key") is var path && File.Exists(path)
? path
: null;
internal static string? SslCertRoot => Environment.GetEnvironmentVariable("PGSSLROOTCERT");
internal static string? SslCertRootDefault
=> GetHomePostgresDir() is string homedir && Path.Combine(homedir, "root.crt") is var path && File.Exists(path)
? path
: null;
internal static string? ClientEncoding => Environment.GetEnvironmentVariable("PGCLIENTENCODING");
internal static string? TimeZone => Environment.GetEnvironmentVariable("PGTZ");
internal static string? Options => Environment.GetEnvironmentVariable("PGOPTIONS");
internal static string? TargetSessionAttributes => Environment.GetEnvironmentVariable("PGTARGETSESSIONATTRS");
internal static string? SslNegotiation => Environment.GetEnvironmentVariable("PGSSLNEGOTIATION");
internal static string? GssEncryptionMode => Environment.GetEnvironmentVariable("PGGSSENCMODE");
internal static string? RequireAuth => Environment.GetEnvironmentVariable("PGREQUIREAUTH");
internal static string? AppName => Environment.GetEnvironmentVariable("PGAPPNAME");
static string? GetHomeDir()
=> Environment.GetEnvironmentVariable(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "APPDATA" : "HOME");
static string? GetHomePostgresDir()
=> GetHomeDir() is string homedir
? Path.Combine(homedir, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "postgresql" : ".postgresql")
: null;
}