34 lines
989 B
C#
34 lines
989 B
C#
using Microsoft.Data.Sqlite;
|
|
using Microsoft.Extensions.Options;
|
|
using MxGateway.Server.Configuration;
|
|
|
|
namespace MxGateway.Server.Security.Authentication;
|
|
|
|
/// <summary>
|
|
/// Factory for creating SQLite connections to the authentication store.
|
|
/// </summary>
|
|
public sealed class AuthSqliteConnectionFactory(IOptions<GatewayOptions> options)
|
|
{
|
|
/// <summary>
|
|
/// Creates and configures a SQLite connection to the auth database.
|
|
/// </summary>
|
|
public SqliteConnection CreateConnection()
|
|
{
|
|
string sqlitePath = options.Value.Authentication.SqlitePath;
|
|
string? directory = Path.GetDirectoryName(sqlitePath);
|
|
|
|
if (!string.IsNullOrWhiteSpace(directory))
|
|
{
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
SqliteConnectionStringBuilder builder = new()
|
|
{
|
|
DataSource = sqlitePath,
|
|
Mode = SqliteOpenMode.ReadWriteCreate
|
|
};
|
|
|
|
return new SqliteConnection(builder.ToString());
|
|
}
|
|
}
|