[REST] Fix #14152: az rest: Accept ARM URLs without subscription ID#14370
Merged
[REST] Fix #14152: az rest: Accept ARM URLs without subscription ID#14370
az rest: Accept ARM URLs without subscription ID#14370Conversation
jiasli
commented
Jul 15, 2020
Comment on lines
+814
to
+815
| logger.debug('No subscription ID specified in the URL %s', url) | ||
| return None |
Member
Author
There was a problem hiding this comment.
Stop raising an exception but return None instead.
jiasli
commented
Jul 15, 2020
Comment on lines
+24
to
+32
| # Test ARM Subscriptions - List | ||
| # https://docs.microsoft.com/en-us/rest/api/resources/subscriptions/list | ||
| self.cmd('az rest -u /subscriptions?api-version=2020-01-01', | ||
| checks=[self.exists("value")]) | ||
|
|
||
| # Test ARM Tenants - List | ||
| # https://docs.microsoft.com/en-us/rest/api/resources/tenants/list | ||
| self.cmd('az rest -u /tenants?api-version=2020-01-01', | ||
| checks=[self.exists("value")]) |
Member
Author
There was a problem hiding this comment.
Scenario tests are added for APIs without subscription ID.
jiasli
commented
Jul 15, 2020
Comment on lines
+304
to
+324
| # Test ARM Subscriptions - List | ||
| # https://docs.microsoft.com/en-us/rest/api/resources/subscriptions/list | ||
| # /subscriptions?api-version=2020-01-01 | ||
| send_raw_request(cli_ctx, 'GET', '/subscriptions?api-version=2020-01-01', body=test_body, | ||
| generated_client_request_id_name=None) | ||
|
|
||
| get_raw_token_mock.assert_called_with(mock.ANY, test_arm_active_directory_resource_id) | ||
| request = send_mock.call_args.args[1] | ||
| self.assertEqual(request.url, test_arm_endpoint.rstrip('/') + '/subscriptions?api-version=2020-01-01') | ||
| self.assertDictEqual(dict(request.headers), expected_header_with_auth) | ||
|
|
||
| # Test ARM Tenants - List | ||
| # https://docs.microsoft.com/en-us/rest/api/resources/tenants/list | ||
| # /tenants?api-version=2020-01-01 | ||
| send_raw_request(cli_ctx, 'GET', '/tenants?api-version=2020-01-01', body=test_body, | ||
| generated_client_request_id_name=None) | ||
|
|
||
| get_raw_token_mock.assert_called_with(mock.ANY, test_arm_active_directory_resource_id) | ||
| request = send_mock.call_args.args[1] | ||
| self.assertEqual(request.url, test_arm_endpoint.rstrip('/') + '/tenants?api-version=2020-01-01') | ||
| self.assertDictEqual(dict(request.headers), expected_header_with_auth) |
Member
Author
There was a problem hiding this comment.
Unit tests are added for APIs without subscription ID.
jiasli
commented
Jul 15, 2020
| # Azure Rest API doc | ||
| from azure.cli.core._profile import Profile | ||
| profile = Profile() | ||
| profile = Profile(cli_ctx=cli_ctx) |
Member
Author
There was a problem hiding this comment.
Pass the existing cli_ctx to Profile. Otherwise, Profile will create a new AzCli which is unnecessary.
Co-authored-by: Yu Chen <ychenu@microsoft.com>
zhoxing-ms
reviewed
Jul 15, 2020
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py
Outdated
Show resolved
Hide resolved
jsntcy
reviewed
Jul 15, 2020
Member
|
@jiasli Please fix style check error. |
mmyyrroonn
approved these changes
Jul 15, 2020
fengzhou-msft
approved these changes
Jul 15, 2020
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fix #14152: No subscription ID specified in the URL
#13782 introduced a bug that
az restfails for ARM URLs without subscription ID, like/subscriptions,/tenants:azure-cli/src/azure-cli-core/azure/cli/core/util.py
Lines 807 to 808 in 62eb25f
This PR makes
az restaccept such URLs and retrieve token for the current selected tenant instead.The debug log is also improved:
Testing Guide