-
Notifications
You must be signed in to change notification settings - Fork 3k
Azure App Configuration Provider Beta #26016
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
137 commits
Select commit
Hold shift + click to select a range
0b71864
Adding azure-appconfiguration-provider
mrm9084 95e8f80
Fixing repo issue
mrm9084 7085b93
Fixing repo issue
mrm9084 2c49e9d
Updated to setup user agent and header info
mrm9084 c6895e9
Updating to cache secret_clients
mrm9084 9f1cc57
Fixed Naming
mrm9084 9a86e7b
Fixed Typo
mrm9084 5e3d409
Added Samples, Fixed issue with Key Vault Options not set when secret…
mrm9084 6ac7714
Fixed SP, Dependency, and Pylint issues
mrm9084 649e6fd
Fixed more lint issues, moved key vault references to be a method
mrm9084 ffd2d62
More Linting fixes
mrm9084 84dd770
Fixing dependency issues with build
mrm9084 31d2318
Updated Docs. Fixed extra code for Key Vault Usage. Updated Readme to…
mrm9084 0aa7e99
Adding Test Case, currently doesn't work
mrm9084 0aa91a5
Fixing Tests
mrm9084 68e20d7
Fixing Trim. Fixing Typo in readme.
mrm9084 7ca6cd3
Fixing Length and vault_url issues.
mrm9084 2c8bb78
Updating from code review comments
mrm9084 f7e3929
Added more error checking. Made Key_VAULT_SECRET_PREFIX a constant.
mrm9084 ef7a7f5
Updated to use Key Vault Identifier.
mrm9084 cbf2acb
Fixed Spelling
mrm9084 047d526
Updated Test
mrm9084 f379833
Reworked key vault reference resolution. Fixed lint issues.
mrm9084 dcb6cf7
Fixing Lint Issue. Updating Test Running
mrm9084 a0c6cb8
Fixing Tests
mrm9084 4dd0831
Fixed Tests?
mrm9084 d7ae7dd
Setting secret clients to {} if none. Adding override to shared_requi…
mrm9084 ce5863f
Merge branch 'Azure:main' into main
mrm9084 17b46ba
Merge branch 'main' of github.com:mrm9084/azure-sdk-for-python
mrm9084 3dcb5d4
Updating shared requirements
mrm9084 821cd09
Fixed override. Switched to SecretReferenceConfigurationSetting
mrm9084 22a7716
Updated Requirement KeyVaultSecretIdentifier is needed.
mrm9084 f67503c
Update ci.yml
mrm9084 34f274d
Update ci.yml
mrm9084 ceab535
Fixed structure
mrm9084 d9e75a6
Update dev_requirements.txt
mrm9084 8407fbc
Update sdk_packaging.toml
mrm9084 6ce62f5
Revert working state
mrm9084 95e5d30
Renamed correctly
mrm9084 1002b68
Merge branch 'main' into main
mrm9084 fdc6e98
Using azure-appconfigurationprovider
mrm9084 2e390e9
Merge branch 'main' of github.com:mrm9084/azure-sdk-for-python
mrm9084 e6d65fb
Fixing shared Requirements merge issue
mrm9084 4a6b17c
Updated from review comments
mrm9084 76c4fb9
Fixing package folder
mrm9084 5c2d30e
Fix lint, removed extra fixture
mrm9084 9171668
Create py.typed
mrm9084 f81281c
Updated Manifest to use right py.typed file
mrm9084 740ba65
Switched Files
mrm9084 7a436aa
Fixing lint issue
mrm9084 3d0a7e9
Setting defaults for test
mrm9084 b8faf09
Updating Docs
mrm9084 8efbc43
Fixing Whitespace
mrm9084 b2cc043
Updating to support in operation
mrm9084 e6619bd
Updated sample with in usage
mrm9084 176673a
Cleaned up key trimming usage
mrm9084 dfd6fac
Removed extra catches for now. Cleaned up lint.
mrm9084 b2bfbff
Adding more tests
mrm9084 75bc7e2
Fixed Linting
mrm9084 9639c96
Fixing Auto Format
mrm9084 2f07a55
Fixing Key Vault Reference Test
mrm9084 560be04
Trying to update the package name
mrm9084 f340a5e
Fixed formatting?
mrm9084 dc943c3
Adding azure-appconfiguration-provider
mrm9084 e8dec63
Fixing repo issue
mrm9084 9e889d0
Fixing repo issue
mrm9084 c3b56e5
Updated to setup user agent and header info
mrm9084 86cd913
Updating to cache secret_clients
mrm9084 1220f9d
Fixed Naming
mrm9084 9e48429
Fixed Typo
mrm9084 0b15d1a
Added Samples, Fixed issue with Key Vault Options not set when secret…
mrm9084 8aa4762
Fixed SP, Dependency, and Pylint issues
mrm9084 4fdfb56
Fixed more lint issues, moved key vault references to be a method
mrm9084 b87beee
More Linting fixes
mrm9084 b237292
Fixing dependency issues with build
mrm9084 8335a1a
Updated Docs. Fixed extra code for Key Vault Usage. Updated Readme to…
mrm9084 b097b0f
Adding Test Case, currently doesn't work
mrm9084 1f57085
Fixing Tests
mrm9084 2bd138e
Fixing Trim. Fixing Typo in readme.
mrm9084 14487de
Fixing Length and vault_url issues.
mrm9084 262ba3d
Updating from code review comments
mrm9084 8dec35a
Added more error checking. Made Key_VAULT_SECRET_PREFIX a constant.
mrm9084 cd5af67
Updated to use Key Vault Identifier.
mrm9084 5c888b4
Fixed Spelling
mrm9084 689487f
Updated Test
mrm9084 9f0d7c7
Reworked key vault reference resolution. Fixed lint issues.
mrm9084 4e977ae
Fixing Lint Issue. Updating Test Running
mrm9084 9d0b579
Fixing Tests
mrm9084 47127bf
Fixed Tests?
mrm9084 5aa01d1
Setting secret clients to {} if none. Adding override to shared_requi…
mrm9084 cb71779
Updating shared requirements
mrm9084 ac8aa14
Fixed override. Switched to SecretReferenceConfigurationSetting
mrm9084 6590ae3
Updated Requirement KeyVaultSecretIdentifier is needed.
mrm9084 0fdaab5
Update ci.yml
mrm9084 a325123
Update ci.yml
mrm9084 ffa7a78
Fixed structure
mrm9084 87cf458
Update dev_requirements.txt
mrm9084 fe5944f
Update sdk_packaging.toml
mrm9084 bc9e941
Revert working state
mrm9084 f776454
Renamed correctly
mrm9084 d585fcd
Using azure-appconfigurationprovider
mrm9084 5a3f340
Fixing shared Requirements merge issue
mrm9084 4af6180
Updated from review comments
mrm9084 20937c8
Fixing package folder
mrm9084 6ea9f72
Fix lint, removed extra fixture
mrm9084 3157ec4
Create py.typed
mrm9084 e967499
Updated Manifest to use right py.typed file
mrm9084 c98f1f8
Switched Files
mrm9084 c794d46
Fixing lint issue
mrm9084 39eacba
Setting defaults for test
mrm9084 23d6fb9
Updating Docs
mrm9084 8c4bc04
Fixing Whitespace
mrm9084 9b33797
Updating to support in operation
mrm9084 682bd2c
Updated sample with in usage
mrm9084 22636cd
Cleaned up key trimming usage
mrm9084 784ffee
Removed extra catches for now. Cleaned up lint.
mrm9084 1bedd5a
Adding more tests
mrm9084 d28b57e
Fixed Linting
mrm9084 9da907d
Fixing Auto Format
mrm9084 f46b1ab
Fixing Key Vault Reference Test
mrm9084 a1feea8
Trying to update the package name
mrm9084 a807121
Merge branch 'main' of github.com:mrm9084/azure-sdk-for-python
mrm9084 abcd3d8
Merge branch 'Azure:main' into main
mrm9084 e1bd5b4
Removing Extra TestProxy
mrm9084 16c3795
Not -e installing azure-appconfiguration
mrm9084 acf1b9c
updates
xiangyan99 bea39b8
update
xiangyan99 9aea9e4
update
xiangyan99 601470f
Update sdk/appconfiguration/azure-appconfiguration-provider/setup.py
xiangyan99 b515416
update
xiangyan99 bf82613
Merge branch 'main' of https://github.com/mrm9084/azure-sdk-for-python
xiangyan99 5802867
Updated min version of app config
mrm9084 3290b6f
Updating sanitizer
mrm9084 b232b93
Merge branch 'main' of github.com:mrm9084/azure-sdk-for-python
mrm9084 16cabad
Updating Shared Requirement
mrm9084 fb4bc3a
Temp removing key vault test
mrm9084 7404333
Removing actual tests
mrm9084 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
20 changes: 20 additions & 0 deletions
20
sdk/appconfiguration/azure-appconfiguration-provider/CHANGELOG.md
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,20 @@ | ||
# Release History | ||
|
||
## 1.0.0b1 (Unreleased) | ||
|
||
New Azure App Configuration Provider | ||
|
||
Provides additional support above the Azure App Configuration SDK. Enables: | ||
* Connecting to an Azure App Configuration store | ||
* Selecting multiple keys using Setting Selector | ||
* Resolve Key Vault References when supplied AzureAppConfigurationKeyVaultOptions | ||
|
||
The Azure App Configuration Provider once loaded returns a dictionary of key/value pairs to use in configuration. | ||
|
||
```python | ||
endpoint = "https://<your-store>.azconfig.io" | ||
default_credential = DefaultAzureCredential() | ||
config = AzureAppConfigurationProvider.load( | ||
endpoint=endpoint, credential=default_credential) | ||
print(config["message"]) | ||
``` |
21 changes: 21 additions & 0 deletions
21
sdk/appconfiguration/azure-appconfiguration-provider/LICENSE
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,21 @@ | ||
Copyright (c) Microsoft Corporation. | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
7 changes: 7 additions & 0 deletions
7
sdk/appconfiguration/azure-appconfiguration-provider/MANIFEST.in
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,7 @@ | ||
recursive-include tests *.py | ||
include *.md | ||
include LICENSE | ||
include azure/__init__.py | ||
recursive-include samples *.py *.md | ||
recursive-include doc *.rst | ||
include azure/appconfiguration/py.typed | ||
121 changes: 121 additions & 0 deletions
121
sdk/appconfiguration/azure-appconfiguration-provider/README.md
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,121 @@ | ||
# Azure App Configuration Python Provider client library for Python | ||
|
||
Azure App Configuration is a managed service that helps developers centralize their application configurations simply and securely. This provider adds additional functionality above the azure-sdk-for-python. | ||
|
||
Using the provider enables loading sets of configurations from a Azure App Configuration store in a managed way. | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Getting started | ||
|
||
### Get credentials | ||
|
||
Use the [Azure CLI][azure_cli] snippet below to get the connection string from the Configuration Store. | ||
|
||
```Powershell | ||
az appconfig credential list --name <config-store-name> | ||
``` | ||
|
||
Alternatively, get the connection string from the Azure Portal. | ||
|
||
### Creating a provider | ||
|
||
You can create a client with a connection string: | ||
|
||
```python | ||
config = AzureAppConfigurationProvider.load(connection_string="your-connection-string") | ||
``` | ||
|
||
or with AAD: | ||
|
||
```python | ||
config = AzureAppConfigurationProvider.load(endpoint="your-endpoint", credential=DefaultAzureCredential()) | ||
``` | ||
|
||
these providers will by default load all configurations with `(No Label)` from your configuration store. | ||
|
||
## Examples | ||
|
||
### Selecting configurations | ||
|
||
You can refine or expand the configurations loaded from your store by using `SettingSelector`s. Setting selectors provide a way to pass a key filter and label filter into the provider. | ||
|
||
```python | ||
selects = {SettingSelector(key_filter="*", label_filter="\0"), SettingSelector(key_filter="*", label_filter="dev")} | ||
config = AzureAppConfigurationProvider.load( | ||
endpoint=endpoint, credential=default_credential, selects=selects) | ||
``` | ||
In this example all configuration with empty label and the dev label are loaded. Because the dev selector is listed last, any configurations from dev take priority over those with `(No Label)` when duplicates are found. | ||
|
||
### Trimming Keys | ||
|
||
You can trim the prefix off of keys by providing a list of trimmed key prefixes to the provider. | ||
|
||
```python | ||
trimmed_key_prefixes={"/application/"} | ||
config = AzureAppConfigurationProvider.load( | ||
endpoint=endpoint, credential=default_credential, trimmed_key_prefixes=trimmed_key_prefixes) | ||
``` | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Resolving Key Vault References | ||
|
||
Key Vault References can be resolved by providing credentials to your key vault to the provider using `AzureAppConfigurationKeyVaultOptions`. | ||
|
||
#### With Credentials | ||
|
||
You can provide `AzureAppConfigurationKeyVaultOptions` with a credential and all key vault references will be resolved with it. The provider will attempt to connect to any key vault referenced with the credential provided. | ||
|
||
```python | ||
key_vault_options = AzureAppConfigurationKeyVaultOptions(credential=default_credential) | ||
config = AzureAppConfigurationProvider.load(endpoint=endpoint, credential=default_credential, key_vault_options=key_vault_options) | ||
``` | ||
### With Clients | ||
|
||
You can provide `AzureAppConfigurationKeyVaultOptions` with a list of `SecretClients`. | ||
|
||
```python | ||
key_vault_options = AzureAppConfigurationKeyVaultOptions( | ||
secret_clients={SecretClient( | ||
vault_url=key_vault_uri, credential=default_credential)}) | ||
config = AzureAppConfigurationProvider.load(endpoint=endpoint, credential=default_credential, key_vault_options=key_vault_options) | ||
``` | ||
|
||
### Secret Resolver | ||
|
||
If no Credentials or Clients are provided a secret resolver can be used. Secret resolver provides a way to return any value you want to a key vault reference. | ||
|
||
```python | ||
def secret_resolver(uri): | ||
return "From Secret Resolver" | ||
|
||
key_vault_options = AzureAppConfigurationKeyVaultOptions( | ||
secret_resolver=secret_resolver) | ||
config = AzureAppConfigurationProvider.load( | ||
endpoint=endpoint, credential=default_credential, key_vault_options=key_vault_options) | ||
``` | ||
|
||
## Key concepts | ||
|
||
## Troubleshooting | ||
|
||
## Next steps | ||
|
||
## Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require | ||
you to agree to a Contributor License Agreement (CLA) declaring that you have | ||
the right to, and actually do, grant us the rights to use your contribution. | ||
For details, visit https://cla.microsoft.com. | ||
|
||
When you submit a pull request, a CLA-bot will automatically determine whether | ||
you need to provide a CLA and decorate the PR appropriately (e.g., label, | ||
comment). Simply follow the instructions provided by the bot. You will only | ||
need to do this once across all repos using our CLA. | ||
|
||
This project has adopted the | ||
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information, | ||
see the Code of Conduct FAQ or contact [email protected] with any | ||
additional questions or comments. | ||
|
||
[cla]: https://cla.microsoft.com | ||
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ | ||
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ | ||
[coc_contact]: mailto:[email protected] |
2 changes: 2 additions & 0 deletions
2
sdk/appconfiguration/azure-appconfiguration-provider/azure/__init__.py
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,2 @@ | ||
__path__ = __import__("pkgutil").extend_path( | ||
__path__, __name__) # type: ignore |
22 changes: 22 additions & 0 deletions
22
...pconfiguration/azure-appconfiguration-provider/azure/appconfigurationprovider/__init__.py
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,22 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
from ._azureappconfigurationprovider import AzureAppConfigurationProvider | ||
from ._azureappconfigurationkeyvaultoptions import AzureAppConfigurationKeyVaultOptions | ||
from ._settingselector import SettingSelector | ||
|
||
from ._version import VERSION | ||
|
||
__version__ = VERSION | ||
__all__ = [ | ||
"AzureAppConfigurationProvider", | ||
"AzureAppConfigurationKeyVaultOptions", | ||
"SettingSelector" | ||
] |
15 changes: 15 additions & 0 deletions
15
...guration-provider/azure/appconfigurationprovider/_azureappconfigurationkeyvaultoptions.py
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,15 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
class AzureAppConfigurationKeyVaultOptions: | ||
|
||
def __init__(self, credential=None, secret_clients=None, secret_resolver=None): | ||
""" | ||
credential, secret_clients (clients for connecting to multiple key vaults with different credentials), | ||
secret_resolver | ||
""" | ||
self.credential = credential | ||
self.secret_clients = secret_clients | ||
self.secret_resolver = secret_resolver |
155 changes: 155 additions & 0 deletions
155
...ppconfiguration-provider/azure/appconfigurationprovider/_azureappconfigurationprovider.py
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,155 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
from urllib.parse import urlparse | ||
import json | ||
import warnings | ||
from azure.appconfiguration import AzureAppConfigurationClient | ||
from azure.keyvault.secrets import SecretClient | ||
from ._settingselector import SettingSelector | ||
from ._user_agent import USER_AGENT | ||
|
||
|
||
class AzureAppConfigurationProvider: | ||
|
||
def __init__(self): | ||
self._dict = {} | ||
self._trim_prefixes = [] | ||
self._client = None | ||
|
||
@classmethod | ||
def load(cls, connection_string=None, endpoint=None, credential=None, **kwargs): | ||
""" | ||
Requires either a connection-string, or an Endpoint with a Credential. Loads the selected configuration | ||
settings into itself for usage. | ||
Optional parameters: | ||
selectors (List of SettingSelector for selecting which applicationconfiguration settings to load),. If not | ||
specified, all key-values with the empty label will be loaded. | ||
trimmed_key_prefixes (remove prefixes in key name, list of what to trim), | ||
key_vault_options (Configurations for connecting to Key Vault(s)) | ||
""" | ||
provider = AzureAppConfigurationProvider() | ||
|
||
key_vault_options = kwargs.pop("key_vault_options", None) | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
provider.buildprovider(connection_string, endpoint, | ||
credential, key_vault_options) | ||
|
||
selects = kwargs.pop("selects", {SettingSelector("*", "\0")}) | ||
provider._trim_prefixes = kwargs.pop("trimmed_key_prefixes", []) | ||
|
||
provider._dict = {} | ||
secret_clients = {} | ||
|
||
for select in selects: | ||
configurations = provider._client.list_configuration_settings( | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
key_filter=select.key_filter, label_filter=select.label_filter) | ||
for config in configurations: | ||
if config.content_type is None: | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Deals with possible null value via Rest API | ||
provider._dict[provider.trim(config.key)] = config.value | ||
elif config.content_type == "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8": | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
provider.resolve_keyvault_references( | ||
config, key_vault_options, secret_clients) | ||
elif "application/json" in config.content_type: | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
j_object = json.loads(config.value) | ||
provider._dict[provider.trim(config.key)] = j_object | ||
else: | ||
provider._dict[provider.trim(config.key)] = config.value | ||
return provider | ||
|
||
def buildprovider(self, connection_string, endpoint, credential, key_vault_options): | ||
usesKeyVault = False | ||
|
||
if (key_vault_options is not None and | ||
(key_vault_options.credential is not None or key_vault_options.secret_clients is not None or | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
key_vault_options.secret_resolver is not None)): | ||
usesKeyVault = True | ||
|
||
headers = {} | ||
correlation_context = "RequestType=Startup" | ||
|
||
if usesKeyVault: | ||
correlation_context += ",UsesKeyVault" | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
headers["Correlation-Context"] = correlation_context | ||
useragent = USER_AGENT | ||
|
||
if connection_string is not None: | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._client = AzureAppConfigurationClient.from_connection_string( | ||
connection_string, user_agent=useragent, headers=headers) | ||
return | ||
self._client = AzureAppConfigurationClient( | ||
endpoint, credential, user_agent=useragent, headers=headers) | ||
|
||
def resolve_keyvault_references(self, config, key_vault_options, secret_clients): | ||
if key_vault_options is None: | ||
warnings.warn( | ||
"Key Vault Reference found, but no Key Vault Options were provided") | ||
return | ||
j_object = json.loads(config.value) | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uri_value = j_object['uri'] | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
uri = urlparse(uri_value) | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
key_vault_uri = "https://" + uri.hostname | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
key_vault_secret_prefix = "/secrets/" | ||
key_vault_secret_name = uri.path[len( | ||
key_vault_secret_prefix):] | ||
if key_vault_options.credential is not None: | ||
secret_client = None | ||
|
||
# Clients only should be made once, will reuse if client already made | ||
for client_uri in secret_clients: | ||
if client_uri == key_vault_uri: | ||
secret_client = secret_clients[client_uri] | ||
break | ||
if secret_client is None: | ||
secret_client = SecretClient( | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vault_url=key_vault_uri, credential=key_vault_options.credential) | ||
secret_clients[key_vault_uri] = secret_client | ||
secret = secret_client.get_secret( | ||
key_vault_secret_name) | ||
self._dict[self.trim(config.key)] = secret.value | ||
return | ||
if key_vault_options.secret_clients is not None: | ||
for secret_client in key_vault_options.secret_clients: | ||
if secret_client._vault_url == key_vault_uri: | ||
secret = secret_client.get_secret( | ||
key_vault_secret_name) | ||
self._dict[self.trim( | ||
config.key)] = secret.value | ||
break | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if key_vault_options.secret_resolver is not None: | ||
self._dict[self.trim( | ||
config.key)] = key_vault_options.secret_resolver(uri) | ||
|
||
def trim(self, key): | ||
for trim in self._trim_prefixes: | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if key.startswith(trim): | ||
return key[len(trim):] | ||
return key | ||
|
||
def __getitem__(self, key): | ||
return self._dict[key] | ||
|
||
def __repr__(self): | ||
return repr(self._dict) | ||
|
||
def __len__(self): | ||
return len(self._dict) | ||
|
||
def copy(self): | ||
return self._dict.copy() | ||
|
||
def has_key(self, k): | ||
return k in self._dict | ||
|
||
def keys(self): | ||
return self._dict.keys() | ||
|
||
def values(self): | ||
return self._dict.values() |
10 changes: 10 additions & 0 deletions
10
...ration/azure-appconfiguration-provider/azure/appconfigurationprovider/_settingselector.py
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,10 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
class SettingSelector: | ||
|
||
def __init__(self, key_filter, label_filter): | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.key_filter = key_filter | ||
self.label_filter = label_filter |
9 changes: 9 additions & 0 deletions
9
...nfiguration/azure-appconfiguration-provider/azure/appconfigurationprovider/_user_agent.py
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,9 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
from ._version import VERSION | ||
|
||
USER_AGENT = "python-appconfigurationprovider/{}".format( | ||
VERSION | ||
) |
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.