Skip to content

Commit 6709151

Browse files
committed
Merge branch 'feature/#1' into develop
2 parents 58d7ee1 + 6ae83d7 commit 6709151

19 files changed

+122
-253
lines changed

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Build Package](https://github.com/SimplifyNet/Etcd.Microsoft.Extensions.Configuration/actions/workflows/build.yml/badge.svg)](https://github.com/SimplifyNet/Etcd.Microsoft.Extensions.Configuration/actions/workflows/build.yml)
66
[![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/nuget/Etcd.Microsoft.Extensions.Configuration)](https://libraries.io/nuget/Etcd.Microsoft.Extensions.Configuration)
77
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/SimplifyNet/Etcd.Microsoft.Extensions.Configuration)](https://www.codefactor.io/repository/github/simplifynet/Etcd.Microsoft.Extensions.Configuration)
8-
![Platform](https://img.shields.io/badge/platform-.NET%206.0%20%7C%20.NET%20Standard%202.1%20%7C%20.NET%20Standard%202.0%20%7C%20.NET%204.6.2-lightgrey)
8+
![Platform](https://img.shields.io/badge/platform-.NET%206.0%20%7C%20.NET%20Standard%202.1-lightgrey)
99
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen)](http://makeapullrequest.com)
1010

1111
Etcd based configuration provider for Microsoft.Extensions.Configuration.
@@ -25,39 +25,27 @@ Etcd based configuration provider for Microsoft.Extensions.Configuration.
2525
var myKeyValue = mySection["MyKeyName"];
2626
```
2727

28-
### HTTPS with certificate in environment variables
28+
### HTTPS
2929

30-
1. Add `ETCD_CLIENT_CA_FILE` environment variable with path to etcd CA file (shoule be provided by etcd administrator), for example: `C:\etcd\cert\EtcdCa.crt`
30+
When using HTTPS, *.crt CA certificate (should be provided by etcd administrator) should be placed in well known system certificate store (depending on OS).
3131

32-
```csharp
33-
var config = new ConfigurationBuilder()
34-
.AddEtcd(
35-
new Credentials("MyEtcdUserName", "passw"),
36-
new EtcdSettings("https://serveraddress:2379"))
37-
.Build();
38-
39-
var mySection = config.GetSection("MySection");
40-
var myKeyValue = mySection["MyKeyName"];
41-
```
32+
* For Windows it is `Trusted Root Certification Authority`.
33+
* For Linux, at least for Arch/Manjaro Linux it should be placed in : `/etc/ca-certificates/trust-source/anchors/` followed by `sudo trust extract-compat` command
4234

4335
### HTTPS with settings from local JSON file
4436

4537
appsettings.json
4638

4739
```json
4840
{
49-
"EtcdSettings":
50-
{
51-
"ConnectionString":, "https://serveraddress:2379",
52-
"CertificateData":, "-----BEGIN CERTIFICATE----- 1234321 -----END CERTIFICATE-----
53-
",
54-
}
41+
"EtcdSettings":
42+
{
43+
"ConnectionString": "https://serveraddress:2379"
44+
}
5545
}
56-
5746
```
5847

5948
```csharp
60-
6149
var jsonConfig = new ConfigurationBuilder()
6250
.AddJsonFile("appsettings.json")
6351
.Build();
@@ -72,4 +60,21 @@ var mySection = config.GetSection("MySection");
7260
var myKeyValue = mySection["MyKeyName"];
7361
```
7462

75-
Settings can be mixed from different locations, for example, you can set only CA file in environment variable and only connection string in JSON file.
63+
Settings can be mixed from different locations.
64+
65+
## Contributing
66+
67+
There are many ways in which you can participate in the project. Like most open-source software projects, contributing code is just one of many outlets where you can help improve. Some of the things that you could help out with are:
68+
69+
* Documentation (both code and features)
70+
* Bug reports
71+
* Bug fixes
72+
* Feature requests
73+
* Feature implementations
74+
* Test coverage
75+
* Code quality
76+
* Sample applications
77+
78+
## License
79+
80+
Licensed under the GNU LESSER GENERAL PUBLIC LICENSE

src/Etcd.Microsoft.Extensions.Configuration.sln

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Etcd.Microsoft.Extensions.C
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D642C321-C71F-4016-99D9-6FC44C2E89AF}"
99
EndProject
10-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration", "Integration", "{2EA4E607-BD67-46D4-B838-7744449AD719}"
11-
EndProject
1210
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Unit", "Unit", "{A4257365-9F14-4D99-A389-B09536B78D06}"
1311
EndProject
1412
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Etcd.Microsoft.Extensions.Configuration.Tests", "..\tests\Unit\Etcd.Microsoft.Extensions.Configuration.Tests\Etcd.Microsoft.Extensions.Configuration.Tests.csproj", "{8DEF43FE-0E8B-4544-B515-230F55E42041}"
1513
EndProject
16-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Etcd.Microsoft.Extensions.Configuration.IntegrationTests", "..\tests\Integration\Etcd.Microsoft.Extensions.Configuration.IntegrationTests\Etcd.Microsoft.Extensions.Configuration.IntegrationTests.csproj", "{9C61F6CE-CBB4-4074-A3B3-3EAA7EC4B081}"
17-
EndProject
18-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Etcd.Microsoft.Extensions.Configuration.IntegrationTests.Core", "..\tests\Integration\Etcd.Microsoft.Extensions.Configuration.IntegrationTests.Core\Etcd.Microsoft.Extensions.Configuration.IntegrationTests.Core.csproj", "{1DB1C2FF-1D1E-4251-AD2E-C6A486681284}"
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Etcd.Microsoft.Extensions.Configuration.IntegrationTests", "..\tests\Integration\Etcd.Microsoft.Extensions.Configuration.IntegrationTests\Etcd.Microsoft.Extensions.Configuration.IntegrationTests.csproj", "{35933B6F-D39E-420A-83DA-6DEAA5641A3C}"
1915
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration", "Integration", "{52819380-DEA0-11EC-A4C3-E12872F27F80}"
17+
EndProject
2018
Global
2119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2220
Debug|Any CPU = Debug|Any CPU
@@ -31,24 +29,19 @@ Global
3129
{8DEF43FE-0E8B-4544-B515-230F55E42041}.Debug|Any CPU.Build.0 = Debug|Any CPU
3230
{8DEF43FE-0E8B-4544-B515-230F55E42041}.Release|Any CPU.ActiveCfg = Release|Any CPU
3331
{8DEF43FE-0E8B-4544-B515-230F55E42041}.Release|Any CPU.Build.0 = Release|Any CPU
34-
{9C61F6CE-CBB4-4074-A3B3-3EAA7EC4B081}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35-
{9C61F6CE-CBB4-4074-A3B3-3EAA7EC4B081}.Debug|Any CPU.Build.0 = Debug|Any CPU
36-
{9C61F6CE-CBB4-4074-A3B3-3EAA7EC4B081}.Release|Any CPU.ActiveCfg = Release|Any CPU
37-
{9C61F6CE-CBB4-4074-A3B3-3EAA7EC4B081}.Release|Any CPU.Build.0 = Release|Any CPU
38-
{1DB1C2FF-1D1E-4251-AD2E-C6A486681284}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39-
{1DB1C2FF-1D1E-4251-AD2E-C6A486681284}.Debug|Any CPU.Build.0 = Debug|Any CPU
40-
{1DB1C2FF-1D1E-4251-AD2E-C6A486681284}.Release|Any CPU.ActiveCfg = Release|Any CPU
41-
{1DB1C2FF-1D1E-4251-AD2E-C6A486681284}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{35933B6F-D39E-420A-83DA-6DEAA5641A3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{35933B6F-D39E-420A-83DA-6DEAA5641A3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{35933B6F-D39E-420A-83DA-6DEAA5641A3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{35933B6F-D39E-420A-83DA-6DEAA5641A3C}.Release|Any CPU.Build.0 = Release|Any CPU
4236
EndGlobalSection
4337
GlobalSection(SolutionProperties) = preSolution
4438
HideSolutionNode = FALSE
4539
EndGlobalSection
4640
GlobalSection(NestedProjects) = preSolution
47-
{2EA4E607-BD67-46D4-B838-7744449AD719} = {D642C321-C71F-4016-99D9-6FC44C2E89AF}
41+
{52819380-DEA0-11EC-A4C3-E12872F27F80} = {D642C321-C71F-4016-99D9-6FC44C2E89AF}
42+
{35933B6F-D39E-420A-83DA-6DEAA5641A3C} = {52819380-DEA0-11EC-A4C3-E12872F27F80}
4843
{A4257365-9F14-4D99-A389-B09536B78D06} = {D642C321-C71F-4016-99D9-6FC44C2E89AF}
4944
{8DEF43FE-0E8B-4544-B515-230F55E42041} = {A4257365-9F14-4D99-A389-B09536B78D06}
50-
{9C61F6CE-CBB4-4074-A3B3-3EAA7EC4B081} = {2EA4E607-BD67-46D4-B838-7744449AD719}
51-
{1DB1C2FF-1D1E-4251-AD2E-C6A486681284} = {2EA4E607-BD67-46D4-B838-7744449AD719}
5245
EndGlobalSection
5346
GlobalSection(ExtensibilityGlobals) = postSolution
5447
SolutionGuid = {17F020F3-70C0-4F38-A51C-215181562945}

src/Etcd.Microsoft.Extensions.Configuration/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [2.0.0] - 2022-06-04
4+
5+
### Removed
6+
7+
- .NET Standard 2.0 support
8+
- .NET Framework 4.6.2 support
9+
10+
### Dependencies
11+
12+
- dotnet-etcd bump to 5.2
13+
- Microsoft.Extensions.Configuration bump to 6.0.1
14+
315
## [1.0.3] - 2022-06-01
416

517
### Fixed
Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
1-
using System;
2-
using dotnet_etcd;
3-
using dotnet_etcd.interfaces;
4-
using Etcd.Microsoft.Extensions.Configuration.Settings;
5-
6-
namespace Etcd.Microsoft.Extensions.Configuration.Client;
7-
8-
/// <summary>
9-
/// Provides etcd client factory
10-
/// </summary>
11-
public class EtcdClientFactory : IEtcdClientFactory
12-
{
13-
/// <summary>
14-
/// Initializes a new instance of the <see cref="EtcdClientFactory" /> class.
15-
/// </summary>
16-
/// <param name="settings">The settings.</param>
17-
/// <exception cref="ArgumentNullException">settings</exception>
18-
public EtcdClientFactory(IEtcdSettings? settings = null)
19-
{
20-
var environmentSetting = EnvironmentSettingsFactory.Create();
21-
22-
Settings = new EtcdSettings(settings?.ConnectionString ?? environmentSetting.ConnectionString,
23-
settings?.CertificateData ?? environmentSetting.CertificateData);
24-
}
25-
26-
/// <summary>
27-
/// Gets the settings.
28-
/// </summary>
29-
/// <value>
30-
/// The settings.
31-
/// </value>
32-
public IEtcdSettings Settings { get; }
33-
34-
/// <summary>
35-
/// Creates the etcd client instance.
36-
/// </summary>
37-
/// <returns></returns>
38-
public IEtcdClient Create()
39-
{
40-
if (string.IsNullOrEmpty(Settings.ConnectionString))
41-
throw new EtcdConfigurationException("Connection string is missing, should be passed in AddEtcd parameters or set in environment variables.");
42-
43-
return Settings.ConnectionString!.StartsWith("https")
44-
? new EtcdClient(Settings.ConnectionString, caCert: Settings.CertificateData ?? throw new EtcdConfigurationException("Certificate data is missing, should be passed in AddEtcd parameters or set in environment variables."))
45-
: new EtcdClient(Settings.ConnectionString);
46-
}
1+
using System;
2+
using dotnet_etcd;
3+
using dotnet_etcd.interfaces;
4+
using Etcd.Microsoft.Extensions.Configuration.Settings;
5+
6+
namespace Etcd.Microsoft.Extensions.Configuration.Client;
7+
8+
/// <summary>
9+
/// Provides etcd client factory
10+
/// </summary>
11+
public class EtcdClientFactory : IEtcdClientFactory
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="EtcdClientFactory" /> class.
15+
/// </summary>
16+
/// <param name="settings">The settings.</param>
17+
/// <exception cref="ArgumentNullException">settings</exception>
18+
public EtcdClientFactory(IEtcdSettings? settings = null)
19+
{
20+
var environmentSetting = EnvironmentSettingsFactory.Create();
21+
22+
Settings = new EtcdSettings(settings?.ConnectionString ?? environmentSetting.ConnectionString);
23+
}
24+
25+
/// <summary>
26+
/// Gets the settings.
27+
/// </summary>
28+
/// <value>
29+
/// The settings.
30+
/// </value>
31+
public IEtcdSettings Settings { get; }
32+
33+
/// <summary>
34+
/// Creates the etcd client instance.
35+
/// </summary>
36+
/// <returns></returns>
37+
public IEtcdClient Create()
38+
{
39+
if (string.IsNullOrEmpty(Settings.ConnectionString))
40+
throw new EtcdConfigurationException("Connection string is missing, should be passed in AddEtcd parameters or set in environment variables.");
41+
42+
return new EtcdClient(Settings.ConnectionString, ssl: Settings.ConnectionString!.StartsWith("https"));
43+
}
4744
}

src/Etcd.Microsoft.Extensions.Configuration/Client/EtcdKeyValueClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Etcdserverpb;
1111
using Google.Protobuf;
1212
using Grpc.Core;
13+
1314
using Convert = Etcd.Microsoft.Extensions.Configuration.Util.Convert;
1415

1516
namespace Etcd.Microsoft.Extensions.Configuration.Client;
@@ -130,7 +131,7 @@ public void Dispose()
130131
if (_unwatchOnDispose)
131132
StopWatchAll();
132133

133-
_client.Dispose();
134+
_client?.Dispose();
134135
}
135136

136137
/// <summary>
@@ -166,7 +167,7 @@ private IEnumerable<Permission> GetPermissions(string role) =>
166167
private Metadata GetMetadata() =>
167168
new()
168169
{
169-
new("token", _token)
170+
new("token", _token!)
170171
};
171172

172173
private void CheckIsAuthenticated()

src/Etcd.Microsoft.Extensions.Configuration/Etcd.Microsoft.Extensions.Configuration.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
3+
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
44
<LangVersion>latest</LangVersion>
55
<Nullable>enable</Nullable>
66
<EmbedUntrackedSources>true</EmbedUntrackedSources>
77
<IncludeSymbols>true</IncludeSymbols>
88
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010

11-
<Version>1.0.3</Version>
11+
<Version>2.0</Version>
1212

1313
<Description>Etcd based configuration provider for Microsoft.Extensions.Configuration</Description>
1414
<Authors>Simplify community</Authors>
@@ -23,11 +23,8 @@
2323
<PackageReleaseNotes>See https://github.com/SimplifyNet/Etcd.Microsoft.Extensions.Configuration/tree/master/src/Etcd.Microsoft.Extensions.Configuration/CHANGELOG.md for details</PackageReleaseNotes>
2424
</PropertyGroup>
2525
<ItemGroup>
26-
<PackageReference Include="dotnet-etcd" Version="4.2.0" />
27-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
28-
</ItemGroup>
29-
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
30-
<PackageReference Include="Grpc.Core" Version="2.46.3" />
26+
<PackageReference Include="dotnet-etcd" Version="5.2.0" />
27+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
3128
</ItemGroup>
3229
<ItemGroup>
3330
<None Include="..\..\images\icon.png" Pack="true" Visible="false" PackagePath="" />

src/Etcd.Microsoft.Extensions.Configuration/EtcdApplicationEnvironment.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,8 @@ public static class EtcdApplicationEnvironment
1313
/// </summary>
1414
public const string ConnectionStringEnvironmentVariableName = "ETCD_CLIENT_CONNECTION_STRING";
1515

16-
/// <summary>
17-
/// The CA certificate file environment variable name
18-
/// </summary>
19-
public const string CaCertificateEnvironmentVariableName = "ETCD_CLIENT_CA_FILE";
20-
2116
private static string? _connectionString;
22-
private static string? _caCertificateFilePath;
2317

24-
/// <summary>
25-
/// Gets or sets the etcd CA certificate file path.
26-
/// </summary>
27-
/// <value>
28-
/// The ca certificate file path.
29-
/// </value>
30-
/// <exception cref="EtcdException">etcd CA environment variable '{CaCertificateEnvironmentVariableName}' is not found</exception>
31-
/// <exception cref="ArgumentNullException">value</exception>
32-
public static string? CaCertificateFilePath
33-
{
34-
get
35-
{
36-
return _caCertificateFilePath ??= Environment.GetEnvironmentVariable(CaCertificateEnvironmentVariableName);
37-
}
38-
set => _caCertificateFilePath = value ?? throw new ArgumentNullException(nameof(value));
39-
}
4018

4119
/// <summary>
4220
/// Gets or sets the connection string.
@@ -53,14 +31,4 @@ public static string? ConnectionString
5331
}
5432
set => _connectionString = value ?? throw new ArgumentNullException(nameof(value));
5533
}
56-
57-
/// <summary>
58-
/// Gets the CA certificate data from CA certificate file.
59-
/// </summary>
60-
/// <returns></returns>
61-
/// <exception cref="EtcdException">Etcd CA file is empty</exception>
62-
public static string GetCaCertificateData() => File.ReadAllText(CaCertificateFilePath
63-
?? throw new EtcdException(
64-
$"Etcd CA certificate environment variable '{CaCertificateEnvironmentVariableName}' is not found"))
65-
?? throw new EtcdException("Etcd CA certificate file is empty");
6634
}

src/Etcd.Microsoft.Extensions.Configuration/Settings/ConfigurationBasedEtcdSettings.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public ConfigurationBasedEtcdSettings(IConfiguration configuration, string confi
3131
throw new EtcdConfigurationException($"`{configurationSectionName}` configuration section is missing");
3232

3333
ConnectionString = section[nameof(ConnectionString)] ?? throw new EtcdConfigurationException($"'{nameof(ConnectionString)}' is missing in configuration");
34-
CertificateData = section[nameof(CertificateData)];
3534
}
3635

3736
/// <summary>
@@ -41,12 +40,4 @@ public ConfigurationBasedEtcdSettings(IConfiguration configuration, string confi
4140
/// The connection string.
4241
/// </value>
4342
public string ConnectionString { get; }
44-
45-
/// <summary>
46-
/// Gets the certificate data.
47-
/// </summary>
48-
/// <value>
49-
/// The certificate data.
50-
/// </value>
51-
public string? CertificateData { get; }
5243
}

src/Etcd.Microsoft.Extensions.Configuration/Settings/EnvironmentSettingsFactory.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,5 @@ public class EnvironmentSettingsFactory
99
/// Creates this instance.
1010
/// </summary>
1111
/// <returns></returns>
12-
public static IEtcdSettings Create() =>
13-
new EtcdSettings(EtcdApplicationEnvironment.ConnectionString,
14-
!string.IsNullOrEmpty(EtcdApplicationEnvironment.CaCertificateFilePath)
15-
? EtcdApplicationEnvironment.GetCaCertificateData()
16-
: null);
12+
public static IEtcdSettings Create() => new EtcdSettings(EtcdApplicationEnvironment.ConnectionString);
1713
}

0 commit comments

Comments
 (0)