-
Notifications
You must be signed in to change notification settings - Fork 285
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
Open
aaronburtle
wants to merge
42
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.
Open
Changes from all commits
Commits
Show all changes
42 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 802eb53
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle 4e71c25
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle ac4356e
addressing comments
aaronburtle c3dabe3
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle 6e77297
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle 3254af5
update names
aaronburtle b28cd6b
cleanup with fix
aaronburtle 5e79339
cleanup
aaronburtle fa6582b
format, cleanup
aaronburtle b761333
Update src/Config/RuntimeConfigLoader.cs
aaronburtle 9411180
Update src/Config/DeserializationVariableReplacementSettings.cs
aaronburtle 890e2c6
Update src/Config/Converters/DatasourceHealthOptionsConvertorFactory.cs
aaronburtle 9af3a4c
Update src/Config/Converters/DatasourceHealthOptionsConvertorFactory.cs
aaronburtle 11318c6
Update src/Config/Converters/EntityCacheOptionsConverterFactory.cs
aaronburtle b9ef8f9
Update src/Config/Converters/EntityCacheOptionsConverterFactory.cs
aaronburtle 3b1d682
Update src/Config/Converters/StringJsonConverterFactory.cs
aaronburtle 15abe47
Update src/Config/Converters/McpRuntimeOptionsConverterFactory.cs
aaronburtle da9d974
Update src/Config/Converters/RuntimeHealthOptionsConvertorFactory.cs
aaronburtle 3bde74c
Update src/Config/Converters/RuntimeHealthOptionsConvertorFactory.cs
aaronburtle 025cbc3
format
aaronburtle 1c6f020
remove last vestigates of replaceEnvVar
aaronburtle 9a14dc3
format
aaronburtle 4f38f92
format
aaronburtle 4742669
using ordering
aaronburtle 6b73688
Merge branch 'main' of github.com:Azure/data-api-builder
aaronburtle 97fdc69
Merge branch 'main' into dev/aaronburtle/AKVReplacement
aaronburtle 10855d0
removed unused null check
aaronburtle a172a16
address comments
aaronburtle 8b8d2de
default to false
aaronburtle 3e0f78b
Merge branch 'main' into dev/aaronburtle/AKVReplacement
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
128 changes: 128 additions & 0 deletions
128
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,128 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Azure.DataApiBuilder.Config.ObjectModel; | ||
aaronburtle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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="replacementSettings">How to handle variable replacement during deserialization.</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 | ||
aaronburtle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// 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.Null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| 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, 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) | ||
| { | ||
| // Uses the AKVRetryPolicyOptionsConverter to read the retry-policy object. | ||
| retryPolicy = JsonSerializer.Deserialize<AKVRetryPolicyOptions>(ref reader, options); | ||
| } | ||
|
|
||
| break; | ||
|
|
||
| default: | ||
| throw new JsonException($"Unexpected property {property}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new JsonException("Invalid AzureKeyVaultOptions format"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// When writing the AzureKeyVaultOptions back to a JSON file, only write the properties | ||
| /// if they are user provided. This avoids polluting the written JSON file with properties | ||
| /// the user most likely omitted when writing the original DAB runtime config file. | ||
| /// This Write operation is only used when a RuntimeConfig object is serialized to JSON. | ||
| /// </summary> | ||
| public override void Write(Utf8JsonWriter writer, AzureKeyVaultOptions value, JsonSerializerOptions options) | ||
aaronburtle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| writer.WriteStartObject(); | ||
|
|
||
| if (value?.UserProvidedEndpoint is true) | ||
| { | ||
| writer.WritePropertyName("endpoint"); | ||
| JsonSerializer.Serialize(writer, value.Endpoint, options); | ||
| } | ||
|
|
||
| if (value?.UserProvidedRetryPolicy is true) | ||
| { | ||
| writer.WritePropertyName("retry-policy"); | ||
| JsonSerializer.Serialize(writer, value.RetryPolicy, options); | ||
| } | ||
|
|
||
| writer.WriteEndObject(); | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.