IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit 0031d72c authored by Douglas Williams's avatar Douglas Williams
Browse files

Merge branch 'release-3' into 'main'

Release 3

See merge request !4
parents c831cb49 08341828
......@@ -4,6 +4,8 @@ tempkey.rsa
ClrConsumer.db
ClrEditor.db
ClrWallet.db
*.bak
**/wwwroot/bundles
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
......
using Microsoft.AspNetCore.Http;
using OpenCredentialPublisher.ClrLibrary.Extensions;
using OpenCredentialPublisher.ClrLibrary.Models;
using OpenCredentialPublisher.Data.Constants;
using OpenCredentialPublisher.Data.Contexts;
using OpenCredentialPublisher.Data.Utils;
using OpenCredentialPublisher.Services.Implementations;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace DataUtility
{
public class DataTasks
{
private readonly WalletDbContext _context;
private readonly SchemaService _schemaService;
private readonly Serilog.ILogger _logger = Log.ForContext<ETLService>();
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly CredentialService _credentialService;
public DataTasks(SchemaService schemaService, WalletDbContext context, IHttpContextAccessor httpContextAccessor, CredentialService credentialService)
{
_httpContextAccessor = httpContextAccessor;
_schemaService = schemaService;
_context = context;
_credentialService = credentialService;
}
public async Task PopulateAssertionNamesAsync()
{
var assertions = await _credentialService.GetAssertionsAsync();
foreach (var assertion in assertions)
{
ConsoleUtil.ConsoleWrite($"Extracting Assertion: {assertion.Id}...", Configuration.ConsoleColors.InProgress);
var assertionDType = JsonSerializer.Deserialize<AssertionDType>(assertion.Json);
assertion.DisplayName = assertionDType.Achievement?.HumanCode == null ? assertionDType.Achievement?.Name : $"{assertionDType.Achievement?.HumanCode}:{assertionDType.Achievement?.Name}";
await _context.SaveChangesAsync();
}
}
public async Task ExtractAssertionsAsync()
{
var pkgIds = await _credentialService.GetPackageUniverseIdsAsync();
var assertions = await _credentialService.GetAssertionsWithClrAsync();
foreach (var assertion in assertions)
{
ConsoleUtil.ConsoleWrite($"Extracting CLR: {assertion.ClrAssertion.ClrId}...", Configuration.ConsoleColors.InProgress);
var clr = JsonSerializer.Deserialize<ClrDType>(assertion.ClrAssertion.Clr.Json);
var allAssertions = new List<MiniAssertion>();
if (clr.SignedAssertions != null)
{
allAssertions.AddRange(clr.SignedAssertions.Select(a =>
{
var assertion = a.DeserializePayload<AssertionDType>();
return MiniAssertion.FromDType(assertion, assertion.ToJson(), a);
}));
}
if (clr.Assertions != null)
{
allAssertions.AddRange(clr.Assertions.ConvertAll(a => MiniAssertion.FromDType(a, a.ToJson())));
}
var found = allAssertions.FirstOrDefault(aa => aa.Id == assertion.Id);
if (found != null)
{
assertion.Json = (found).Json;
assertion.IsSigned = found.IsSigned;
assertion.SignedAssertion = found.SignedAssertion;
}
await _context.SaveChangesAsync();
}
}
}
internal class MiniAssertion
{
internal string Id { get; set; }
internal string SignedAssertion { get; set; }
internal bool IsSigned { get; set; }
internal string Json { get; set; }
internal static MiniAssertion FromDType(AssertionDType asrt, string json, string signedAssertion = null)
{
return new MiniAssertion
{
Id = asrt.Id,
SignedAssertion = signedAssertion,
Json = json,
IsSigned = signedAssertion != null
};
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>8e078e5b-41c9-47a5-b0b3-bf283c4674c4</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenCredentialPublisher.Services\OpenCredentialPublisher.Services.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
namespace DataUtility
{
public static class Extensions
{
// Step 1: Inject smuggler when building web host
public static IWebHostBuilder SniffRouteData(this IWebHostBuilder builder)
{
return builder.ConfigureServices(svc => svc.AddSingleton<Capture>());
}
// Step 2: Swipe the route data in application startup
public static IApplicationBuilder UseMvcAndSniffRoutes(this IApplicationBuilder app)
{
var capture = app.ApplicationServices.GetRequiredService<Capture>();
IRouteBuilder capturedRoutes = null;
app.UseMvc(routeBuilder => capturedRoutes = routeBuilder);
capture.Router = capturedRoutes?.Build();
return app;
}
// Step 3: Build the UrlHelper using the captured routes and webhost
public static IUrlHelper GetStaticUrlHelper(this IWebHost host, string baseUri)
=> GetStaticUrlHelper(host, new Uri(baseUri));
public static IUrlHelper GetStaticUrlHelper(this IWebHost host, Uri baseUri)
{
HttpContext httpContext = new DefaultHttpContext()
{
RequestServices = host.Services,
Request =
{
Scheme = baseUri.Scheme,
Host = HostString.FromUriComponent(baseUri),
PathBase = PathString.FromUriComponent(baseUri),
},
};
var captured = host.Services.GetRequiredService<Capture>();
var actionContext = new ActionContext
{
HttpContext = httpContext,
RouteData = new RouteData { Routers = { captured.Router }},
ActionDescriptor = new ActionDescriptor(),
};
return new UrlHelper(actionContext);
}
}
public class Capture
{
public IRouter Router { get; set; }
}
}
\ No newline at end of file
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OpenCredentialPublisher.ClrLibrary.Extensions;
using OpenCredentialPublisher.ClrLibrary.Models;
using OpenCredentialPublisher.Data.Constants;
using OpenCredentialPublisher.Data.Contexts;
using OpenCredentialPublisher.Data.Models.ClrEntities.Relationships;
using OpenCredentialPublisher.Data.Options;
using OpenCredentialPublisher.Data.Utils;
using OpenCredentialPublisher.Services.Implementations;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Threading.Tasks;
namespace DataUtility
{
class Program
{
private static bool _keepGoing = true;
private static string env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
private static IConfiguration _config;
private static ServiceProvider _provider;
private static CredentialService _credentialService;
private static ETLService _etlService;
private static SchemaService _schemaService;
private static WalletDbContext _context;
private static DataTasks _dataTasks;
private static IUrlHelper _urlHelper;
public static async Task Main(string[] args)
{
/********************************************************************************************************************
* This app extracts all legacy CLR Assertions & persists them in the database to facilitate the first interim
* version of the access optimized data structure. Uses secrets file for db connection
* for use after Migration - 20210618202418_AngularConversion.cs
********************************************************************************************************************/
ConsoleUtil.ConsoleLine(MethodBase.GetCurrentMethod().DeclaringType.Namespace, Configuration.ConsoleColors.Name);
ServiceCollection services = new ServiceCollection();
//This is used only for creating the mvc UrlHelper required by the CredentialService/SchemaService
BuildWebHost(args);
Init(services);
#region OldDataTasks
/*
//2021-07-20ish
await _dataTasks.ExtractAssertionsAsync();
*/
#endregion
//2021-08-04
await _dataTasks.PopulateAssertionNamesAsync();
ConsoleUtil.ConsoleLine($"Completed Execution!", Configuration.ConsoleColors.Success);
}
private static void Init(IServiceCollection services)
{
_config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false, true)
.AddEnvironmentVariables()
.AddUserSecrets<Program>()
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(_config)
.MinimumLevel.Error()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Error)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate)
.CreateLogger();
Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
var keyVaultSection = _config.GetSection(nameof(KeyVaultOptions));
services.Configure<KeyVaultOptions>(keyVaultSection);
var keyVaultOptions = keyVaultSection.Get<KeyVaultOptions>();
// Add access to generic IConfiguration
services.AddSingleton(_config);
services.AddSingleton(_urlHelper);
services.AddHttpContextAccessor();
services.AddTransient<SchemaService>();
services.AddTransient<ETLService>();
services.AddTransient<CredentialService>();
services.AddTransient<DataTasks>();
var connectionString = _config.GetConnectionString("DefaultConnection");
var migrationsAssembly = typeof(WalletDbContext).Assembly.GetName().Name;
services.AddDbContext<WalletDbContext>(options =>
{
options.UseSqlServer(connectionString,
sql => {
sql.EnableRetryOnFailure(5);
});
});
_provider = services.BuildServiceProvider();
_schemaService = _provider.GetService<SchemaService>();
_dataTasks = _provider.GetService<DataTasks>();
_schemaService = _provider.GetService<SchemaService>();
_etlService = _provider.GetService<ETLService>();
_credentialService = _provider.GetService<CredentialService>();
_context = _provider.GetService<WalletDbContext>();
}
private static IWebHost BuildWebHost(string[] args)
{
var webhost = WebHost.CreateDefaultBuilder(args)
.SniffRouteData()
.UseStartup<Startup>()
.Build();
_urlHelper = webhost.GetStaticUrlHelper("https://localhost:44392/credentials");
return webhost;
}
}
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace DataUtility
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Capture capture)
{
app.UseMvcAndSniffRoutes();
}
}
}
\ No newline at end of file
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:9000"
},
"Https": {
"Url": "https://*:9001"
}
}
},
"IdentityServer": {
"Key": {
"Type": "Store",
"StoreName": "My",
"StoreLocation": "CurrentUser",
"Name": "CN=ocp-wallet-dev.azurewebsites.net"
}
},
"HostSettings": {
"DnsName": "ocp-wallet-dev.azurewebsites.net"
},
"SchemaLocation": "/schema/json",
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
\ No newline at end of file
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:9000"
},
"Https": {
"Url": "https://*:9001"
}
}
},
"HostSettings": {
"DnsName": "ocp-wallet-dev.azurewebsites.net"
},
"SchemaLocation": "/schema/json",
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:9000"
},
"Https": {
"Url": "https://*:9001"
}
}
},
"HostSettings": {
"DnsName": "localhost"
},
"MailSettings": {
"RedirectToInternal": true
}
}
\ No newline at end of file
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:9000"
},
"Https": {
"Url": "https://*:9001"
}
}
},
"HostSettings": {
"DnsName": "ocp-wallet-qa.azurewebsites.net"
},
"MailSettings": {
"RedirectToInternal": false
}
}
\ No newline at end of file
{
"AllowedHosts": "*",
"HostSettings": {
"ClientName": "Open Credential Publisher"
},
"IdentityServer": {
"Key": {
"Type": "Development",
"Name": "CN=localhost"
}
},
"Logging": {
"LogLevel": {
"Default": "Critical",
"System.Net.Http.HttpClient": "Critical"
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.MSSqlServer" ],
"WriteTo": [
{ "Name": "Console" },
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "DefaultConnection",
"tableName": "Logs",
"autoCreateSqlTable": true
}
}
]
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>d0033e80-5266-469f-96fc-29f3ff821491</UserSecretsId>
<Configurations>Debug;Dev;Qa;Release;IIS</Configurations>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.AzureDev.json" />
<None Remove="appsettings.Development.json" />
<None Remove="appsettings.json" />
<None Remove="appsettings.Localhost.json" />
<None Remove="appsettings.QA.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.AzureDev.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.Localhost.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.QA.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenCredentialPublisher.Services\OpenCredentialPublisher.Services.csproj" />
</ItemGroup>
</Project>
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
namespace ClrAssertionExtractor
{
public static class Extensions
{
// Step 1: Inject smuggler when building web host
public static IWebHostBuilder SniffRouteData(this IWebHostBuilder builder)
{
return builder.ConfigureServices(svc => svc.AddSingleton<Capture>());
}
// Step 2: Swipe the route data in application startup
public static IApplicationBuilder UseMvcAndSniffRoutes(this IApplicationBuilder app)
{
var capture = app.ApplicationServices.GetRequiredService<Capture>();
IRouteBuilder capturedRoutes = null;
app.UseMvc(routeBuilder => capturedRoutes = routeBuilder);
capture.Router = capturedRoutes?.Build();
return app;
}
// Step 3: Build the UrlHelper using the captured routes and webhost
public static IUrlHelper GetStaticUrlHelper(this IWebHost host, string baseUri)
=> GetStaticUrlHelper(host, new Uri(baseUri));
public static IUrlHelper GetStaticUrlHelper(this IWebHost host, Uri baseUri)
{
HttpContext httpContext = new DefaultHttpContext()
{
RequestServices = host.Services,
Request =
{
Scheme = baseUri.Scheme,
Host = HostString.FromUriComponent(baseUri),
PathBase = PathString.FromUriComponent(baseUri),
},
};
var captured = host.Services.GetRequiredService<Capture>();
var actionContext = new ActionContext
{
HttpContext = httpContext,
RouteData = new RouteData { Routers = { captured.Router }},
ActionDescriptor = new ActionDescriptor(),
};
return new UrlHelper(actionContext);
}
}
public class Capture
{
public IRouter Router { get; set; }
}
}
\ No newline at end of file