-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Key Vault] Add ID parsing method for keys #15044
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 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d8388be
Add non-test changes to keys ID parser
mccoyp 6902510
Add key ID parsing tests
mccoyp 4864bc4
Fix test names
mccoyp 9f108b4
Fix parser references in crypto client
mccoyp 7f35a63
Fix key_id property for crypto client
mccoyp ce339cb
Address feedback, fix certs tests accordingly
mccoyp 31f7067
Apply suggestions from code review
mccoyp 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
28 changes: 28 additions & 0 deletions
28
sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_parse_id.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,28 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| from ._shared import parse_key_vault_id, KeyVaultResourceId | ||
|
|
||
|
|
||
| def parse_key_vault_key_id(source_id): | ||
| # type: (str) -> KeyVaultResourceId | ||
| """Parses a key's full ID into a class with parsed contents as attributes. | ||
| :param str source_id: the full original identifier of a key | ||
| :returns: Returns a parsed key ID as a :class:`KeyVaultResourceId` | ||
| :rtype: ~azure.keyvault.keys.KeyVaultResourceId | ||
| :raises: ValueError | ||
| Example: | ||
| .. literalinclude:: ../tests/test_parse_id.py | ||
| :start-after: [START parse_key_vault_key_id] | ||
| :end-before: [END parse_key_vault_key_id] | ||
| :language: python | ||
| :caption: Parse a key's ID | ||
| :dedent: 8 | ||
| """ | ||
| parsed_id = parse_key_vault_id(source_id) | ||
|
|
||
| return KeyVaultResourceId( | ||
| name=parsed_id.name, source_id=parsed_id.source_id, vault_url=parsed_id.vault_url, version=parsed_id.version | ||
| ) | ||
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |||||
| from ._providers import get_local_cryptography_provider, NoLocalCryptography | ||||||
| from .. import KeyOperation | ||||||
| from .._models import KeyVaultKey | ||||||
| from .._shared import KeyVaultClientBase, parse_vault_id | ||||||
| from .._shared import KeyVaultClientBase, parse_key_vault_id | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| # pylint:disable=unused-import | ||||||
|
|
@@ -53,10 +53,10 @@ def __init__(self, key, credential, **kwargs): | |||||
|
|
||||||
| if isinstance(key, KeyVaultKey): | ||||||
| self._key = key | ||||||
| self._key_id = parse_vault_id(key.id) | ||||||
| self._key_id = parse_key_vault_id(key.id) | ||||||
| elif isinstance(key, six.string_types): | ||||||
| self._key = None | ||||||
| self._key_id = parse_vault_id(key) | ||||||
| self._key_id = parse_key_vault_id(key) | ||||||
| self._keys_get_forbidden = None # type: Optional[bool] | ||||||
| else: | ||||||
| raise ValueError("'key' must be a KeyVaultKey instance or a key ID string including a version") | ||||||
|
|
@@ -76,7 +76,7 @@ def key_id(self): | |||||
|
|
||||||
| :rtype: str | ||||||
| """ | ||||||
| return "/".join(self._key_id) | ||||||
| return self._key_id.source_id | ||||||
|
|
||||||
| @distributed_trace | ||||||
| def _initialize(self, **kwargs): | ||||||
|
|
@@ -242,7 +242,7 @@ def unwrap_key(self, algorithm, encrypted_key, **kwargs): | |||||
| parameters=self._models.KeyOperationsParameters(algorithm=algorithm, value=encrypted_key), | ||||||
| **kwargs | ||||||
| ) | ||||||
| return UnwrapResult(key_id=self._key_id, algorithm=algorithm, key=operation_result.result) | ||||||
| return UnwrapResult(key_id=self._key_id.source_id, algorithm=algorithm, key=operation_result.result) | ||||||
|
||||||
| return UnwrapResult(key_id=self._key_id.source_id, algorithm=algorithm, key=operation_result.result) | |
| return UnwrapResult(key_id=self.key_id, algorithm=algorithm, key=operation_result.result) |
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
146 changes: 146 additions & 0 deletions
146
...lt/azure-keyvault-keys/tests/recordings/test_parse_id.test_parse_key_id_with_version.yaml
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,146 @@ | ||
| interactions: | ||
| - request: | ||
| body: null | ||
| headers: | ||
| Accept: | ||
| - application/json | ||
| Accept-Encoding: | ||
| - gzip, deflate | ||
| Connection: | ||
| - keep-alive | ||
| Content-Length: | ||
| - '0' | ||
| Content-Type: | ||
| - application/json | ||
| User-Agent: | ||
| - azsdk-python-keyvault-keys/4.3.1 Python/3.5.3 (Windows-10-10.0.19041-SP0) | ||
| method: POST | ||
| uri: https://vaultname.vault.azure.net/keys/key95c61223/create?api-version=7.1 | ||
| response: | ||
| body: | ||
| string: '{"error":{"code":"Unauthorized","message":"Request is missing a Bearer | ||
| or PoP token."}}' | ||
| headers: | ||
| cache-control: | ||
| - no-cache | ||
| content-length: | ||
| - '87' | ||
| content-type: | ||
| - application/json; charset=utf-8 | ||
| date: | ||
| - Thu, 05 Nov 2020 18:50:23 GMT | ||
| expires: | ||
| - '-1' | ||
| pragma: | ||
| - no-cache | ||
| strict-transport-security: | ||
| - max-age=31536000;includeSubDomains | ||
| www-authenticate: | ||
| - Bearer authorization="https://login.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47", | ||
| resource="https://vault.azure.net" | ||
| x-content-type-options: | ||
| - nosniff | ||
| x-ms-keyvault-network-info: | ||
| - conn_type=Ipv4;addr=162.211.216.102;act_addr_fam=InterNetwork; | ||
| x-ms-keyvault-region: | ||
| - westus | ||
| x-ms-keyvault-service-version: | ||
| - 1.2.58.0 | ||
| x-powered-by: | ||
| - ASP.NET | ||
| status: | ||
| code: 401 | ||
| message: Unauthorized | ||
| - request: | ||
| body: '{"kty": "RSA"}' | ||
| headers: | ||
| Accept: | ||
| - application/json | ||
| Accept-Encoding: | ||
| - gzip, deflate | ||
| Connection: | ||
| - keep-alive | ||
| Content-Length: | ||
| - '14' | ||
| Content-Type: | ||
| - application/json | ||
| User-Agent: | ||
| - azsdk-python-keyvault-keys/4.3.1 Python/3.5.3 (Windows-10-10.0.19041-SP0) | ||
| method: POST | ||
| uri: https://vaultname.vault.azure.net/keys/key95c61223/create?api-version=7.1 | ||
| response: | ||
| body: | ||
| string: '{"key":{"kid":"https://vaultname.vault.azure.net/keys/key95c61223/2164353f4c7b4e309b33df9b5586e4d6","kty":"RSA","key_ops":["encrypt","decrypt","sign","verify","wrapKey","unwrapKey"],"n":"04KGXsZjjZ375gDqJTN1bAAN1xYjgzUhY48-x8g6_AB5BqTZp5nqYXOOsM3Socnp5xFkM0kRQ97N59AhsKUQs4VOwOZfKcHjyG24y44HwllQY3p8d_VJSkaYi2f5uF13fMuhukcwHPFtW76pafhN4zQxsZ8PiR0VWetLLRHo_l8oHF9MrxDos1ks0468XDT8WhbG7AnpkiX0KKFTXydk1j-fTzuvGkL6C4T66x3ryt3FJf4B6O6dqo4LcEVDgV6Q9DtHoR4qmf7BudykCTUGwXxtQ2GfYmgJiuyVZvRGC-ZeXEHvJAc-jDHj3OahZi4uQ4SymgzXIPov907lq0jqNQ","e":"AQAB"},"attributes":{"enabled":true,"created":1604602224,"updated":1604602224,"recoveryLevel":"Recoverable+Purgeable","recoverableDays":90}}' | ||
| headers: | ||
| cache-control: | ||
| - no-cache | ||
| content-length: | ||
| - '691' | ||
| content-type: | ||
| - application/json; charset=utf-8 | ||
| date: | ||
| - Thu, 05 Nov 2020 18:50:24 GMT | ||
| expires: | ||
| - '-1' | ||
| pragma: | ||
| - no-cache | ||
| strict-transport-security: | ||
| - max-age=31536000;includeSubDomains | ||
| x-content-type-options: | ||
| - nosniff | ||
| x-ms-keyvault-network-info: | ||
| - conn_type=Ipv4;addr=162.211.216.102;act_addr_fam=InterNetwork; | ||
| x-ms-keyvault-region: | ||
| - westus | ||
| x-ms-keyvault-service-version: | ||
| - 1.2.58.0 | ||
| x-powered-by: | ||
| - ASP.NET | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| - request: | ||
| body: null | ||
| headers: | ||
| Accept: | ||
| - application/json | ||
| Accept-Encoding: | ||
| - gzip, deflate | ||
| Connection: | ||
| - keep-alive | ||
| User-Agent: | ||
| - azsdk-python-keyvault-keys/4.3.1 Python/3.5.3 (Windows-10-10.0.19041-SP0) | ||
| method: GET | ||
| uri: https://vaultname.vault.azure.net/keys/key95c61223/?api-version=7.1 | ||
| response: | ||
| body: | ||
| string: '{"key":{"kid":"https://vaultname.vault.azure.net/keys/key95c61223/2164353f4c7b4e309b33df9b5586e4d6","kty":"RSA","key_ops":["encrypt","decrypt","sign","verify","wrapKey","unwrapKey"],"n":"04KGXsZjjZ375gDqJTN1bAAN1xYjgzUhY48-x8g6_AB5BqTZp5nqYXOOsM3Socnp5xFkM0kRQ97N59AhsKUQs4VOwOZfKcHjyG24y44HwllQY3p8d_VJSkaYi2f5uF13fMuhukcwHPFtW76pafhN4zQxsZ8PiR0VWetLLRHo_l8oHF9MrxDos1ks0468XDT8WhbG7AnpkiX0KKFTXydk1j-fTzuvGkL6C4T66x3ryt3FJf4B6O6dqo4LcEVDgV6Q9DtHoR4qmf7BudykCTUGwXxtQ2GfYmgJiuyVZvRGC-ZeXEHvJAc-jDHj3OahZi4uQ4SymgzXIPov907lq0jqNQ","e":"AQAB"},"attributes":{"enabled":true,"created":1604602224,"updated":1604602224,"recoveryLevel":"Recoverable+Purgeable","recoverableDays":90}}' | ||
| headers: | ||
| cache-control: | ||
| - no-cache | ||
| content-length: | ||
| - '691' | ||
| content-type: | ||
| - application/json; charset=utf-8 | ||
| date: | ||
| - Thu, 05 Nov 2020 18:50:24 GMT | ||
| expires: | ||
| - '-1' | ||
| pragma: | ||
| - no-cache | ||
| strict-transport-security: | ||
| - max-age=31536000;includeSubDomains | ||
| x-content-type-options: | ||
| - nosniff | ||
| x-ms-keyvault-network-info: | ||
| - conn_type=Ipv4;addr=162.211.216.102;act_addr_fam=InterNetwork; | ||
| x-ms-keyvault-region: | ||
| - westus | ||
| x-ms-keyvault-service-version: | ||
| - 1.2.58.0 | ||
| x-powered-by: | ||
| - ASP.NET | ||
| status: | ||
| code: 200 | ||
| message: OK | ||
| version: 1 |
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.