示例#1
0
def create_fd_routing_rules(cmd,
                            resource_group_name,
                            front_door_name,
                            item_name,
                            frontend_endpoints,
                            backend_pool,
                            accepted_protocols=None,
                            patterns_to_match=None,
                            custom_forwarding_path=None,
                            forwarding_protocol=None,
                            disabled=None,
                            dynamic_compression=None,
                            query_parameter_strip_directive=None):
    from azext_front_door.vendored_sdks.models import CacheConfiguration, RoutingRule, SubResource
    rule = RoutingRule(
        name=item_name,
        enabled_state='Disabled' if disabled else 'Enabled',
        frontend_endpoints=[SubResource(
            id=x) for x in frontend_endpoints] if frontend_endpoints else None,
        accepted_protocols=accepted_protocols or ['Http'],
        patterns_to_match=patterns_to_match or ['/*'],
        custom_forwarding_path=custom_forwarding_path,
        forwarding_protocol=forwarding_protocol,
        backend_pool=SubResource(id=backend_pool) if backend_pool else None,
        cache_configuration=CacheConfiguration(
            query_parameter_strip_directive=query_parameter_strip_directive,
            dynamic_compression=dynamic_compression))
    return _upsert_frontdoor_subresource(cmd, resource_group_name,
                                         front_door_name, 'routing_rules',
                                         rule, 'name')
示例#2
0
def create_front_door(cmd,
                      resource_group_name,
                      front_door_name,
                      backend_address,
                      friendly_name=None,
                      tags=None,
                      disabled=None,
                      no_wait=False,
                      backend_host_header=None,
                      frontend_host_name=None,
                      probe_path='/',
                      probe_protocol='Https',
                      probe_interval=30,
                      accepted_protocols=None,
                      patterns_to_match=None,
                      forwarding_protocol='MatchRequest'):
    from azext_front_door.vendored_sdks.models import (
        FrontDoor, FrontendEndpoint, BackendPool, Backend,
        HealthProbeSettingsModel, LoadBalancingSettingsModel, RoutingRule)

    # set the default names (consider making user-settable)
    backend_pool_name = 'DefaultBackendPool'
    frontend_endpoint_name = 'DefaultFrontendEndpoint'
    probe_setting_name = 'DefaultProbeSettings'
    load_balancing_settings_name = 'DefaultLoadBalancingSettings'
    routing_rule_name = 'DefaultRoutingRule'

    # get the IDs to fill the references
    backend_pool_id = _front_door_subresource_id(cmd, resource_group_name,
                                                 front_door_name,
                                                 'backendPools',
                                                 backend_pool_name)
    frontend_endpoint_id = _front_door_subresource_id(cmd, resource_group_name,
                                                      front_door_name,
                                                      'frontendEndpoints',
                                                      frontend_endpoint_name)
    probe_settings_id = _front_door_subresource_id(cmd, resource_group_name,
                                                   front_door_name,
                                                   'healthProbeSettings',
                                                   probe_setting_name)
    load_balancing_settings_id = _front_door_subresource_id(
        cmd, resource_group_name, front_door_name, 'loadBalancingSettings',
        load_balancing_settings_name)

    front_door = FrontDoor(
        tags=tags,
        location='global',
        friendly_name=friendly_name or front_door_name,
        enabled_state='Enabled' if not disabled else 'Disabled',
        backend_pools=[
            BackendPool(
                name=backend_pool_name,
                backends=[
                    Backend(address=backend_address,
                            http_port=80,
                            https_port=443,
                            priority=1,
                            weight=50,
                            backend_host_header=backend_host_header
                            or backend_address,
                            enabled_state='Enabled')
                ],
                health_probe_settings={'id': probe_settings_id},
                load_balancing_settings={'id': load_balancing_settings_id},
                resource_state='Enabled')
        ],
        health_probe_settings=[
            HealthProbeSettingsModel(name=probe_setting_name,
                                     interval_in_seconds=probe_interval,
                                     path=probe_path,
                                     protocol=probe_protocol,
                                     resource_state='Enabled')
        ],
        frontend_endpoints=[
            FrontendEndpoint(name=frontend_endpoint_name,
                             host_name=frontend_host_name if frontend_host_name
                             else '{}.azurefd.net'.format(front_door_name),
                             session_affinity_enabled_state='Disabled',
                             resource_state='Enabled')
        ],
        load_balancing_settings=[
            LoadBalancingSettingsModel(name=load_balancing_settings_name,
                                       additional_latency_milliseconds=0,
                                       sample_size=4,
                                       successful_samples_required=2,
                                       resource_state='Enabled')
        ],
        routing_rules=[
            RoutingRule(name=routing_rule_name,
                        frontend_endpoints=[{
                            'id': frontend_endpoint_id
                        }],
                        accepted_protocols=accepted_protocols or ['Http'],
                        patterns_to_match=patterns_to_match or ['/*'],
                        forwarding_protocol=forwarding_protocol,
                        backend_pool={'id': backend_pool_id},
                        enabled_state='Enabled',
                        resource_state='Enabled')
        ])
    return sdk_no_wait(no_wait,
                       cf_frontdoor(cmd.cli_ctx, None).create_or_update,
                       resource_group_name, front_door_name, front_door)
示例#3
0
def create_fd_routing_rules(cmd, resource_group_name, front_door_name, item_name, frontend_endpoints, route_type,
                            backend_pool=None, accepted_protocols=None, patterns_to_match=None,
                            custom_forwarding_path=None, forwarding_protocol=None, disabled=None,
                            dynamic_compression=None, query_parameter_strip_directive=None,
                            redirect_type='Moved', redirect_protocol='MatchRequest', custom_host=None, custom_path=None,
                            custom_fragment=None, custom_query_string=None):
    from azext_front_door.vendored_sdks.models import (CacheConfiguration, RoutingRule, SubResource,
                                                       ForwardingConfiguration, RedirectConfiguration)

    forwarding_usage = ('usage error: [--backend-pool BACKEND_POOL] '
                        '[--custom-forwarding-path CUSTOM_FORWARDING_PATH] '
                        '[--forwarding-protocol FORWARDING_PROTOCOL] '
                        '[--query-parameter-strip-directive {StripNone,StripAll}] '
                        '[--dynamic-compression [{Enabled,Disabled}]]')
    redirect_usage = ('usage error: [--redirect-type {Moved,Found,TemporaryRedirect,PermanentRedirect}]'
                      '[--redirect-protocol {HttpOnly,HttpsOnly,MatchRequest}] '
                      '[--custom-host CUSTOM_HOST] [--custom-path CUSTOM_PATH] '
                      '[--custom-fragment CUSTOM_FRAGMENT] [--custom-query-string CUSTOM_QUERY_STRING]')

    # pylint: disable=line-too-long
    if (route_type == 'Forward' and any([custom_host, custom_path, custom_fragment, custom_query_string]) and getattr(redirect_type, 'is_default', None) and getattr(redirect_protocol, 'is_default', None)):
        from knack.util import CLIError
        raise CLIError(forwarding_usage)
    if route_type == 'Redirect' and any([custom_forwarding_path, forwarding_protocol, backend_pool,
                                         query_parameter_strip_directive, dynamic_compression]):
        from knack.util import CLIError
        raise CLIError(redirect_usage)

    if route_type == 'Forward':
        rule = RoutingRule(
            name=item_name,
            enabled_state='Disabled' if disabled else 'Enabled',
            frontend_endpoints=[SubResource(id=x) for x in frontend_endpoints] if frontend_endpoints else None,
            accepted_protocols=accepted_protocols or ['Http'],
            patterns_to_match=patterns_to_match or ['/*'],
            route_configuration=ForwardingConfiguration(
                custom_forwarding_path=custom_forwarding_path,
                forwarding_protocol=forwarding_protocol,
                backend_pool=SubResource(id=backend_pool) if backend_pool else None,
                cache_configuration=CacheConfiguration(
                    query_parameter_strip_directive=query_parameter_strip_directive,
                    dynamic_compression=dynamic_compression
                )
            )
        )
    elif route_type == 'Redirect':
        rule = RoutingRule(
            name=item_name,
            enabled_state='Disabled' if disabled else 'Enabled',
            frontend_endpoints=[SubResource(id=x) for x in frontend_endpoints] if frontend_endpoints else None,
            accepted_protocols=accepted_protocols or ['Http'],
            patterns_to_match=patterns_to_match or ['/*'],
            route_configuration=RedirectConfiguration(
                redirect_type=redirect_type,
                redirect_protocol=redirect_protocol,
                custom_host=custom_host,
                custom_path=custom_path,
                custom_fragment=custom_fragment,
                custom_query_string=custom_query_string
            )
        )
    return _upsert_frontdoor_subresource(cmd, resource_group_name, front_door_name, 'routing_rules', rule, 'name')