Skip to content

Commit

Permalink
[Network] az network front-door routing-rule update: support update c…
Browse files Browse the repository at this point in the history
…ommand (Azure#1347)

* support update command

* fix style

* address comments

* fix linter

* bump version

* a small fix for help

Co-authored-by: Jianhui Harold <haroldrandom@gmail.com>
  • Loading branch information
mmyyrroonn and Jianhui Harold authored Mar 13, 2020
1 parent 21ed8d8 commit 15231d8
Show file tree
Hide file tree
Showing 7 changed files with 1,690 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/front-door/azext_front_door/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@
-n redirectRouteRule1 --patterns /redirect1 --custom-query-string querystring
"""

helps['network front-door routing-rule update'] = """
type: command
short-summary: Update a Front Door routing rule.
"""

helps['network front-door routing-rule list'] = """
type: command
short-summary: List Front Door routing rules.
Expand Down
2 changes: 2 additions & 0 deletions src/front-door/azext_front_door/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ def load_arguments(self, _):
c.argument('forwarding_protocol', help='Protocol to use for forwarding traffic.')
c.argument('backend_pool', help='Name or ID of a backend pool.', validator=validate_backend_pool)
c.argument('frontend_endpoints', help='Space-separated list of frontend endpoint names or IDs.', nargs='+', validator=validate_frontend_endpoints)
with self.argument_context('network front-door routing-rule', arg_group='Forward Routing Rule') as c:
c.argument('custom_forwarding_path', help='Custom path used to rewrite resource paths matched by this rule. Leave empty to use incoming path.')
c.argument('caching', arg_type=get_three_state_flag(positive_label='Enabled', negative_label='Disabled', return_label=False), help='Whether to enable caching for this route.')
c.argument('dynamic_compression', arg_type=get_three_state_flag(positive_label='Enabled', negative_label='Disabled', return_label=True), help='Use dynamic compression for cached content.')
c.argument('query_parameter_strip_directive', arg_type=get_enum_type(FrontDoorQuery), help='Treatment of URL query terms when forming the cache key.')
with self.argument_context('network front-door routing-rule', arg_group='Redirect Routing Rule') as c:
c.argument('redirect_type', arg_type=get_enum_type(FrontDoorRedirectType), help='The redirect type the rule will use when redirecting traffic.')
c.argument('redirect_protocol', arg_type=get_enum_type(FrontDoorRedirectProtocol), help='The protocol of the destination to where the traffic is redirected.')
c.argument('custom_host', help='Host to redirect. Leave empty to use use the incoming host as the destination host.')
Expand Down
5 changes: 5 additions & 0 deletions src/front-door/azext_front_door/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def load_command_table(self, _):
g.custom_command('disable-https', 'configure_fd_frontend_endpoint_disable_https')
g.custom_command('enable-https', 'configure_fd_frontend_endpoint_enable_https')

with self.command_group('network front-door routing-rule', frontdoor_sdk) as g:
g.generic_update_command('update', custom_func_name='update_fd_routing_rule',
is_preview=True, setter_arg_name='front_door_parameters',
child_collection_prop_name='routing_rules')

# with self.command_group('network front-door probe', frontdoor_sdk) as g:
# g.custom_command('create', 'create_fd_probe')
# g.command('delete', 'delete')
Expand Down
56 changes: 40 additions & 16 deletions src/front-door/azext_front_door/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,23 +559,47 @@ def create_fd_routing_rules(cmd, resource_group_name, front_door_name, item_name
return _upsert_frontdoor_subresource(cmd, resource_group_name, front_door_name, 'routing_rules', rule, 'name')


def update_fd_routing_rules(instance, frontend_endpoints=None, accepted_protocols=None, patterns_to_match=None,
custom_forwarding_path=None, forwarding_protocol=None, backend_pool=None, enabled=None,
dynamic_compression=None, query_parameter_strip_directive=None):
def update_fd_routing_rule(parent, instance, item_name, frontend_endpoints=None, accepted_protocols=None, # pylint: disable=unused-argument
patterns_to_match=None, custom_forwarding_path=None, forwarding_protocol=None,
backend_pool=None, enabled=None, dynamic_compression=None,
caching=None, query_parameter_strip_directive=None, redirect_type=None,
redirect_protocol=None, custom_host=None, custom_path=None,
custom_fragment=None, custom_query_string=None):
from azext_front_door.vendored_sdks.models import SubResource
with UpdateContext(instance) as c:
c.update_param('frontend_endpoints', [SubResource(id=x) for x in frontend_endpoints]
if frontend_endpoints else None, False)
c.update_param('accepted_protocols', accepted_protocols, False)
c.update_param('patterns_to_match', patterns_to_match, False)
c.update_param('custom_forwarding_path', custom_forwarding_path, False)
c.update_param('forwarding_protocol', forwarding_protocol, False)
c.update_param('backend_pool', SubResource(id=backend_pool) if backend_pool else None, False)
c.update_param('enabled_state', enabled, False)
with UpdateContext(instance.cache_configuration) as c:
c.update_param('dynamic_compression', dynamic_compression, False)
c.update_param('query_parameter_strip_directive', query_parameter_strip_directive, False)
return instance
if instance:
if hasattr(instance.route_configuration, 'forwarding_protocol'):
with UpdateContext(instance) as c:
c.update_param('frontend_endpoints', [SubResource(id=x) for x in frontend_endpoints]
if frontend_endpoints else None, False)
c.update_param('accepted_protocols', accepted_protocols, False)
c.update_param('patterns_to_match', patterns_to_match, False)
c.update_param('enabled_state', enabled, False)
with UpdateContext(instance.route_configuration) as c:
c.update_param('custom_forwarding_path', custom_forwarding_path, False)
c.update_param('forwarding_protocol', forwarding_protocol, False)
c.update_param('backend_pool', SubResource(id=backend_pool) if backend_pool else None, False)
if caching:
with UpdateContext(instance.route_configuration.cache_configuration) as c:
c.update_param('dynamic_compression', dynamic_compression, False)
c.update_param('query_parameter_strip_directive', query_parameter_strip_directive, False)
else:
if hasattr(instance.route_configuration, 'cache_configuration'):
instance.route_configuration.cache_configuration = None
elif hasattr(instance.route_configuration, 'redirect_protocol'):
with UpdateContext(instance) as c:
c.update_param('frontend_endpoints', [SubResource(id=x) for x in frontend_endpoints]
if frontend_endpoints else None, False)
c.update_param('accepted_protocols', accepted_protocols, False)
c.update_param('patterns_to_match', patterns_to_match, False)
c.update_param('enabled_state', enabled, False)
with UpdateContext(instance.route_configuration) as c:
c.update_param('redirect_type', redirect_type, False)
c.update_param('redirect_protocol', redirect_protocol, False)
c.update_param('custom_host', custom_host, False)
c.update_param('custom_path', custom_path, False)
c.update_param('custom_fragment', custom_fragment, False)
c.update_param('custom_query_string', custom_query_string, False)
return parent
# endregion


Expand Down
Loading

0 comments on commit 15231d8

Please sign in to comment.