Skip to content

Commit 9d0335c

Browse files
Ptnan7JingnanXu
andauthored
Migrate cdn from az cli to extensions (Azure#9786)
* init * add preview * fix linter * lint * add examples * add migration example * add examples * add examples * add entry * rerun test * update ut * use vendor * update tests * Fix CDN extension style and recordings * Fix CDN custom domain delete recording --------- Co-authored-by: JingnanXu <jingnanxu@microsoft.com>
1 parent aa719d7 commit 9d0335c

315 files changed

Lines changed: 179553 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/cdn/HISTORY.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. :changelog:
2+
3+
Release History
4+
===============
5+
6+
1.0.0b1
7+
+++++++
8+
* Initial release. Migrated from azure-cli core CDN command module.

src/cdn/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Azure CLI CDN and AFD Extension
2+
3+
This extension provides commands for managing Azure CDN and Azure Front Door (AFD) resources.
4+
5+
## Command Groups
6+
7+
- `az cdn` — Manage Azure CDN profiles, endpoints, origins, custom domains, WAF policies
8+
- `az afd` — Manage Azure Front Door profiles, endpoints, origins, routes, rules, secrets, security policies

src/cdn/azext_cdn/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
# pylint: disable=unused-import
6+
import azext_cdn._help
7+
8+
from azure.cli.core import AzCommandsLoader
9+
10+
11+
class CdnCommandsLoader(AzCommandsLoader):
12+
13+
def __init__(self, cli_ctx=None):
14+
from azure.cli.core.commands import CliCommandType
15+
cdn_custom = CliCommandType(operations_tmpl='azext_cdn.custom#{}')
16+
super().__init__(cli_ctx=cli_ctx,
17+
custom_command_type=cdn_custom)
18+
19+
def load_command_table(self, args):
20+
from .commands import load_command_table
21+
from azure.cli.core.aaz import load_aaz_command_table
22+
try:
23+
from . import aaz
24+
except ImportError:
25+
aaz = None
26+
if aaz:
27+
load_aaz_command_table(
28+
loader=self,
29+
aaz_pkg_name=aaz.__name__,
30+
args=args
31+
)
32+
load_command_table(self, args)
33+
return self.command_table
34+
35+
def load_arguments(self, command):
36+
from ._params import load_arguments
37+
load_arguments(self, command)
38+
39+
40+
COMMAND_LOADER_CLS = CdnCommandsLoader

src/cdn/azext_cdn/_actions.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import argparse
7+
8+
9+
# pylint:disable=protected-access
10+
# pylint:disable=too-few-public-methods
11+
class OriginType(argparse._AppendAction):
12+
def __call__(self, parser, namespace, values, option_string=None):
13+
deep_created_origin = self.get_origin(values, option_string)
14+
super().__call__(parser, namespace, deep_created_origin, option_string)
15+
16+
def get_origin(self, values, option_string):
17+
from azext_cdn.vendored_sdks.models import DeepCreatedOrigin
18+
19+
if not 1 <= len(values) <= 3 and not 5 <= len(values) <= 6:
20+
msg = '%s takes 1, 2, 3, 5, or 6 values, %d given'
21+
raise argparse.ArgumentError(
22+
self, msg % (option_string, len(values)))
23+
24+
deep_created_origin = DeepCreatedOrigin(
25+
name='origin',
26+
host_name=values[0],
27+
http_port=80,
28+
https_port=443)
29+
30+
if len(values) > 1:
31+
deep_created_origin.http_port = int(values[1])
32+
if len(values) > 2:
33+
deep_created_origin.https_port = int(values[2])
34+
if len(values) > 4:
35+
deep_created_origin.private_link_resource_id = values[3]
36+
deep_created_origin.private_link_location = values[4]
37+
if len(values) > 5:
38+
deep_created_origin.private_link_approval_message = values[5]
39+
return deep_created_origin
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
7+
def cf_cdn(cli_ctx, *kwargs): # pylint: disable=unused-argument
8+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
9+
from azext_cdn.vendored_sdks import CdnManagementClient
10+
return get_mgmt_service_client(cli_ctx, CdnManagementClient)
11+
12+
13+
def cf_custom_domain(cli_ctx, _):
14+
return cf_cdn(cli_ctx).custom_domains
15+
16+
17+
def cf_endpoints(cli_ctx, _):
18+
return cf_cdn(cli_ctx).endpoints
19+
20+
21+
def cf_profiles(cli_ctx, _):
22+
return cf_cdn(cli_ctx).profiles
23+
24+
25+
def cf_afd_profiles(cli_ctx, _):
26+
return cf_cdn(cli_ctx).afd_profiles
27+
28+
29+
def cf_origins(cli_ctx, _):
30+
return cf_cdn(cli_ctx).origins
31+
32+
33+
def cf_origin_groups(cli_ctx, _):
34+
return cf_cdn(cli_ctx).origin_groups
35+
36+
37+
def cf_resource_usage(cli_ctx, _):
38+
return cf_cdn(cli_ctx).resource_usage
39+
40+
41+
def cf_edge_nodes(cli_ctx, _):
42+
return cf_cdn(cli_ctx).edge_nodes
43+
44+
45+
def cf_waf_policy(cli_ctx, _):
46+
return cf_cdn(cli_ctx).policies
47+
48+
49+
def cf_waf_rule_set(cli_ctx, _):
50+
return cf_cdn(cli_ctx).managed_rule_sets
51+
52+
53+
def cf_afd_endpoints(cli_ctx, _):
54+
return cf_cdn(cli_ctx).afd_endpoints
55+
56+
57+
def cf_afd_origin_groups(cli_ctx, _):
58+
return cf_cdn(cli_ctx).afd_origin_groups
59+
60+
61+
def cf_afd_origins(cli_ctx, _):
62+
return cf_cdn(cli_ctx).afd_origins
63+
64+
65+
def cf_afd_routes(cli_ctx, _):
66+
return cf_cdn(cli_ctx).routes
67+
68+
69+
def cf_afd_rule_sets(cli_ctx, _):
70+
return cf_cdn(cli_ctx).rule_sets
71+
72+
73+
def cf_afd_rules(cli_ctx, _):
74+
return cf_cdn(cli_ctx).rules
75+
76+
77+
def cf_afd_security_policies(cli_ctx, _):
78+
return cf_cdn(cli_ctx).security_policies
79+
80+
81+
def cf_afd_custom_domain(cli_ctx, _):
82+
return cf_cdn(cli_ctx).afd_custom_domains
83+
84+
85+
def cf_afd_secrets(cli_ctx, _):
86+
return cf_cdn(cli_ctx).secrets
87+
88+
89+
def cf_afd_log_analytics(cli_ctx, _):
90+
return cf_cdn(cli_ctx).log_analytics

0 commit comments

Comments
 (0)