Skip to content

Commit

Permalink
Add Update Song Director API
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhoffmeister committed Feb 9, 2023
1 parent f54ffa5 commit 14f48fe
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 63 deletions.
10 changes: 5 additions & 5 deletions Asaph.Bootstrapper/Asaph.Bootstrapper.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.43.0.51858">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.52.0.60960">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 7 additions & 7 deletions Asaph.Core.UnitTests/Asaph.Core.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand All @@ -11,11 +11,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentResults" Version="3.10.0" />
<PackageReference Include="Microsoft.Graph" Version="4.35.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.43.0.51858">
<PackageReference Include="FluentResults" Version="3.15.2" />
<PackageReference Include="Microsoft.Graph" Version="4.53.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.52.0.60960">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -28,7 +28,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions Asaph.Core/Asaph.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentResults" Version="3.10.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.43.0.51858">
<PackageReference Include="FluentResults" Version="3.15.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.52.0.60960">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,21 +284,21 @@ private static AggregateSongDirectorRepository GetAggregateSongDirectorRepositor
IConfiguration configuration = builder.Build();

AzureAdb2cConfiguration azureAdb2CConfiguration = new(
configuration[$"{userSecretsSection}:AzureAdb2c:ClientId"],
configuration[$"{userSecretsSection}:AzureAdb2c:ClientSecret"],
configuration[$"{userSecretsSection}:AzureAdb2c:Domain"],
configuration[$"{userSecretsSection}:AzureAdb2c:ExtensionsAppClientId"],
configuration[$"{userSecretsSection}:AzureAdb2c:TenantId"]);
configuration[$"{userSecretsSection}:AzureAdb2c:ClientId"]!,
configuration[$"{userSecretsSection}:AzureAdb2c:ClientSecret"]!,
configuration[$"{userSecretsSection}:AzureAdb2c:Domain"]!,
configuration[$"{userSecretsSection}:AzureAdb2c:ExtensionsAppClientId"]!,
configuration[$"{userSecretsSection}:AzureAdb2c:TenantId"]!);

AzureAdb2cSongDirectorRepository azureAdb2CSongDirectorRepository = new(
azureAdb2CConfiguration);

DynamoDBConfiguration dynamoDBConfiguration = new(
configuration[$"{userSecretsSection}:DynamoDB:AwsAccessKeyId"],
configuration[$"{userSecretsSection}:DynamoDB:AwsSecretAccessKey"],
configuration[$"{userSecretsSection}:DynamoDB:AwsAccessKeyId"]!,
configuration[$"{userSecretsSection}:DynamoDB:AwsSecretAccessKey"]!,
awsRegionSystemName,
configuration[$"{userSecretsSection}:DynamoDB:TableNamePrefix"],
configuration[$"{userSecretsSection}:DynamoDB:DynamoDBLocalUrl"],
configuration[$"{userSecretsSection}:DynamoDB:TableNamePrefix"]!,
configuration[$"{userSecretsSection}:DynamoDB:DynamoDBLocalUrl"]!,
useDynamoDBLocal);

DynamoDBSongDirectorRepository amazonDynamoDBSongDirectorRepository = new(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand All @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.43.0.51858">
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.52.0.60960">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -26,7 +26,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ private static AzureAdb2cConfiguration GetConfiguration()
IConfiguration configuration = builder.Build();

return new(
configuration["AzureAdb2c:ClientId"],
configuration["AzureAdb2c:ClientSecret"],
configuration["AzureAdb2c:Domain"],
configuration["AzureAdb2c:ExtensionsAppClientId"],
configuration["AzureAdb2c:TenantId"]);
configuration["AzureAdb2c:ClientId"]!,
configuration["AzureAdb2c:ClientSecret"]!,
configuration["AzureAdb2c:Domain"]!,
configuration["AzureAdb2c:ExtensionsAppClientId"]!,
configuration["AzureAdb2c:TenantId"]!);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ private static DynamoDBConfiguration GetConfiguration(
.AddUserSecrets<DynamoDBSongDirectorRepositoryTests>()
.Build();

string awsAccessKeyId = configuration["DynamoDB:AwsAccessKeyId"];
string awsSecretAccessKey = configuration["DynamoDB:AwsSecretAccessKey"];
string dynamoDBLocalUrl = configuration["DynamoDB:DynamoDBLocalUrl"];
string awsAccessKeyId = configuration["DynamoDB:AwsAccessKeyId"]!;
string awsSecretAccessKey = configuration["DynamoDB:AwsSecretAccessKey"]!;
string dynamoDBLocalUrl = configuration["DynamoDB:DynamoDBLocalUrl"]!;
string tableNamePrefix = "Dev_";

return new(
return new DynamoDBConfiguration(
awsAccessKeyId,
awsSecretAccessKey,
awsRegionSystemName,
Expand All @@ -266,4 +266,4 @@ private static DynamoDBConfiguration GetConfiguration(
useDynamoDBLocal);
}
}
}
}
12 changes: 6 additions & 6 deletions Asaph.Infrastructure/Asaph.Infrastructure.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.3.66" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.101.41" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.2" />
<PackageReference Include="Azure.Identity" Version="1.6.1" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.29.0" />
<PackageReference Include="Microsoft.Graph" Version="4.35.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.43.0.51858">
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.32.0" />
<PackageReference Include="Microsoft.Graph" Version="4.53.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.52.0.60960">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Asaph.Infrastructure.SongDirectorRepository;

public record struct DynamoDBConfiguration(
public record DynamoDBConfiguration(
string AwsAccessKeyId,
string AwsSecretAccessKey,
string AwsRegionSystemName,
Expand Down
28 changes: 24 additions & 4 deletions Asaph.WebApi/ApiDocumentationBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.OpenApi.Models;
using Microsoft.Identity.Web.Resource;
using Microsoft.OpenApi.Models;
using System.Configuration;
using System.Security.Claims;

/// <summary>
Expand Down Expand Up @@ -58,7 +60,9 @@ public static OpenApiDocument GetAsaphOpenApiDocument(
Scopes = swaggerUIConfiguration
.GetSection("Scopes")
.GetChildren()
.ToDictionary(kv => kv.Value, kv => kv.Key),
.Where(section => section.Value != null)
.ToDictionary(
section => section.Value!, section => section.Key),

TokenUrl = GetTokenUrl(azureAdb2cConfiguration),
},
Expand All @@ -76,8 +80,16 @@ public static OpenApiDocument GetAsaphOpenApiDocument(
/// <returns>Authorization URL.</returns>
private static Uri GetAuthorizationUrl(IConfiguration azureAdb2cConfiguration)
{
string? authorizationUrlTemplate = azureAdb2cConfiguration["AuthorizationUrlTemplate"];

if (authorizationUrlTemplate == null)
{
throw new ConfigurationErrorsException(
"Missing Azure AD B2C authorization URL template configuration.");
}

return new(string.Format(
azureAdb2cConfiguration["AuthorizationUrlTemplate"],
authorizationUrlTemplate,
azureAdb2cConfiguration["Instance"],
azureAdb2cConfiguration["Domain"],
azureAdb2cConfiguration["SignUpSignInPolicyId"]));
Expand Down Expand Up @@ -123,8 +135,16 @@ private static List<OpenApiSecurityRequirement> GetOpenApiSecurityRequirements(
/// <returns>Token URL.</returns>
private static Uri GetTokenUrl(IConfiguration azureAdb2cConfiguration)
{
string? tokenUrlTemplate = azureAdb2cConfiguration["TokenUrlTemplate"];

if (tokenUrlTemplate == null)
{
throw new ConfigurationErrorsException(
"Missing Azure AD B2C token URL template configuration.");
}

return new(string.Format(
azureAdb2cConfiguration["TokenUrlTemplate"],
tokenUrlTemplate,
azureAdb2cConfiguration["Instance"],
azureAdb2cConfiguration["Domain"],
azureAdb2cConfiguration["SignUpSignInPolicyId"]));
Expand Down
12 changes: 6 additions & 6 deletions Asaph.WebApi/Asaph.WebApi.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>fc8fb0f9-8023-4345-8aae-7355b736e2ff</UserSecretsId>
Expand All @@ -10,20 +10,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Cloud.SecretManager.V1" Version="2.0.0" />
<PackageReference Include="Google.Cloud.SecretManager.V1" Version="2.1.0" />
<PackageReference Include="Hydra.NET" Version="1.0.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.25.1" />
<PackageReference Include="Microsoft.OpenApi" Version="1.3.2" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.26.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.43.0.51858">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.52.0.60960">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
52 changes: 52 additions & 0 deletions Asaph.WebApi/ForbiddenObjectResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// <summary>
/// Forbidden object result.
/// </summary>
public class ForbiddenObjectResult : IResult
{
/// <summary>
/// Initializes a new instance of the <see cref="ForbiddenObjectResult"/> class.
/// </summary>
/// <param name="value">Value.</param>
/// <param name="contentType">Content type.</param>
public ForbiddenObjectResult(object value, string contentType) =>
(ContentType, Value) = (contentType, value);

/// <summary>
/// Gets the value for the <c>Content-Type</c> header.
/// </summary>
public string ContentType { get; }

/// <summary>
/// The object result.
/// </summary>
public object Value { get; }

/// <inheritdoc/>
public Task ExecuteAsync(HttpContext httpContext)
{
int forbiddenStatusCode = StatusCodes.Status403Forbidden;

Type valueType = Value.GetType();

LogForbiddenObjectResultExecuting(httpContext, valueType);

httpContext.Response.StatusCode = forbiddenStatusCode;

return httpContext.Response.WriteAsJsonAsync(
Value, valueType, options: null, contentType: ContentType);
}

private void LogForbiddenObjectResultExecuting(HttpContext httpContext, Type valueType)
{
ILoggerFactory? loggerFactory = httpContext
.RequestServices
.GetRequiredService<ILoggerFactory>();

ILogger? logger = loggerFactory.CreateLogger(GetType());

logger?.LogInformation(
"Executing {ResultName}. Writing value of type {ValueTypeName}.",
nameof(ForbiddenObjectResult),
valueType.Name);
}
}
11 changes: 9 additions & 2 deletions Asaph.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
using Microsoft.OpenApi;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using System.Configuration;

WebApplicationBuilder? builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddGcpSecretManager(builder.Configuration);

builder.Configuration.AddEnvironmentVariables();

string baseUri = builder.Configuration["BaseUri"];
string? baseUri = builder.Configuration["BaseUri"];

if (baseUri == null)
throw new ConfigurationErrorsException("Missing base URI configuration.");

builder.Logging
.ClearProviders()
Expand All @@ -34,7 +38,10 @@

WebApplication? app = builder.Build();

string[] allowedOrigins = builder.Configuration["Cors:AllowedOrigins"].Split(',');
string[]? allowedOrigins = builder.Configuration["Cors:AllowedOrigins"]?.Split(',');

if (allowedOrigins == null)
throw new ConfigurationErrorsException("Missing CORS allowed origins configuration.");

app
.UseCors(c => c
Expand Down
Loading

0 comments on commit 14f48fe

Please sign in to comment.