-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathPostgresCredentials.cs
More file actions
35 lines (31 loc) · 1.28 KB
/
PostgresCredentials.cs
File metadata and controls
35 lines (31 loc) · 1.28 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
using Npgsql;
using System;
using System.IO;
namespace Medallion.Threading.Tests;
internal static class PostgresCredentials
{
private static (string username, string password) GetCredentials(string baseDirectory)
{
var file = Path.GetFullPath(Path.Combine(baseDirectory, "..", "..", "..", "credentials", "postgres.txt"));
if (!File.Exists(file)) { throw new InvalidOperationException($"Unable to find postgres credentials file {file}"); }
var lines = File.ReadAllLines(file);
if (lines.Length != 2) { throw new FormatException($"{file} must contain exactly 2 lines of text"); }
return (lines[0], lines[1]);
}
public static string GetConnectionString(string baseDirectory)
{
var (username, password) = GetCredentials(baseDirectory);
return new NpgsqlConnectionStringBuilder
{
Port = 5432,
Host = "localhost",
Database = "postgres",
Username = username,
Password = password,
PersistSecurityInfo = true,
ApplicationName = SqlServerCredentials.ApplicationName,
// set a high pool size so that we don't empty the pool through things like lock abandonment tests
MaxPoolSize = 500,
}.ConnectionString;
}
}