Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from martincostello/AspNetCore-2.1
Migrate to ASP.NET Core 2.1
- Loading branch information
Showing
36 changed files
with
3,114 additions
and
4,092 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "2.1.101" | ||
"version": "2.1.300" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Martin Costello, 2017. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
namespace MartinCostello.LondonTravel.Site | ||
{ | ||
using System; | ||
using Microsoft.Azure.KeyVault.Models; | ||
using Microsoft.Extensions.Configuration.AzureKeyVault; | ||
|
||
/// <summary> | ||
/// A class representing an implementation of <see cref="IKeyVaultSecretManager"/> | ||
/// that selects keys based on the Azure environment name. This class cannot be inherited. | ||
/// </summary> | ||
internal sealed class AzureEnvironmentSecretManager : IKeyVaultSecretManager | ||
{ | ||
/// <summary> | ||
/// The secret prefix to use for the environment. | ||
/// </summary> | ||
private readonly string _prefix; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AzureEnvironmentSecretManager"/> class. | ||
/// </summary> | ||
/// <param name="azureEnvironment">The name of the Azure environment.</param> | ||
public AzureEnvironmentSecretManager(string azureEnvironment) | ||
{ | ||
_prefix = $"LondonTravel-{azureEnvironment}-"; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string GetKey(SecretBundle secret) | ||
{ | ||
return secret.SecretIdentifier.Name.Substring(_prefix.Length) | ||
.Replace("--", "_", StringComparison.Ordinal) | ||
.Replace("-", ":", StringComparison.Ordinal); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool Load(SecretItem secret) | ||
{ | ||
return secret.Identifier.Name.StartsWith(_prefix, StringComparison.Ordinal); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/LondonTravel.Site/Extensions/IConfigurationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Martin Costello, 2017. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
namespace MartinCostello.LondonTravel.Site.Extensions | ||
{ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
/// <summary> | ||
/// A class containing extension methods for the <see cref="IConfigurationBuilder"/> interface. This class cannot be inherited. | ||
/// </summary> | ||
public static class IConfigurationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the application. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to configure.</param> | ||
/// <param name="context">The <see cref="WebHostBuilderContext"/> to use.</param> | ||
/// <returns> | ||
/// The <see cref="IConfigurationBuilder"/> passed as the value of <paramref name="builder"/>. | ||
/// </returns> | ||
public static IConfigurationBuilder ConfigureApplication(this IConfigurationBuilder builder, WebHostBuilderContext context) | ||
{ | ||
builder.AddApplicationInsightsSettings(developerMode: context.HostingEnvironment.IsDevelopment()); | ||
|
||
// Build the configuration so far | ||
IConfiguration config = builder.Build(); | ||
|
||
// Get the settings for Azure Key Vault | ||
string vault = config["AzureKeyVault:Uri"]; | ||
string clientId = config["AzureKeyVault:ClientId"]; | ||
string clientSecret = config["AzureKeyVault:ClientSecret"]; | ||
|
||
bool canUseKeyVault = | ||
!string.IsNullOrEmpty(vault) && | ||
!string.IsNullOrEmpty(clientId) && | ||
!string.IsNullOrEmpty(clientSecret); | ||
|
||
if (canUseKeyVault) | ||
{ | ||
var manager = new AzureEnvironmentSecretManager(config.AzureEnvironment()); | ||
|
||
builder.AddAzureKeyVault( | ||
vault, | ||
clientId, | ||
clientSecret, | ||
manager); | ||
} | ||
|
||
return builder; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/LondonTravel.Site/Extensions/ILoggingBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Martin Costello, 2017. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
namespace MartinCostello.LondonTravel.Site.Extensions | ||
{ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
|
||
/// <summary> | ||
/// A class containing extension methods for the <see cref="ILoggingBuilder"/> interface. This class cannot be inherited. | ||
/// </summary> | ||
public static class ILoggingBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Configures logging for the application. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="ILoggingBuilder"/> to configure.</param> | ||
/// <param name="context">The <see cref="WebHostBuilderContext"/> to use.</param> | ||
/// <returns> | ||
/// The <see cref="ILoggingBuilder"/> passed as the value of <paramref name="builder"/>. | ||
/// </returns> | ||
public static ILoggingBuilder ConfigureLogging(this ILoggingBuilder builder, WebHostBuilderContext context) | ||
{ | ||
var loggerConfig = new LoggerConfiguration() | ||
.Enrich.FromLogContext() | ||
.Enrich.WithProperty("AspNetCoreEnvironment", context.HostingEnvironment.EnvironmentName) | ||
.Enrich.WithProperty("AzureDatacenter", context.Configuration.AzureDatacenter()) | ||
.Enrich.WithProperty("AzureEnvironment", context.Configuration.AzureEnvironment()) | ||
.Enrich.WithProperty("Version", GitMetadata.Commit) | ||
.ReadFrom.Configuration(context.Configuration) | ||
.WriteTo.ApplicationInsightsEvents(context.Configuration.ApplicationInsightsKey()); | ||
|
||
if (context.HostingEnvironment.IsDevelopment()) | ||
{ | ||
loggerConfig = loggerConfig.WriteTo.LiterateConsole(); | ||
} | ||
|
||
string papertrailHostname = context.Configuration.PapertrailHostname(); | ||
|
||
if (!string.IsNullOrWhiteSpace(papertrailHostname)) | ||
{ | ||
loggerConfig.WriteTo.Papertrail(papertrailHostname, context.Configuration.PapertrailPort()); | ||
} | ||
|
||
Log.Logger = loggerConfig.CreateLogger(); | ||
return builder.AddSerilog(dispose: true); | ||
} | ||
} | ||
} |
Oops, something went wrong.