-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Migrate cdn from az cli to extensions #9786
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
Open
Ptnan7
wants to merge
10
commits into
Azure:main
Choose a base branch
from
Ptnan7:cdn-ext
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f533ce4
init
f065355
add preview
23273aa
fix linter
d57217e
lint
4565c06
add examples
defaa47
add migration example
ebbc74b
add examples
81cc72d
add examples
824e778
add entry
50034dd
rerun test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .. :changelog: | ||
|
|
||
| Release History | ||
| =============== | ||
|
|
||
| 1.0.0b1 | ||
| +++++++ | ||
| * Initial release. Migrated from azure-cli core CDN command module. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Azure CLI CDN and AFD Extension | ||
|
|
||
| This extension provides commands for managing Azure CDN and Azure Front Door (AFD) resources. | ||
|
|
||
| ## Command Groups | ||
|
|
||
| - `az cdn` — Manage Azure CDN profiles, endpoints, origins, custom domains, WAF policies | ||
| - `az afd` — Manage Azure Front Door profiles, endpoints, origins, routes, rules, secrets, security policies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| # pylint: disable=unused-import | ||
| import azext_cdn._help | ||
|
|
||
| from azure.cli.core import AzCommandsLoader | ||
|
|
||
|
|
||
| class CdnCommandsLoader(AzCommandsLoader): | ||
|
|
||
| def __init__(self, cli_ctx=None): | ||
| from azure.cli.core.commands import CliCommandType | ||
| cdn_custom = CliCommandType(operations_tmpl='azext_cdn.custom#{}') | ||
| super().__init__(cli_ctx=cli_ctx, | ||
| custom_command_type=cdn_custom) | ||
|
|
||
| def load_command_table(self, args): | ||
| from .commands import load_command_table | ||
| from azure.cli.core.aaz import load_aaz_command_table | ||
| try: | ||
| from . import aaz | ||
| except ImportError: | ||
| aaz = None | ||
| if aaz: | ||
| load_aaz_command_table( | ||
| loader=self, | ||
| aaz_pkg_name=aaz.__name__, | ||
| args=args | ||
| ) | ||
| load_command_table(self, args) | ||
| return self.command_table | ||
|
|
||
| def load_arguments(self, command): | ||
| from ._params import load_arguments | ||
| load_arguments(self, command) | ||
|
|
||
|
|
||
| COMMAND_LOADER_CLS = CdnCommandsLoader |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import argparse | ||
|
|
||
|
|
||
| # pylint:disable=protected-access | ||
| # pylint:disable=too-few-public-methods | ||
| class OriginType(argparse._AppendAction): | ||
| def __call__(self, parser, namespace, values, option_string=None): | ||
| deep_created_origin = self.get_origin(values, option_string) | ||
| super().__call__(parser, namespace, deep_created_origin, option_string) | ||
|
|
||
| def get_origin(self, values, option_string): | ||
| from azure.mgmt.cdn.models import DeepCreatedOrigin | ||
|
|
||
| if not 1 <= len(values) <= 3 and not 5 <= len(values) <= 6: | ||
| msg = '%s takes 1, 2, 3, 5, or 6 values, %d given' | ||
| raise argparse.ArgumentError( | ||
| self, msg % (option_string, len(values))) | ||
|
|
||
| deep_created_origin = DeepCreatedOrigin( | ||
| name='origin', | ||
| host_name=values[0], | ||
| http_port=80, | ||
| https_port=443) | ||
|
|
||
| if len(values) > 1: | ||
| deep_created_origin.http_port = int(values[1]) | ||
| if len(values) > 2: | ||
| deep_created_origin.https_port = int(values[2]) | ||
| if len(values) > 4: | ||
| deep_created_origin.private_link_resource_id = values[3] | ||
| deep_created_origin.private_link_location = values[4] | ||
| if len(values) > 5: | ||
| deep_created_origin.private_link_approval_message = values[5] | ||
| return deep_created_origin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def cf_cdn(cli_ctx, *kwargs): # pylint: disable=unused-argument | ||
| from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
| from azure.mgmt.cdn import CdnManagementClient | ||
| return get_mgmt_service_client(cli_ctx, CdnManagementClient) | ||
|
|
||
|
|
||
| def cf_custom_domain(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).custom_domains | ||
|
|
||
|
|
||
| def cf_endpoints(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).endpoints | ||
|
|
||
|
|
||
| def cf_profiles(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).profiles | ||
|
|
||
|
|
||
| def cf_afd_profiles(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).afd_profiles | ||
|
|
||
|
|
||
| def cf_origins(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).origins | ||
|
|
||
|
|
||
| def cf_origin_groups(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).origin_groups | ||
|
|
||
|
|
||
| def cf_resource_usage(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).resource_usage | ||
|
|
||
|
|
||
| def cf_edge_nodes(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).edge_nodes | ||
|
|
||
|
|
||
| def cf_waf_policy(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).policies | ||
|
|
||
|
|
||
| def cf_waf_rule_set(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).managed_rule_sets | ||
|
|
||
|
|
||
| def cf_afd_endpoints(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).afd_endpoints | ||
|
|
||
|
|
||
| def cf_afd_origin_groups(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).afd_origin_groups | ||
|
|
||
|
|
||
| def cf_afd_origins(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).afd_origins | ||
|
|
||
|
|
||
| def cf_afd_routes(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).routes | ||
|
|
||
|
|
||
| def cf_afd_rule_sets(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).rule_sets | ||
|
|
||
|
|
||
| def cf_afd_rules(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).rules | ||
|
|
||
|
|
||
| def cf_afd_security_policies(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).security_policies | ||
|
|
||
|
|
||
| def cf_afd_custom_domain(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).afd_custom_domains | ||
|
|
||
|
|
||
| def cf_afd_secrets(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).secrets | ||
|
|
||
|
|
||
| def cf_afd_log_analytics(cli_ctx, _): | ||
| return cf_cdn(cli_ctx).log_analytics | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
cf_cdnfactory is using*kwargsinstead of**kwargs. This breaks the conventional client-factory signature (callers passing keyword arguments will raise aTypeError). Change the parameter to**kwargs(or**_if intentionally unused).