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

Static Webapp Azure Frontdoor Integration (enterprise edge) #3959

Merged
merged 16 commits into from
Jan 11, 2022

Conversation

StrawnSC
Copy link
Contributor


This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run 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.

@yonzhan
Copy link
Collaborator

yonzhan commented Oct 13, 2021

Webapp

@StrawnSC StrawnSC marked this pull request as ready for review January 3, 2022 20:07
Copy link
Contributor

@panchagnula panchagnula left a comment

Choose a reason for hiding this comment

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

LGTM

@StrawnSC
Copy link
Contributor Author

StrawnSC commented Jan 6, 2022

Putting do-not-merge label on again so we can wait to release after an announcement (at @simonaco's request)

Should be released on Jan 12 alongside the public announcement

@StrawnSC
Copy link
Contributor Author

Should be merged on the evening (in PT) of 11 Jan 2022

Comment on lines +18 to +72
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))
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

@zhoxing-ms
Copy link
Contributor

Could you add some tests for those new commands?

@StrawnSC
Copy link
Contributor Author

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

@zhoxing-ms zhoxing-ms merged commit 5b0c34b into Azure:main Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants