-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Static Webapp Azure Frontdoor Integration (enterprise edge) #3959
Conversation
Webapp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Putting Should be released on Jan 12 alongside the public announcement |
Should be merged on the evening (in PT) of 11 Jan 2022 |
class StaticWebAppFrontDoorClient: | ||
@classmethod | ||
def _request(cls, cmd, resource_group, name, http_method="GET", body=None): | ||
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
api_version = "2021-02-01" | ||
sub_id = get_subscription_id(cmd.cli_ctx) | ||
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticSites/{}?api-version={}" | ||
request_url = url_fmt.format( | ||
management_hostname.strip('/'), | ||
sub_id, | ||
resource_group, | ||
name, | ||
api_version) | ||
|
||
if body is not None: | ||
r = send_raw_request(cmd.cli_ctx, http_method, request_url, body=json.dumps(body)) | ||
else: | ||
r = send_raw_request(cmd.cli_ctx, http_method, request_url) | ||
|
||
return r | ||
|
||
@classmethod | ||
def set(cls, cmd, resource_group, name, enable): | ||
params = cls.get(cmd, resource_group, name).json() | ||
|
||
if enable: | ||
cls._validate_cdn_provider_registered(cmd) | ||
cls._validate_sku(params["sku"].get("name")) | ||
|
||
params["properties"]["enterpriseGradeCdnStatus"] = "enabled" if enable else "disabled" | ||
return cls._request(cmd, resource_group, name, "PUT", params) | ||
|
||
@classmethod | ||
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'") | ||
|
||
@classmethod | ||
def _validate_sku(cls, sku_name): | ||
if sku_name.lower() != "standard": | ||
raise CLIError("Invalid SKU: '{}'. Staticwebapp must have 'Standard' SKU to use " | ||
"enterprise edge CDN".format(sku_name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I ask why is this client not defined in Python SDK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new API features were not added to the SDK in time, so we decided to release an extension in the meantime that calls the ARM API directly. Once the SDK is ready and we want to incorporate this feature into the core CLI, we will change it to use the SDK
@panchagnula
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
Could you add some tests for those new commands? |
@zhoxing-ms we don't have any scenario tests for static webapps (even in the core CLI) because the create command requires a GitHub auth token, which would fail the cred scan |
This checklist is used to make sure that common guidelines for a pull request are followed.
General Guidelines
azdev style <YOUR_EXT>
locally? (pip install azdev
required)python scripts/ci/test_index.py -q
locally?For new extensions:
About Extension Publish
There is a pipeline to automatically build, upload and publish extension wheels.
Once your PR is merged into master branch, a new PR will be created to update
src/index.json
automatically.The precondition is to put your code inside this repo and upgrade the version in the PR but do not modify
src/index.json
.