Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/azure-cli-core/azure/cli/core/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from azure.cli.core.util import \
(get_file_json, truncate_text, shell_safe_json_parse, b64_to_hex, hash_string, random_string,
open_page_in_browser, can_launch_browser, handle_exception, ConfiguredDefaultSetter, send_raw_request,
should_disable_connection_verify, parse_proxy_resource_id, get_az_user_agent)
should_disable_connection_verify, parse_proxy_resource_id, get_az_user_agent, get_az_rest_user_agent)
from azure.cli.core.mock import DummyCli


Expand Down Expand Up @@ -246,7 +246,7 @@ def test_send_raw_requests(self, send_mock, get_raw_token_mock):
test_body = '{"b1": "v1"}'

expected_header = {
'User-Agent': get_az_user_agent(),
'User-Agent': get_az_rest_user_agent(),
'Accept-Encoding': 'gzip, deflate',
'Accept': '*/*',
'Connection': 'keep-alive',
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_send_raw_requests(self, send_mock, get_raw_token_mock):

get_raw_token_mock.assert_called_with(mock.ANY, test_arm_active_directory_resource_id, subscription=subscription_id)
request = send_mock.call_args.args[1]
self.assertEqual(request.headers['User-Agent'], get_az_user_agent() + ' env-ua ARG-UA')
self.assertEqual(request.headers['User-Agent'], get_az_rest_user_agent() + ' env-ua ARG-UA')


class TestBase64ToHex(unittest.TestCase):
Expand Down
13 changes: 12 additions & 1 deletion src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def send_raw_request(cli_ctx, method, url, headers=None, uri_parameters=None, #
skip_authorization_header = True

# Handle User-Agent
agents = [get_az_user_agent()]
agents = [get_az_rest_user_agent()]

# Borrow AZURE_HTTP_USER_AGENT from msrest
# https://github.com/Azure/msrest-for-python/blob/4cc8bc84e96036f03b34716466230fb257e27b36/msrest/pipeline/universal.py#L70
Expand Down Expand Up @@ -1077,6 +1077,17 @@ def get_az_user_agent():
return ' '.join(agents)


def get_az_rest_user_agent():
"""Get User-Agent for az rest calls"""
Comment thread
houk-ms marked this conversation as resolved.

agents = ['python/{}'.format(platform.python_version()),
Comment thread
houk-ms marked this conversation as resolved.
'({})'.format(platform.platform()),
get_az_user_agent()
]

return ' '.join(agents)


def user_confirmation(message, yes=False):
if yes:
return
Expand Down