-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Placeholder/encryption configuration refactorings (#1354)
* Placeholder/encryption configuration refactorings # Placeholder/encryption configuration providers - Extract duplicate code from configuration sources/providers - Fix reloading and change notification when binding to options - Remove special-cased code paths for `ConfigurationManager` (no longer needed) - Add trace-level logging, using source generator - Refactor internal methods to recursively search through configuration sources/providers and update call sites - Wire `Configuration.Encryption` from `AddSteeltoe` in Bootstrap ## Placeholder - Fixes in placeholder substitution when using '.' (Spring-style) key separator with default value ## Encryption - Rename various types and methods containing Encrypt* that actually decrypt. - Remove `IConfiguration` extension methods, lazily create decryptor from loaded configuration - Fix regex used in decryption, tweak its options, and use source generator ## Config Server - Change: Do not implicitly add placeholder anymore; nesting of placeholder/encryption depends on what the user needs - Remove duplicate tests # Env actuator (Management) - Fix host configuration from not being included in the response - Include an empty placeholder/encryption property source in the response when used * Review feedback: rename variables * Update src/Configuration/src/Placeholder/PropertyPlaceHolderHelper.cs Co-authored-by: Tim Hess <[email protected]> --------- Co-authored-by: Tim Hess <[email protected]>
- Loading branch information
1 parent
50b22fa
commit 44602e7
Showing
115 changed files
with
2,157 additions
and
3,865 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
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
146 changes: 146 additions & 0 deletions
146
src/Configuration/src/Abstractions/CompositeConfigurationProvider.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,146 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace Steeltoe.Configuration; | ||
|
||
internal abstract partial class CompositeConfigurationProvider : IConfigurationProvider, IDisposable | ||
{ | ||
private readonly IList<IConfigurationProvider> _providers; | ||
private readonly ILogger<CompositeConfigurationProvider> _logger; | ||
private bool _isDisposed; | ||
|
||
protected internal IConfigurationRoot? ConfigurationRoot { get; private set; } | ||
|
||
protected CompositeConfigurationProvider(IList<IConfigurationProvider> providers, ILoggerFactory loggerFactory) | ||
{ | ||
ArgumentNullException.ThrowIfNull(providers); | ||
ArgumentNullException.ThrowIfNull(loggerFactory); | ||
|
||
_providers = providers; | ||
_logger = loggerFactory.CreateLogger<CompositeConfigurationProvider>(); | ||
} | ||
|
||
public IChangeToken GetReloadToken() | ||
{ | ||
LogGetReloadToken(GetType().Name); | ||
return ConfigurationRoot?.GetReloadToken()!; | ||
} | ||
|
||
public void Load() | ||
{ | ||
Load(ConfigurationRoot != null); | ||
} | ||
|
||
private void Load(bool isReload) | ||
{ | ||
LogLoad(GetType().Name, isReload); | ||
|
||
if (isReload) | ||
{ | ||
ConfigurationRoot!.Reload(); | ||
} | ||
else | ||
{ | ||
LogCreateConfigurationRoot(GetType().Name, _providers.Count); | ||
ConfigurationRoot = new ConfigurationRoot(_providers); | ||
} | ||
} | ||
|
||
public IEnumerable<string> GetChildKeys(IEnumerable<string> earlierKeys, string? parentPath) | ||
{ | ||
string[] earlierKeysArray = earlierKeys as string[] ?? earlierKeys.ToArray(); | ||
#pragma warning disable S3236 // Caller information arguments should not be provided explicitly | ||
ArgumentNullException.ThrowIfNull(earlierKeysArray, nameof(earlierKeys)); | ||
#pragma warning restore S3236 // Caller information arguments should not be provided explicitly | ||
|
||
LogGetChildKeys(GetType().Name, earlierKeysArray, parentPath); | ||
|
||
IConfiguration? section = parentPath == null ? ConfigurationRoot : ConfigurationRoot?.GetSection(parentPath); | ||
|
||
if (section == null) | ||
{ | ||
return earlierKeysArray; | ||
} | ||
|
||
List<string> keys = []; | ||
keys.AddRange(section.GetChildren().Select(child => child.Key)); | ||
keys.AddRange(earlierKeysArray); | ||
keys.Sort(ConfigurationKeyComparer.Instance); | ||
return keys; | ||
} | ||
|
||
public virtual bool TryGet(string key, out string? value) | ||
{ | ||
ArgumentNullException.ThrowIfNull(key); | ||
|
||
LogTryGet(GetType().Name, key); | ||
|
||
value = ConfigurationRoot?.GetValue<string>(key); | ||
bool found = value != null; | ||
|
||
if (found) | ||
{ | ||
LogTryGetFound(GetType().Name, key, value!); | ||
} | ||
|
||
return found; | ||
} | ||
|
||
public void Set(string key, string? value) | ||
{ | ||
ArgumentNullException.ThrowIfNull(key); | ||
|
||
LogSet(GetType().Name, key, value); | ||
|
||
if (ConfigurationRoot != null) | ||
{ | ||
ConfigurationRoot[key] = value; | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (disposing && !_isDisposed && ConfigurationRoot is IDisposable disposable) | ||
{ | ||
_isDisposed = true; | ||
|
||
LogDispose(GetType().Name); | ||
disposable.Dispose(); | ||
} | ||
} | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "GetReloadToken from {Type}.")] | ||
private partial void LogGetReloadToken(string type); | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "Load from {Type} with isReload {IsReload}.")] | ||
private partial void LogLoad(string type, bool isReload); | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "CreateConfigurationRoot from {Type} with {ProviderCount} providers.")] | ||
private partial void LogCreateConfigurationRoot(string type, int providerCount); | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "GetChildKeys from {Type} with earlierKeys [{EarlierKeys}] and parentPath '{ParentPath}'.")] | ||
private partial void LogGetChildKeys(string type, string[] earlierKeys, string? parentPath); | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "TryGet from {Type} with key '{Key}'.")] | ||
private partial void LogTryGet(string type, string key); | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "TryGet from {Type} with key '{Key}' found value '{Value}'.")] | ||
private partial void LogTryGetFound(string type, string key, string value); | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "Set from {Type} with key '{Key}' and value '{Value}'.")] | ||
private partial void LogSet(string type, string key, string? value); | ||
|
||
[LoggerMessage(Level = LogLevel.Trace, Message = "Dispose from {Type}.")] | ||
private partial void LogDispose(string type); | ||
} |
67 changes: 0 additions & 67 deletions
67
src/Configuration/src/Abstractions/ConfigurationExtensions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.