Skip to content
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

Track 2 Azure CLI Support Extension #3738

Merged
merged 15 commits into from
Nov 1, 2021
Merged
4 changes: 4 additions & 0 deletions src/support/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Release History
===============

1.0.3
-----
* Migrate to track 2 SDK

1.0.2
-----
* Removed custom error message in lieu of error message coming from backend.
Expand Down
4 changes: 2 additions & 2 deletions src/support/azext_support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self, cli_ctx=None):
support_custom = CliCommandType(
operations_tmpl='azext_support.custom#{}',
client_factory=cf_support)
super(SupportCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=support_custom)
super().__init__(cli_ctx=cli_ctx,
RudraSharma93Microsoft marked this conversation as resolved.
Show resolved Hide resolved
custom_command_type=support_custom)

def load_command_table(self, args):
from azext_support.commands import load_command_table
Expand Down
4 changes: 2 additions & 2 deletions src/support/azext_support/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def get_bearer_token(cmd, tenant_id):
try:
logger.debug("Retrieving access token for tenant %s", tenant_id)
creds, _, _ = client.get_raw_token(tenant=tenant_id)
except CLIError:
except CLIError as cli_error:
raise CLIError("Can't find authorization for {0}. ".format(tenant_id) +
RudraSharma93Microsoft marked this conversation as resolved.
Show resolved Hide resolved
"Run \'az login -t <tenant_name> --allow-no-subscriptions\' and try again.")
RudraSharma93Microsoft marked this conversation as resolved.
Show resolved Hide resolved
"Run \'az login -t <tenant_name> --allow-no-subscriptions\' and try again.") from cli_error

return "Bearer " + creds[1]
8 changes: 5 additions & 3 deletions src/support/azext_support/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ def validate_communication_create(cmd, namespace):

def _validate_communication_name(cmd, ticket_name, communication_name):
client = cf_communications(cmd.cli_ctx)
rsp = client.check_name_availability(support_ticket_name=ticket_name, name=communication_name,
type="Microsoft.Support/communications")
check_name_availability_input = {"name": communication_name, "type": "Microsoft.Support/communications"}
rsp = client.check_name_availability(support_ticket_name=ticket_name,
check_name_availability_input=check_name_availability_input)
if not rsp.name_available:
raise CLIError(rsp.message)


def _validate_ticket_name(cmd, ticket_name):
client = cf_support_tickets(cmd.cli_ctx)
rsp = client.check_name_availability(name=ticket_name, type="Microsoft.Support/supportTickets")
check_name_availability_input = {"name": ticket_name, "type": "Microsoft.Support/supportTickets"}
rsp = client.check_name_availability(check_name_availability_input=check_name_availability_input)
if not rsp.name_available:
raise CLIError(rsp.message)

Expand Down
12 changes: 6 additions & 6 deletions src/support/azext_support/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ def create_support_tickets(cmd, client,
logger.debug("Sending create request with below payload: ")
logger.debug(json.dumps(body, indent=4))

custom_headers = {}
if partner_tenant_id is not None:
custom_headers["x-ms-authorization-auxiliary"] = get_bearer_token(cmd, partner_tenant_id)
external_bearer_token = get_bearer_token(cmd, partner_tenant_id)
client.begin_create(support_ticket_name=ticket_name, create_support_ticket_parameters=body,
headers={'x-ms-authorization-auxiliary': external_bearer_token})

return client.create(support_ticket_name=ticket_name, create_support_ticket_parameters=body,
custom_headers=custom_headers)
return client.begin_create(support_ticket_name=ticket_name, create_support_ticket_parameters=body)


def create_support_tickets_communications(cmd, client,
Expand All @@ -154,5 +154,5 @@ def create_support_tickets_communications(cmd, client,
body["subject"] = communication_subject
body["body"] = communication_body

return client.create(support_ticket_name=ticket_name, communication_name=communication_name,
create_communication_parameters=body)
return client.begin_create(support_ticket_name=ticket_name, communication_name=communication_name,
create_communication_parameters=body)

Large diffs are not rendered by default.

8,580 changes: 8,416 additions & 164 deletions src/support/azext_support/tests/latest/recordings/test_support_tickets.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,170 @@
interactions:
- request:
body: '{"name": "test_ticket_from_cli_000001", "type": "Microsoft.Support/supportTickets"}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- support tickets create
Connection:
- keep-alive
Content-Length:
- '86'
Content-Type:
- application/json
ParameterSetName:
- --debug --description --severity --ticket-name --severity --title --contact-country
--contact-email --contact-first-name --contact-language --contact-last-name
--contact-method --contact-timezone --problem-classification --technical-resource
User-Agent:
- AZURECLI/2.27.0 azsdk-python-mgmt-support/6.0.0 Python/3.8.2 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Support/checkNameAvailability?api-version=2020-04-01
response:
body:
string: '{"nameAvailable":true}'
headers:
cache-control:
- no-cache
content-length:
- '22'
content-type:
- application/json; charset=utf-8
date:
- Tue, 03 Aug 2021 09:28:28 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-writes:
- '1199'
status:
code: 200
message: OK
- request:
body: '{"properties": {"description": "test ticket from python cli test. Do not
assign and close after a day.", "problemClassificationId": "/providers/Microsoft.Support/services/cddd3eb5-1830-b494-44fd-782f691479dc/problemClassifications/ef8b3865-0c5a-247b-dcaa-d70fd7611a3c",
"severity": "minimal", "require24X7Response": false, "contactDetails": {"firstName":
"Foo", "lastName": "Bar", "preferredContactMethod": "email", "primaryEmailAddress":
"azengcase@microsoft.com", "preferredTimeZone": "Pacific Standard Time", "country":
"USA", "preferredSupportLanguage": "en-US"}, "title": "test ticket from python
cli test. Do not assign and close after a day.", "problemStartTime": "2021-08-03T02:28:29.000Z",
"serviceId": "/providers/Microsoft.Support/services/cddd3eb5-1830-b494-44fd-782f691479dc",
"technicalTicketDetails": {"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test/providers/Microsoft.Compute/virtualMachines/testserver"}}}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- support tickets create
Connection:
- keep-alive
Content-Length:
- '962'
Content-Type:
- application/json
ParameterSetName:
- --debug --description --severity --ticket-name --severity --title --contact-country
--contact-email --contact-first-name --contact-language --contact-last-name
--contact-method --contact-timezone --problem-classification --technical-resource
User-Agent:
- AZURECLI/2.27.0 azsdk-python-mgmt-support/6.0.0 Python/3.8.2 (Windows-10-10.0.19041-SP0)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Support/supportTickets/test_ticket_from_cli_000001?api-version=2020-04-01
response:
body:
string: ''
headers:
azure-asyncoperation:
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Support/operationsStatus/684e4f7f-c164-48db-b3cb-75d91cff2384?api-version=2020-04-01
cache-control:
- no-cache
content-length:
- '0'
date:
- Tue, 03 Aug 2021 09:28:30 GMT
expires:
- '-1'
location:
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Support/operationResults/684e4f7f-c164-48db-b3cb-75d91cff2384?api-version=2020-04-01
pragma:
- no-cache
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-writes:
- '1199'
status:
code: 202
message: Accepted
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
CommandName:
- support tickets create
Connection:
- keep-alive
ParameterSetName:
- --debug --description --severity --ticket-name --severity --title --contact-country
--contact-email --contact-first-name --contact-language --contact-last-name
--contact-method --contact-timezone --problem-classification --technical-resource
User-Agent:
- AZURECLI/2.27.0 azsdk-python-mgmt-support/6.0.0 Python/3.8.2 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Support/operationsStatus/684e4f7f-c164-48db-b3cb-75d91cff2384?api-version=2020-04-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Support/operationsStatus/684e4f7f-c164-48db-b3cb-75d91cff2384","status":"Failed","error":{"code":"InvalidParameterValue","message":"Resource
Id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test/providers/Microsoft.Compute/virtualMachines/testserver
is not valid. Provide a valid ResourceId for technical support ticket","target":"Resource
Id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test/providers/Microsoft.Compute/virtualMachines/testserver
is not valid. Provide a valid ResourceId for technical support ticket","details":[]}}'
headers:
cache-control:
- no-cache
content-length:
- '655'
content-type:
- application/json; charset=utf-8
date:
- Tue, 03 Aug 2021 09:29:01 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
- request:
body: '{"name": "12345", "type": "Microsoft.Support/supportTickets"}'
headers:
Expand All @@ -13,16 +179,13 @@ interactions:
Content-Length:
- '61'
Content-Type:
- application/json; charset=utf-8
- application/json
ParameterSetName:
- --debug --description --severity --ticket-name --severity --title --contact-country
--contact-email --contact-first-name --contact-language --contact-last-name
--contact-method --contact-timezone --problem-classification
User-Agent:
- python/3.8.2 (Windows-10-10.0.18362-SP0) msrest/0.6.11 msrest_azure/0.6.2
azure-mgmt-support/2.0.0 Azure-SDK-For-Python AZURECLI/2.1.0
accept-language:
- en-US
- AZURECLI/2.27.0 azsdk-python-mgmt-support/6.0.0 Python/3.8.2 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Support/checkNameAvailability?api-version=2020-04-01
response:
Expand All @@ -39,7 +202,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 10 Mar 2020 00:21:34 GMT
- Tue, 03 Aug 2021 09:29:01 GMT
expires:
- '-1'
pragma:
Expand All @@ -55,7 +218,7 @@ interactions:
x-content-type-options:
- nosniff
x-ms-ratelimit-remaining-subscription-writes:
- '1198'
- '1199'
status:
code: 200
message: OK
Expand Down
18 changes: 9 additions & 9 deletions src/support/azext_support/vendored_sdks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# 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.
#
# 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.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._configuration import MicrosoftSupportConfiguration
from ._microsoft_support import MicrosoftSupport
__all__ = ['MicrosoftSupport', 'MicrosoftSupportConfiguration']

from .version import VERSION
from ._version import VERSION

__version__ = VERSION
__all__ = ['MicrosoftSupport']

try:
from ._patch import patch_sdk # type: ignore
patch_sdk()
except ImportError:
pass
Loading