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

Feature/net 6 #28

Merged
merged 21 commits into from
Jul 26, 2022
Merged
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
4 changes: 2 additions & 2 deletions dotnet-tools.json → .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "1.3.0",
"version": "2.2.0",
"commands": [
"dotnet-cake"
]
}
}
}
}
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ This project supports only the latest version with security updates. However, we

## Reporting a Vulnerability

Contact [user@example.com|@ExampleUser] to report a security vulnerability. You will be thanked!
Contact mihail.merkulov@gmail.com to report a security vulnerability. You will be thanked!
39 changes: 30 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0
- name: 'Git Fetch Tags'
run: git fetch --tags
shell: pwsh
- name: 'Install .NET Core SDK'
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.x
dotnet-version: '6.0.x'
- name: 'Dotnet Tool Restore'
run: dotnet tool restore
shell: pwsh
Expand All @@ -38,17 +38,38 @@ jobs:
shell: pwsh
- name: 'Dotnet Cake Test'
run: dotnet cake --target=Test
shell: pwsh
- name: 'Dotnet Cake Pack'
run: dotnet cake --target=Pack
shell: pwsh
shell: pwsh
- name: Copy Coverage To Predictable Location
if: github.event_name == 'pull_request'
run: cp coverage/*/coverage.opencover.xml coverage/coverage.opencover.xml
- name: 'Publish Code Coverage'
uses: actions/upload-artifact@v2
with:
name: tests
path: './Artefacts/**/coverage.opencover.xml'
path: './coverage/coverage.opencover.xml'
- name: 'Publish Test Results'
uses: actions/upload-artifact@v2
with:
name: tests
path: './Artefacts/VaultSharp.Extensions.Configuration.Test.html'
path: './coverage/VaultSharp.Extensions.Configuration.Test.html'
# - name: Code Coverage Summary Report
# if: github.event_name == 'pull_request'
# uses: irongut/CodeCoverageSummary@v1.2.0
# with:
# filename: coverage/coverage.opencover.xml
# badge: true
# fail_below_min: true
# format: markdown
# hide_branch_rate: false
# hide_complexity: true
# indicators: true
# output: both
# - name: Add Coverage PR Comment
# uses: marocchino/sticky-pull-request-comment@v2
# if: github.event_name == 'pull_request'
# with:
# recreate: true
# path: code-coverage-results.md
- name: 'Dotnet Cake Pack'
run: dotnet cake --target=Pack
shell: pwsh
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0
- name: 'Git Fetch Tags'
run: git fetch --tags
shell: pwsh
- name: 'Install .NET Core SDK'
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.x
dotnet-version: '6.0.x'
- name: 'Dotnet Tool Restore'
run: dotnet tool restore
shell: pwsh
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ MigrationBackup/
.ionide/

Artefacts/
coverage/
14 changes: 6 additions & 8 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
<PropertyGroup Label="Package">
<Authors>Mikhail Merkulov</Authors>
<Company>Mikhail Merkulov</Company>
<Copyright>Copyright 2020 © Mikhail Merkulov. All rights Reserved</Copyright>
<Copyright>Copyright 2022 © Mikhail Merkulov. All rights Reserved</Copyright>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/MrZoidberg/VaultSharp.Extensions.Configuration</PackageProjectUrl>
<RepositoryUrl>https://github.com/MrZoidberg/VaultSharp.Extensions.Configuration.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>https://github.com/MrZoidberg/VaultSharp.Extensions.Configuration/releases</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" PrivateAssets="All" Version="5.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.10.56" />
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.5.0" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
</ItemGroup>
</Project>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Project Author
Copyright (c) 2022 Mikhail Merkulov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

VaultSharp.Extensions.Configuration is an extension to [VaultSharp](https://github.com/rajanadar/VaultSharp) that allows reading configuration options from Vault.

VaultSharp.Extensions.Configuration is a .NET Standard 2.1 and .NET 6.0 based cross-platform C# Library.

## Get Started

VaultSharp.Extensions.Configuration can be installed using the Nuget package manager or the dotnet CLI.
Expand Down Expand Up @@ -67,8 +69,10 @@ Keep in mind that your service should be registered as scoped or transient to re
Also `IOptionsSnapshot` can return empty value in some cases ([it's .net core bug](https://github.com/dotnet/runtime/issues/37860))

## Configuration using additional characters for a configuration path

This will be helpful when you want to flatten the structure of the secrets.
For example the following two secret objects will evaluate to the same configuration if for the second object the `additionalCharactersForConfigurationPath` option is used with `new []{'.'}` value:
For example the following two secret objects will evaluate to the same configuration if for the second object the `additionalCharactersForConfigurationPath` option is used with `new []{'.'}` value:

```json
{
"secrets":
Expand All @@ -80,6 +84,7 @@ For example the following two secret objects will evaluate to the same configura
}
}
```

```json
{
"secrets":
Expand Down Expand Up @@ -128,7 +133,7 @@ All parameters are grouped and arranged in folders and can be managed within the

There are two ways to create nested parameters.

1. Description of nesting directly in Json format:
1. Description of nesting directly in Json format (preferred approach):

```json
{
Expand Down
4 changes: 0 additions & 4 deletions Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions Source/SampleWebApp/Controllers/HelloController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SampleWebApp.Controllers;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Options;

[Route("hello")]
[ApiController]
public class HelloController
{
[HttpGet("")]
public IActionResult GetValue([FromServices] IOptionsSnapshot<TestOptions> testOptions) => new OkObjectResult(testOptions.Value);
}
12 changes: 6 additions & 6 deletions Source/SampleWebApp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY /SampleWebApp/SampleWebApp.csproj ./SampleWebApp/
COPY /VaultSharp.Extensions.Configuration/VaultSharp.Extensions.Configuration.csproj ./VaultSharp.Extensions.Configuration/
RUN dotnet restore ./SampleWebApp/SampleWebApp.csproj
COPY /Source/SampleWebApp/SampleWebApp.csproj ./Source/SampleWebApp/
COPY /Source/VaultSharp.Extensions.Configuration/VaultSharp.Extensions.Configuration.csproj ./Source/VaultSharp.Extensions.Configuration/
RUN dotnet restore ./Source/SampleWebApp/SampleWebApp.csproj

# Copy everything else and build
COPY . ./
RUN dotnet publish ./SampleWebApp/SampleWebApp.csproj -c Release -o out
RUN dotnet publish ./Source/SampleWebApp/SampleWebApp.csproj -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "SampleWebApp.dll"]
8 changes: 8 additions & 0 deletions Source/SampleWebApp/Options/TestOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SampleWebApp.Options;

public class TestOptions
{
public const string Test = "Test";

public string ValueA { get; set; }
}
80 changes: 45 additions & 35 deletions Source/SampleWebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
namespace SampleWebApp
namespace SampleWebApp;

using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using VaultSharp.Extensions.Configuration;

public class Program
{
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using VaultSharp.Extensions.Configuration;
public static ILogger Logger { get; private set; }

public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();

public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
})
.ConfigureAppConfiguration((hostingContext, config) =>
{
using var loggerFactory = LoggerFactory.Create(builder =>
builder.AddConsole(c => c.LogToStandardErrorThreshold = LogLevel.Debug).AddDebug());
Logger = loggerFactory.CreateLogger<Program>();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json",
optional: true)
.AddEnvironmentVariables()
.AddVaultConfiguration(
() => new VaultOptions(
"http://localhost:8200",
"root",
reloadOnChange: true,
reloadCheckIntervalSeconds: 60),
"sampleapp",
"secret");
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json",
optional: true)
.AddEnvironmentVariables()
.AddVaultConfiguration(
() => new VaultOptions(
"http://vault:8200", // Change this to "http://localhost:8200" if you are working locally without Docker
"root",
reloadOnChange: true,
reloadCheckIntervalSeconds: 60),
"sampleapp",
"secret",
Logger);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
14 changes: 12 additions & 2 deletions Source/SampleWebApp/SampleWebApp.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\VaultSharp.Extensions.Configuration\VaultSharp.Extensions.Configuration.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.2.32">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MinVer" Version="4.1.0" />
</ItemGroup>


Expand Down
Loading