-
Notifications
You must be signed in to change notification settings - Fork 279
Update variable replacement during deserialization to use replacement settings class and add AKV replacement logic. #2882
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
Draft
aaronburtle
wants to merge
12
commits into
main
Choose a base branch
from
dev/aaronburtle/AKVReplacement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2fc665d
allow unused cache-control options without error
aaronburtle 50e54aa
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle 455ff18
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle e0574bf
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle 033eeb0
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle c7ad08f
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle 049b23e
...
aaronburtle cfdc2b5
extend variable replacment and include AKV
aaronburtle 5eb9f0e
change some logic for first pass var replacement
aaronburtle bbcc159
fix old bools being used
aaronburtle f6f92bd
more bool replacements
aaronburtle 0dd7ad6
refactor out bools
aaronburtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -12,9 +12,8 @@ namespace Azure.DataApiBuilder.Config.Converters; | |
/// </summary> | ||
internal class AKVRetryPolicyOptionsConverterFactory : JsonConverterFactory | ||
{ | ||
// Determines whether to replace environment variable with its | ||
// value or not while deserializing. | ||
private bool _replaceEnvVar; | ||
// Settings for variable replacement during deserialization. | ||
private readonly DeserializationVariableReplacementSettings? _replacementSettings; | ||
|
||
/// <inheritdoc/> | ||
public override bool CanConvert(Type typeToConvert) | ||
|
@@ -25,27 +24,26 @@ public override bool CanConvert(Type typeToConvert) | |
/// <inheritdoc/> | ||
public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return new AKVRetryPolicyOptionsConverter(_replaceEnvVar); | ||
return new AKVRetryPolicyOptionsConverter(_replacementSettings); | ||
} | ||
|
||
/// <param name="replaceEnvVar">Whether to replace environment variable with its | ||
/// value or not while deserializing.</param> | ||
internal AKVRetryPolicyOptionsConverterFactory(bool replaceEnvVar) | ||
/// <param name="replacementSettings">Settings for variable replacement during deserialization. | ||
/// If null, no variable replacement will be performed.</param> | ||
internal AKVRetryPolicyOptionsConverterFactory(DeserializationVariableReplacementSettings? replacementSettings = null) | ||
{ | ||
_replaceEnvVar = replaceEnvVar; | ||
_replacementSettings = replacementSettings; | ||
} | ||
|
||
private class AKVRetryPolicyOptionsConverter : JsonConverter<AKVRetryPolicyOptions> | ||
{ | ||
// Determines whether to replace environment variable with its | ||
// value or not while deserializing. | ||
private bool _replaceEnvVar; | ||
// Settings for variable replacement during deserialization. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as comment above, this applies to all the places where the variable type was changed |
||
private readonly DeserializationVariableReplacementSettings? _replacementSettings; | ||
|
||
/// <param name="replaceEnvVar">Whether to replace environment variable with its | ||
/// value or not while deserializing.</param> | ||
public AKVRetryPolicyOptionsConverter(bool replaceEnvVar) | ||
/// <param name="replacementSettings">Settings for variable replacement during deserialization. | ||
/// If null, no variable replacement will be performed.</param> | ||
public AKVRetryPolicyOptionsConverter(DeserializationVariableReplacementSettings? replacementSettings) | ||
{ | ||
_replaceEnvVar = replaceEnvVar; | ||
_replacementSettings = replacementSettings; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -82,7 +80,7 @@ public AKVRetryPolicyOptionsConverter(bool replaceEnvVar) | |
} | ||
else | ||
{ | ||
mode = EnumExtensions.Deserialize<AKVRetryPolicyMode>(reader.DeserializeString(_replaceEnvVar)!); | ||
mode = EnumExtensions.Deserialize<AKVRetryPolicyMode>(reader.DeserializeString(_replacementSettings)!); | ||
} | ||
|
||
break; | ||
|
113 changes: 113 additions & 0 deletions
113
src/Config/Converters/AzureKeyVaultOptionsConverterFactory.cs
This file contains hidden or 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,113 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Azure.DataApiBuilder.Config.ObjectModel; | ||
|
||
namespace Azure.DataApiBuilder.Config.Converters; | ||
|
||
/// <summary> | ||
/// Converter factory for AzureKeyVaultOptions that can optionally perform variable replacement. | ||
/// </summary> | ||
internal class AzureKeyVaultOptionsConverterFactory : JsonConverterFactory | ||
{ | ||
// Determines whether to replace environment variable with its | ||
// value or not while deserializing. | ||
private readonly DeserializationVariableReplacementSettings? _replacementSettings; | ||
|
||
/// <param name="replaceEnvVar">Whether to replace environment variable with its | ||
/// value or not while deserializing.</param> | ||
internal AzureKeyVaultOptionsConverterFactory(DeserializationVariableReplacementSettings? replacementSettings = null) | ||
{ | ||
_replacementSettings = replacementSettings; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override bool CanConvert(Type typeToConvert) | ||
{ | ||
return typeToConvert.IsAssignableTo(typeof(AzureKeyVaultOptions)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return new AzureKeyVaultOptionsConverter(_replacementSettings); | ||
} | ||
|
||
private class AzureKeyVaultOptionsConverter : JsonConverter<AzureKeyVaultOptions> | ||
{ | ||
// Determines whether to replace environment variable with its | ||
// value or not while deserializing. | ||
private readonly DeserializationVariableReplacementSettings? _replacementSettings; | ||
|
||
/// <param name="replaceEnvVar">Whether to replace environment variable with its | ||
/// value or not while deserializing.</param> | ||
public AzureKeyVaultOptionsConverter(DeserializationVariableReplacementSettings? replacementSettings) | ||
{ | ||
_replacementSettings = replacementSettings; | ||
} | ||
|
||
/// <summary> | ||
/// Reads AzureKeyVaultOptions with optional variable replacement. | ||
/// </summary> | ||
public override AzureKeyVaultOptions? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType is JsonTokenType.StartObject) | ||
{ | ||
string? endpoint = null; | ||
AKVRetryPolicyOptions? retryPolicy = null; | ||
|
||
while (reader.Read()) | ||
{ | ||
if (reader.TokenType is JsonTokenType.EndObject) | ||
{ | ||
return new AzureKeyVaultOptions | ||
{ | ||
Endpoint = endpoint, | ||
RetryPolicy = retryPolicy | ||
}; | ||
} | ||
|
||
string? property = reader.GetString(); | ||
reader.Read(); | ||
|
||
switch (property) | ||
{ | ||
case "endpoint": | ||
if (reader.TokenType is JsonTokenType.String) | ||
{ | ||
endpoint = reader.DeserializeString(_replacementSettings); | ||
} | ||
|
||
break; | ||
|
||
case "retry-policy": | ||
if (reader.TokenType is JsonTokenType.StartObject) | ||
{ | ||
// Pass the replaceEnvVar setting to the retry policy converter | ||
retryPolicy = JsonSerializer.Deserialize<AKVRetryPolicyOptions>(ref reader, options); | ||
} | ||
|
||
break; | ||
|
||
default: | ||
reader.Skip(); | ||
break; | ||
} | ||
} | ||
} | ||
else if (reader.TokenType is JsonTokenType.Null) | ||
{ | ||
return null; | ||
} | ||
|
||
throw new JsonException("Invalid AzureKeyVaultOptions format"); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, AzureKeyVaultOptions value, JsonSerializerOptions options) | ||
{ | ||
JsonSerializer.Serialize(writer, value, options); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make the comment a bit more descriptive, to show that it can replace the variable with either AKV, an environment variable, or nothing during deserialization.