Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for Sqlite #994

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Skuruba.IdentityServer4.STS.Identity (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Skoruba.IdentityServer4.STS.Identity/bin/Debug/net6.0/Skoruba.IdentityServer4.STS.Identity.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": "Skoruba.IdentityServer4.Admin.Api (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Skoruba.IdentityServer4.Admin.Api/bin/Debug/net6.0/Skoruba.IdentityServer4.Admin.Api.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": "Skoruba.IdentityServer4.Admin (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}//src/Skoruba.IdentityServer4.Admin/bin/Debug/net6.0/Skoruba.IdentityServer4.Admin.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true
}
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary",
"Skoruba.IdentityServer4.Admin.sln"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
13 changes: 10 additions & 3 deletions Skoruba.IdentityServer4.Admin.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.452
# Visual Studio Version 17
VisualStudioVersion = 17.3.32519.111
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "admin", "admin", "{588205D4-3A30-4DA4-849D-C7422C396DAA}"
EndProject
Expand Down Expand Up @@ -55,7 +55,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skoruba.IdentityServer4.Adm
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skoruba.IdentityServer4.Admin.EntityFramework.Configuration", "src\Skoruba.IdentityServer4.Admin.EntityFramework.Configuration\Skoruba.IdentityServer4.Admin.EntityFramework.Configuration.csproj", "{45FB23BE-A7F9-4172-8868-B5E387007644}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skoruba.IdentityServer4.Shared.Configuration", "src\Skoruba.IdentityServer4.Shared.Configuration\Skoruba.IdentityServer4.Shared.Configuration.csproj", "{D49A2D61-AEEB-457C-B3BA-D1322EB2F4EC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skoruba.IdentityServer4.Shared.Configuration", "src\Skoruba.IdentityServer4.Shared.Configuration\Skoruba.IdentityServer4.Shared.Configuration.csproj", "{D49A2D61-AEEB-457C-B3BA-D1322EB2F4EC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Skoruba.IdentityServer4.Admin.EntityFramework.Sqlite", "src\Skoruba.IdentityServer4.Admin.EntityFramework.Sqlite\Skoruba.IdentityServer4.Admin.EntityFramework.Sqlite.csproj", "{EDFB9D5A-BF86-4C0F-A91C-0E443FEC9A72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -151,6 +153,10 @@ Global
{D49A2D61-AEEB-457C-B3BA-D1322EB2F4EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D49A2D61-AEEB-457C-B3BA-D1322EB2F4EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D49A2D61-AEEB-457C-B3BA-D1322EB2F4EC}.Release|Any CPU.Build.0 = Release|Any CPU
{EDFB9D5A-BF86-4C0F-A91C-0E443FEC9A72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDFB9D5A-BF86-4C0F-A91C-0E443FEC9A72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDFB9D5A-BF86-4C0F-A91C-0E443FEC9A72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDFB9D5A-BF86-4C0F-A91C-0E443FEC9A72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -177,6 +183,7 @@ Global
{6DD24C2C-0FB5-4C37-8B42-5DACA0FDE4EC} = {588205D4-3A30-4DA4-849D-C7422C396DAA}
{45FB23BE-A7F9-4172-8868-B5E387007644} = {2A514C8F-6A53-41CA-AB41-B644E7BC92A7}
{D49A2D61-AEEB-457C-B3BA-D1322EB2F4EC} = {EE588CE5-51D0-4E98-A2B3-40EC8E655931}
{EDFB9D5A-BF86-4C0F-A91C-0E443FEC9A72} = {2A514C8F-6A53-41CA-AB41-B644E7BC92A7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B3166EDE-037B-4C68-BEBA-5DE9C5E3DB82}
Expand Down
15 changes: 15 additions & 0 deletions src/Skoruba.IdentityServer4.Admin.Api/Helpers/StartupHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
using Skoruba.IdentityServer4.Admin.EntityFramework.Configuration.Configuration;
using Skoruba.IdentityServer4.Admin.EntityFramework.Configuration.MySql;
using Skoruba.IdentityServer4.Admin.EntityFramework.Configuration.PostgreSQL;
using Skoruba.IdentityServer4.Admin.EntityFramework.Configuration.Sqlite;
using Skoruba.IdentityServer4.Admin.EntityFramework.Configuration.SqlServer;
using Skoruba.IdentityServer4.Admin.EntityFramework.Helpers;
using Skoruba.IdentityServer4.Admin.EntityFramework.Interfaces;

using Skoruba.IdentityServer4.Admin.EntityFramework.Sqlite.Helpers;

namespace Skoruba.IdentityServer4.Admin.Api.Helpers
{
public static class StartupHelpers
Expand Down Expand Up @@ -159,6 +162,9 @@ public static IServiceCollection AddAdminApiCors(this IServiceCollection service
case DatabaseProviderType.MySql:
services.RegisterMySqlDbContexts<TIdentityDbContext, TConfigurationDbContext, TPersistedGrantDbContext, TLogDbContext, TAuditLoggingDbContext, TDataProtectionDbContext, TAuditLog>(connectionStrings, databaseMigrations);
break;
case DatabaseProviderType.Sqlite:
services.RegisterSqliteDbContexts<TIdentityDbContext, TConfigurationDbContext, TPersistedGrantDbContext, TLogDbContext, TAuditLoggingDbContext, TDataProtectionDbContext, TAuditLog>(connectionStrings, databaseMigrations);
break;
default:
throw new ArgumentOutOfRangeException(nameof(databaseProvider.ProviderType), $@"The value needs to be one of {string.Join(", ", Enum.GetNames(typeof(DatabaseProviderType)))}.");
}
Expand Down Expand Up @@ -335,6 +341,15 @@ public static void AddIdSHealthChecks<TConfigurationDbContext, TPersistedGrantDb
.AddMySql(auditLogDbConnectionString, name: "AuditLogDb")
.AddMySql(dataProtectionDbConnectionString, name: "DataProtectionDb");
break;
case DatabaseProviderType.Sqlite:
healthChecksBuilder
.AddSqlite(configurationDbConnectionString, name: "ConfigurationDb")
.AddSqlite(persistedGrantsDbConnectionString, name: "PersistentGrantsDb")
.AddSqlite(identityDbConnectionString, name: "IdentityDb")
.AddSqlite(logDbConnectionString, name: "LogDb")
.AddSqlite(auditLogDbConnectionString, name: "AuditLogDb")
.AddSqlite(dataProtectionDbConnectionString, name: "DataProtectionDb");
break;
default:
throw new NotImplementedException($"Health checks not defined for database provider {databaseProvider.ProviderType}");
}
Expand Down
34 changes: 25 additions & 9 deletions src/Skoruba.IdentityServer4.Admin.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
Expand All @@ -14,9 +15,16 @@ public static void Main(string[] args)
{
var configuration = GetConfiguration(args);

Log.Logger = new LoggerConfiguration()
Log.Logger = (new LoggerConfiguration())
.ReadFrom.Configuration(configuration)
.CreateLogger();

foreach (var file in configuration.AsEnumerable())
{
Log.Debug("************* " + file.Key + "************* " + file.Value);
}


try
{
DockerHelpers.ApplyDockerConfiguration(configuration);
Expand All @@ -37,13 +45,16 @@ private static IConfiguration GetConfiguration(string[] args)
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var isDevelopment = environment == Environments.Development;
var exeLocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);


var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.SetBasePath(exeLocation + "/")
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
.AddJsonFile("serilog.json", optional: true, reloadOnChange: true)
.AddJsonFile($"serilog.{environment}.json", optional: true, reloadOnChange: true);
.AddJsonFile($"serilog.{environment}.json", optional: true, reloadOnChange: true)
;

if (isDevelopment)
{
Expand All @@ -52,12 +63,14 @@ private static IConfiguration GetConfiguration(string[] args)

var configuration = configurationBuilder.Build();



configuration.AddAzureKeyVaultConfiguration(configurationBuilder);

configurationBuilder.AddCommandLine(args);
configurationBuilder.AddEnvironmentVariables();

return configurationBuilder.Build();
return configuration;
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Expand All @@ -66,13 +79,16 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
{
var configurationRoot = configApp.Build();

configApp.AddJsonFile("serilog.json", optional: true, reloadOnChange: true);

var env = hostContext.HostingEnvironment;
var environment = hostContext.HostingEnvironment;
var exeLocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

configApp.AddJsonFile($"serilog.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
configApp.SetBasePath(exeLocation + "/")
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddJsonFile("serilog.json", optional: true, reloadOnChange: true)
.AddJsonFile($"serilog.{environment.EnvironmentName}.json", optional: true, reloadOnChange: true);

if (env.IsDevelopment())
if (environment.IsDevelopment())
{
configApp.AddUserSecrets<Startup>(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="6.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Sqlite" Version="6.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="6.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.OpenIdConnectServer" Version="6.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.1" />
Expand Down Expand Up @@ -47,6 +48,7 @@
<ProjectReference Include="..\Skoruba.IdentityServer4.Admin.BusinessLogic\Skoruba.IdentityServer4.Admin.BusinessLogic.csproj" />
<ProjectReference Include="..\Skoruba.IdentityServer4.Admin.EntityFramework.MySql\Skoruba.IdentityServer4.Admin.EntityFramework.MySql.csproj" />
<ProjectReference Include="..\Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL\Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL.csproj" />
<ProjectReference Include="..\Skoruba.IdentityServer4.Admin.EntityFramework.Sqlite\Skoruba.IdentityServer4.Admin.EntityFramework.Sqlite.csproj" />
<ProjectReference Include="..\Skoruba.IdentityServer4.Admin.EntityFramework.SqlServer\Skoruba.IdentityServer4.Admin.EntityFramework.SqlServer.csproj" />
<ProjectReference Include="..\Skoruba.IdentityServer4.Shared.Configuration\Skoruba.IdentityServer4.Shared.Configuration.csproj" />
<ProjectReference Include="..\Skoruba.IdentityServer4.Shared\Skoruba.IdentityServer4.Shared.csproj" />
Expand Down
16 changes: 14 additions & 2 deletions src/Skoruba.IdentityServer4.Admin.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

namespace Skoruba.IdentityServer4.Admin.Api
{
public class Ab{
public string A{get;set;}
public string B{get;set;}
}
public class Startup
{
public Startup(IWebHostEnvironment env, IConfiguration configuration)
Expand All @@ -39,10 +43,18 @@ public Startup(IWebHostEnvironment env, IConfiguration configuration)

public void ConfigureServices(IServiceCollection services)
{
var adminApiConfiguration = Configuration.GetSection(nameof(AdminApiConfiguration)).Get<AdminApiConfiguration>();

var serilog = Configuration.GetSection("Serilog:MinimumLevel");


var section = Configuration.GetSection(nameof(AdminApiConfiguration));

AdminApiConfiguration adminApiConfiguration = section.Get<AdminApiConfiguration>();


services.AddSingleton(adminApiConfiguration);

// Add DbContexts
// Add DbContextsvar section =
RegisterDbContexts(services);

services.AddDataProtection<IdentityServerDataProtectionDbContext>(Configuration);
Expand Down
Loading