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
4 changes: 4 additions & 0 deletions src/enterprise-edge/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.1.1
++++++
* Automatically register Microsoft.CDN resource provider upon running enable command

0.1.0
++++++
* Initial release.
2 changes: 1 addition & 1 deletion src/enterprise-edge/azext_enterprise_edge/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

helps['staticwebapp enterprise-edge enable'] = """
type: command
short-summary: Enable the Azure Front Door CDN for a static webapp. For optimal experience and availability please check our documentation https://aka.ms/swaedge
short-summary: Enable the Azure Front Door CDN for a static webapp. Enabling enterprise-grade edge requires re-registration for the Azure Front Door Microsoft.CDN resource provider. For optimal experience and availability please check our documentation https://aka.ms/swaedge
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:re-registration?
Too Many links in the short-summary move the fwd link about registration to the no-register parameter part of help.


helps['staticwebapp enterprise-edge disable'] = """
Expand Down
3 changes: 3 additions & 0 deletions src/enterprise-edge/azext_enterprise_edge/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ def load_arguments(self, _):
with self.argument_context('staticwebapp enterprise-edge') as c:
c.argument("name", arg_type=staticsite_name_arg_type)
c.argument("resource_group_name", arg_type=resource_group_name_type)

with self.argument_context('staticwebapp enterprise-edge') as c:
c.argument("no_register", help="Don't try to register the Microsoft.CDN provider. Registration can be done manually with: az provider register --wait --namespace Microsoft.CDN. For more details, please review the documentation available at https://go.microsoft.com/fwlink/?linkid=2184995 .", default=False)
48 changes: 28 additions & 20 deletions src/enterprise-edge/azext_enterprise_edge/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from azure.cli.core.util import send_raw_request
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.command_modules.appservice._client_factory import providers_client_factory


logger = get_logger(__name__)
Expand Down Expand Up @@ -37,11 +38,11 @@ def _request(cls, cmd, resource_group, name, http_method="GET", body=None):
return r

@classmethod
def set(cls, cmd, resource_group, name, enable):
def set(cls, cmd, resource_group, name, enable, no_register=False):
params = cls.get(cmd, resource_group, name).json()

if enable:
cls._validate_cdn_provider_registered(cmd)
if enable and not no_register:
cls._register_cdn_provider(cmd)
cls._validate_sku(params["sku"].get("name"))

params["properties"]["enterpriseGradeCdnStatus"] = "enabled" if enable else "disabled"
Expand All @@ -52,18 +53,24 @@ def get(cls, cmd, resource_group, name):
return cls._request(cmd, resource_group, name)

@classmethod
def _validate_cdn_provider_registered(cls, cmd):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = "2021-04-01"
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/providers/Microsoft.CDN?api-version={}"

request_url = url_fmt.format(management_hostname.strip('/'), sub_id, api_version)

registration = send_raw_request(cmd.cli_ctx, "GET", request_url).json().get("registrationState").lower()
if registration != "registered":
raise CLIError("Provider Microsoft.CDN is not registered. "
"Please run 'az provider register --wait --namespace Microsoft.CDN'")
def _register_cdn_provider(cls, cmd):
from azure.mgmt.resource.resources.models import ProviderRegistrationRequest, ProviderConsentDefinition

namespace = "Microsoft.CDN"
properties = ProviderRegistrationRequest(third_party_provider_consent=ProviderConsentDefinition(
consent_to_authorization=True))

client = providers_client_factory(cmd.cli_ctx)
try:
client.register(namespace, properties=properties)
except Exception as e:
msg = "Server responded with error message : {} \n"\
"Enabling enterprise-grade edge requires reregistration for the Azure Front "\
"Door Microsoft.CDN resource provider. We were unable to perform that reregistration on your "\
"behalf. Please check with your admin on permissions and review the documentation available at "\
"https://go.microsoft.com/fwlink/?linkid=2185350. "\
"Or try running registration manually with: az provider register --wait --namespace Microsoft.CDN"
raise CLIError(msg.format(e.args)) from e

@classmethod
def _validate_sku(cls, sku_name):
Expand All @@ -77,18 +84,19 @@ def _format_show_response(cmd, name, resource_group_name):
return {"enterpriseGradeCdnStatus": staticsite_data["properties"]["enterpriseGradeCdnStatus"]}


def enable_staticwebapp_enterprise_edge(cmd, name, resource_group_name):
logger.warn("For optimal experience and availability please check our documentation https://aka.ms/swaedge")
StaticWebAppFrontDoorClient.set(cmd, name=name, resource_group=resource_group_name, enable=True)
def enable_staticwebapp_enterprise_edge(cmd, name, resource_group_name, no_register=False):
logger.warning("For optimal experience and availability please check our documentation https://aka.ms/swaedge")
StaticWebAppFrontDoorClient.set(cmd, name=name, resource_group=resource_group_name, enable=True,
no_register=no_register)
return _format_show_response(cmd, name, resource_group_name)


def disable_staticwebapp_enterprise_edge(cmd, name, resource_group_name):
logger.warn("For optimal experience and availability please check our documentation https://aka.ms/swaedge")
logger.warning("For optimal experience and availability please check our documentation https://aka.ms/swaedge")
StaticWebAppFrontDoorClient.set(cmd, name=name, resource_group=resource_group_name, enable=False)
return _format_show_response(cmd, name, resource_group_name)


def show_staticwebapp_enterprise_edge_status(cmd, name, resource_group_name):
logger.warn("For optimal experience and availability please check our documentation https://aka.ms/swaedge")
logger.warning("For optimal experience and availability please check our documentation https://aka.ms/swaedge")
return _format_show_response(cmd, name, resource_group_name)
2 changes: 1 addition & 1 deletion src/enterprise-edge/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '0.1.0'
VERSION = '0.1.1'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down