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
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
9 changes: 5 additions & 4 deletions src/support/azext_support/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import re

from azure.cli.core._profile import Profile
from azure.cli.core.azclierror import UnauthorizedError
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
from knack.log import get_logger
from knack.util import CLIError

logger = get_logger(__name__)

Expand Down Expand Up @@ -48,8 +48,9 @@ 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:
raise CLIError("Can't find authorization for {0}. ".format(tenant_id) +
"Run \'az login -t <tenant_name> --allow-no-subscriptions\' and try again.")
RudraSharma93Microsoft marked this conversation as resolved.
Show resolved Hide resolved
except UnauthorizedError as unauthorized_error:
jsntcy marked this conversation as resolved.
Show resolved Hide resolved
raise UnauthorizedError("Can't find authorization for {0}. ".format(tenant_id) +
"Run \'az login -t <tenant_name> --allow-no-subscriptions\' and try again.") from \
unauthorized_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)
return 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.

Loading