-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[keyvault] add parse id feature for certs #13321
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b5de5d7
renamed existing id parser to be more consistent with new class
iscai-msft 6c9f3e0
add parse_certificate_id
iscai-msft ead06e6
add tests
iscai-msft 1a5c23b
remove print override, validate properties instead
iscai-msft 05be0b7
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
iscai-msft af05671
remove exposed collection property
iscai-msft 00a32cb
original_id -> source_id
iscai-msft 5f1d2f6
parse_certificate_id -> parse_key_vault_certificate_id
iscai-msft 6bc362f
remove etc from changelog comment
iscai-msft 057ee2d
make code snippet include get of certificate
iscai-msft 3de59c3
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
iscai-msft 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
33 changes: 33 additions & 0 deletions
33
sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_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,33 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| from ._shared import parse_key_vault_identifier, ParsedId | ||
|
|
||
|
|
||
| def parse_key_vault_certificate_id(source_id): | ||
| # type: (str) -> ParsedId | ||
| """Parses a full certificate's ID into a class. | ||
|
|
||
| :param str source_id: the full original identifier of a certificate | ||
| :returns: Returns a parsed certificate id | ||
| :rtype: ~azure.keyvault.certificates.ParsedId | ||
| :raises: ValueError | ||
|
|
||
| Example: | ||
| .. literalinclude:: ../tests/test_parse_id.py | ||
| :start-after: [START parse_key_vault_certificate_id] | ||
| :end-before: [END parse_key_vault_certificate_id] | ||
| :language: python | ||
| :caption: Parse a certificate's ID | ||
| :dedent: 8 | ||
| """ | ||
| parsed_id = parse_key_vault_identifier(source_id) | ||
|
|
||
| return ParsedId( | ||
| 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
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
42 changes: 42 additions & 0 deletions
42
sdk/keyvault/azure-keyvault-certificates/tests/test_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,42 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------- | ||
| import pytest | ||
| from azure.keyvault.certificates import parse_key_vault_certificate_id | ||
| from _shared.test_case import KeyVaultTestCase | ||
|
|
||
|
|
||
| class TestParseId(KeyVaultTestCase): | ||
| def test_parse_certificate_id_with_version(self): | ||
| # [START parse_key_vault_certificate_id] | ||
| source_id = "https://keyvault-name.vault.azure.net/certificates/certificate-name/version" | ||
| parsed_certificate_id = parse_key_vault_certificate_id(source_id) | ||
|
||
|
|
||
| print(parsed_certificate_id.name) | ||
| print(parsed_certificate_id.vault_url) | ||
| print(parsed_certificate_id.version) | ||
| print(parsed_certificate_id.source_id) | ||
| # [END parse_key_vault_certificate_id] | ||
| assert parsed_certificate_id.name == "certificate-name" | ||
| assert parsed_certificate_id.vault_url == "https://keyvault-name.vault.azure.net" | ||
| assert parsed_certificate_id.version == "version" | ||
| assert parsed_certificate_id.source_id == "https://keyvault-name.vault.azure.net/certificates/certificate-name/version" | ||
|
|
||
| def test_parse_certificate_id_with_pending_version(self): | ||
| source_id = "https://keyvault-name.vault.azure.net/certificates/certificate-name/pending" | ||
| parsed_certificate_id = parse_key_vault_certificate_id(source_id) | ||
|
|
||
| assert parsed_certificate_id.name == "certificate-name" | ||
| assert parsed_certificate_id.vault_url == "https://keyvault-name.vault.azure.net" | ||
| assert parsed_certificate_id.version == "pending" | ||
| assert parsed_certificate_id.source_id == "https://keyvault-name.vault.azure.net/certificates/certificate-name/pending" | ||
|
|
||
| def test_parse_deleted_certificate_id(self): | ||
| source_id = "https://keyvault-name.vault.azure.net/deletedcertificates/deleted-certificate" | ||
| parsed_certificate_id = parse_key_vault_certificate_id(source_id) | ||
|
|
||
| assert parsed_certificate_id.name == "deleted-certificate" | ||
| assert parsed_certificate_id.vault_url == "https://keyvault-name.vault.azure.net" | ||
| assert parsed_certificate_id.version == None | ||
| assert parsed_certificate_id.source_id == "https://keyvault-name.vault.azure.net/deletedcertificates/deleted-certificate" | ||
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.
These tests can be module-level methods.