Skip to content

Commit

Permalink
Merge pull request #462 from Laixer/develop
Browse files Browse the repository at this point in the history
v3.0-prerelease
  • Loading branch information
yorickdewid authored Feb 5, 2021
2 parents d29cce8 + ff68366 commit aec22c2
Show file tree
Hide file tree
Showing 260 changed files with 3,253 additions and 5,632 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ jobs:

- name: Test
run: dotnet test --nologo --configuration ${{ env.BUILD_CONFIG }} --no-restore
env:
Jwt__Issuer: "FunderMapsTest"
Jwt__Audience: "FunderMapsTest"
Jwt__TokenValidity: 10
Jwt__SignatureKey: somelargetextstringusedinsignatures
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

5 changes: 1 addition & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
"cwd": "${workspaceFolder}/src/FunderMaps.BatchNode",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": false
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
"DOTNET_ENVIRONMENT": "Development"
}
},
{
Expand Down
40 changes: 21 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# FunderMaps Ecosystem

# Build the application solution
# Build application solution
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /source

# The subtool must be defined. The build container will only build the
# subtool application.
ARG subtool

RUN test -n "$subtool" || (echo "subtool argument not set" && false)

# Copy and restore app
# Copy the entire solution in the container
COPY . .

# Substitute magic variables with version
RUN find . -type f -exec sed -i "s/@@VERSION@@/$(git describe --long --always)/" {} +
RUN find . -type f -exec sed -i "s/@@COMMIT@@/$(git rev-parse HEAD)/" {} +
# Print the application version in the source
RUN find . -type f -exec sed -i "s/@@VERSION@@/$(git describe --long --always)/" {} + \
&& find . -type f -exec sed -i "s/@@COMMIT@@/$(git rev-parse HEAD)/" {} +

# Publish app and libraries
RUN echo "Building $subtool"
# Publish and configure subtool application
WORKDIR "/source/src/$subtool"
RUN dotnet publish -c release -o /app \
&& git describe --long --always > /app/VERSION \
&& git rev-parse HEAD > /app/COMMIT \
&& echo "$subtool" > /app/SUBTOOL

WORKDIR /app
RUN ln -s "$subtool" "entry"

# Runtime image
#
# Any FunderMaps application in the repository can
# be called via the CMD=<application> environment
# variable.
FROM mcr.microsoft.com/dotnet/aspnet:latest
&& echo "$subtool" > /app/SUBTOOL \
&& ln -s "$subtool" /app/entry \
&& rm -f /app/appsettings.json /app/appsettings.*.json \
&& cp /source/contrib/etc/_appsettings.Production.json /app/appsettings.Production.json \
&& cp /source/contrib/etc/_appsettings.Staging.json /app/appsettings.Staging.json

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal
ENV DOTNET_PRINT_TELEMETRY_MESSAGE=false
WORKDIR /app
COPY --from=build /app .
RUN if grep -Fxq "FunderMaps.BatchNode" SUBTOOL ; then \
apt -y update; \
apt -y install gdal-bin; \
fi
EXPOSE 80/tcp
ENTRYPOINT "/app/$CMD"
ENTRYPOINT "/app/entry"
7 changes: 0 additions & 7 deletions FunderMaps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.IntegrationTests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.Data", "src\FunderMaps.Data\FunderMaps.Data.csproj", "{E176260E-0D9C-4374-AC49-F312C7EC23FD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.Core.Tests", "tests\FunderMaps.Core.Tests\FunderMaps.Core.Tests.csproj", "{3206FABE-295E-401D-A43A-41174E2DEA61}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.Core.Authentication", "src\FunderMaps.Core.Authentication\FunderMaps.Core.Authentication.csproj", "{604F9414-3E2F-4DC7-9420-366441FFA31D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunderMaps.Webservice", "src\FunderMaps.Webservice\FunderMaps.Webservice.csproj", "{278702CF-559B-4ED5-8C57-FD0E23DC4014}"
Expand Down Expand Up @@ -63,10 +61,6 @@ Global
{E176260E-0D9C-4374-AC49-F312C7EC23FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E176260E-0D9C-4374-AC49-F312C7EC23FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E176260E-0D9C-4374-AC49-F312C7EC23FD}.Release|Any CPU.Build.0 = Release|Any CPU
{3206FABE-295E-401D-A43A-41174E2DEA61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3206FABE-295E-401D-A43A-41174E2DEA61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3206FABE-295E-401D-A43A-41174E2DEA61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3206FABE-295E-401D-A43A-41174E2DEA61}.Release|Any CPU.Build.0 = Release|Any CPU
{604F9414-3E2F-4DC7-9420-366441FFA31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{604F9414-3E2F-4DC7-9420-366441FFA31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{604F9414-3E2F-4DC7-9420-366441FFA31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -105,7 +99,6 @@ Global
{FE4947DD-2A36-4FD6-BC31-674797585837} = {3CCE5914-CD6D-4DFD-9FF5-E872044553DD}
{3BD8CCB6-82FC-4016-8D43-6814473E5796} = {0219D434-DD4F-4187-ADED-8CD4A62E90F1}
{E176260E-0D9C-4374-AC49-F312C7EC23FD} = {3CCE5914-CD6D-4DFD-9FF5-E872044553DD}
{3206FABE-295E-401D-A43A-41174E2DEA61} = {0219D434-DD4F-4187-ADED-8CD4A62E90F1}
{604F9414-3E2F-4DC7-9420-366441FFA31D} = {3CCE5914-CD6D-4DFD-9FF5-E872044553DD}
{278702CF-559B-4ED5-8C57-FD0E23DC4014} = {54F0529D-8DC7-4DCC-8A93-BF0B2E5F8BE2}
{8A28CFFE-2028-40AC-9CCD-81796FD360AE} = {54F0529D-8DC7-4DCC-8A93-BF0B2E5F8BE2}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ test:

clean:
dotnet clean --nologo
rm Documentation*.xml
find . -type f -name "Documentation*.xml" -exec rm {} +
37 changes: 37 additions & 0 deletions contrib/etc/_appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Jwt": {
"Issuer": "FunderMapsDev",
"Audience": "FunderMapsDev",
"TokenValidity": 5,
"SignatureKey": "dhfgdfubhgbdfghredfgregurhe78gh348yvt784tcno3qt74gntkuirdhg"
},
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"Incident": {
"ClientId": 12,
"Recipients": [
"info@fundermaps.com"
]
},
"UseExternalServices": false,
"Smtp": {
"SmtpServer": "smtp.transip.email",
"SmtpPort": 465,
"SmtpUsername": "info@fundermaps.com",
"SmtpPassword": null,
"DefaultSenderName": "FunderMaps",
"DefaultSenderAddress": "info@fundermaps.com"
},
"ConnectionStrings": {
"FunderMapsConnection": null
},
"BlobStorage": {
"AccessKey": "LOUSAQJLIXLMIXKTKDW5",
"SecretKey": null,
"ServiceUri": "https://ams3.digitaloceanspaces.com/",
"BlobStorageName": "fundermaps-development"
}
}
26 changes: 26 additions & 0 deletions contrib/etc/_appsettings.Production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Jwt": {
"Issuer": "FunderMaps",
"Audience": "FunderMaps",
"TokenValidity": 120
},
"Logging": {
"LogLevel": {
"Default": "Warning",
"Microsoft.AspNetCore.DataProtection": "Error"
}
},
"Batch": {
"ServiceUri": "https://batch.fundermaps.com"
},
"Smtp": {
"SmtpPort": 465,
"DefaultSenderName": "FunderMaps",
"DefaultSenderAddress": "info@fundermaps.com"
},
"BlobStorage": {
"AccessKey": "ZDQQ3W7SX2LTGEHGIY3M",
"ServiceUri": "https://ams3.digitaloceanspaces.com/",
"BlobStorageName": "fundermaps-production"
}
}
25 changes: 25 additions & 0 deletions contrib/etc/_appsettings.Staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Jwt": {
"Issuer": "FunderMaps",
"Audience": "FunderMaps",
"TokenValidity": 60
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"Batch": {
"ServiceUri": "https://staging.batch.fundermaps.com"
},
"Smtp": {
"SmtpPort": 465,
"DefaultSenderName": "FunderMaps",
"DefaultSenderAddress": "info@fundermaps.com"
},
"BlobStorage": {
"AccessKey": "5K6F45VBQEH6NRT6QMB7",
"ServiceUri": "https://ams3.digitaloceanspaces.com/",
"BlobStorageName": "fundermaps-staging"
}
}
48 changes: 0 additions & 48 deletions src/FunderMaps.AspNetCore/AspAppContextFactory.cs

This file was deleted.

26 changes: 16 additions & 10 deletions src/FunderMaps.AspNetCore/Authentication/JwtBearerTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class JwtBearerTokenProvider : ISecurityTokenProvider
/// </summary>
public JwtBearerTokenProvider(IOptionsMonitor<JwtBearerOptions> options, ILogger<JwtBearerTokenProvider> logger, ISystemClock clock)
{
if (options == null)
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
Expand All @@ -48,11 +48,17 @@ public JwtBearerTokenProvider(IOptionsMonitor<JwtBearerOptions> options, ILogger
Clock = clock ?? throw new ArgumentNullException(nameof(clock));
}

/// <summary>
/// Find the first security token handler that can write a token.
/// </summary>
private SecurityTokenHandler Handler
=> (SecurityTokenHandler)Options
.SecurityTokenValidators
.FirstOrDefault(s => (s as SecurityTokenHandler).CanValidateToken);
=> (SecurityTokenHandler)Options.SecurityTokenValidators.FirstOrDefault(s => (s as SecurityTokenHandler).CanWriteToken);

/// <summary>
/// Generate a <see cref="SecurityToken"/> from a <see cref="ClaimsPrincipal"/>.
/// </summary>
/// <param name="principal">Claims principal.</param>
/// <returns>Instance of <see cref="SecurityToken"/>.</returns>
protected virtual SecurityToken GenerateSecurityToken(ClaimsPrincipal principal)
{
if (principal is null)
Expand All @@ -64,17 +70,17 @@ protected virtual SecurityToken GenerateSecurityToken(ClaimsPrincipal principal)

var JwtTokenValidationParameters = Options.TokenValidationParameters as JwtTokenValidationParameters;
var issuerSigningKey = JwtTokenValidationParameters.IssuerSigningKey;
var SigningCredentials = new SigningCredentials(issuerSigningKey, SecurityAlgorithms.HmacSha256);
SigningCredentials SigningCredentials = new(issuerSigningKey, SecurityAlgorithms.HmacSha256);

List<Claim> claims = new(principal.Claims)
{
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
};

var nameClaim = claims.FirstOrDefault(c => c.Type.Equals(ClaimTypes.Name, StringComparison.Ordinal));
if (nameClaim != null)
if (nameClaim is not null)
{
claims.Add(new Claim(JwtRegisteredClaimNames.Sub, nameClaim.Value));
claims.Add(new(JwtRegisteredClaimNames.Sub, nameClaim.Value));
}

DateTimeOffset issuedUtc;
Expand Down Expand Up @@ -103,7 +109,7 @@ protected virtual SecurityToken GenerateSecurityToken(ClaimsPrincipal principal)
}

/// <summary>
/// Generate token.
/// Generate a <see cref="SecurityToken"/> from a <see cref="ClaimsPrincipal"/>.
/// </summary>
/// <param name="principal">Claims principal.</param>
/// <returns>Instance of <see cref="SecurityToken"/>.</returns>
Expand All @@ -112,7 +118,7 @@ public virtual SecurityToken GetToken(ClaimsPrincipal principal)
=> GenerateSecurityToken(principal);

/// <summary>
/// Generate token.
/// Generate a <see cref="TokenContext"/> from a <see cref="ClaimsPrincipal"/>.
/// </summary>
/// <param name="principal">Claims principal.</param>
/// <returns>Instance of <see cref="TokenContext"/>.</returns>
Expand All @@ -124,7 +130,7 @@ public virtual TokenContext GetTokenContext(ClaimsPrincipal principal)
}

SecurityToken token = GetToken(principal);
return new TokenContext
return new()
{
TokenString = Handler.WriteToken(token),
Token = token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class JwtTokenValidationParameters : TokenValidationParameters
/// <summary>
/// Token valid time.
/// </summary>
public TimeSpan Valid { get; set; }
public TimeSpan Valid { get; init; }
}
}
Loading

0 comments on commit aec22c2

Please sign in to comment.