Esempio n. 1
0
def update_endpoint(instance,
                    origin_host_header=None,
                    origin_path=None,
                    content_types_to_compress=None,
                    is_compression_enabled=None,
                    is_http_allowed=None,
                    is_https_allowed=None,
                    query_string_caching_behavior=None,
                    tags=None):
    params = EndpointUpdateParameters(
        origin_host_header=origin_host_header,
        origin_path=origin_path,
        content_types_to_compress=content_types_to_compress,
        is_compression_enabled=is_compression_enabled,
        is_http_allowed=is_http_allowed,
        is_https_allowed=is_https_allowed,
        query_string_caching_behavior=query_string_caching_behavior,
        tags=tags)

    if is_compression_enabled and not instance.content_types_to_compress:
        params.content_types_to_compress = default_content_types()

    _update_mapper(instance, params, [
        'origin_host_header', 'origin_path', 'content_types_to_compress',
        'is_compression_enabled', 'is_http_allowed', 'is_https_allowed',
        'query_string_caching_behavior', 'tags'
    ])
    return params
Esempio n. 2
0
def update_endpoint(instance,
                    origin_host_header=None,
                    origin_path=None,
                    content_types_to_compress=None,
                    is_compression_enabled=None,
                    is_http_allowed=None,
                    is_https_allowed=None,
                    query_string_caching_behavior=None,
                    tags=None):
    params = EndpointUpdateParameters(
        origin_host_header=origin_host_header,
        origin_path=origin_path,
        content_types_to_compress=content_types_to_compress,
        is_compression_enabled=is_compression_enabled,
        is_http_allowed=is_http_allowed,
        is_https_allowed=is_https_allowed,
        query_string_caching_behavior=query_string_caching_behavior,
        tags=tags
    )

    if is_compression_enabled and not instance.content_types_to_compress:
        params.content_types_to_compress = default_content_types()

    _update_mapper(instance, params, [
        'origin_host_header',
        'origin_path',
        'content_types_to_compress',
        'is_compression_enabled',
        'is_http_allowed',
        'is_https_allowed',
        'query_string_caching_behavior',
        'tags'
    ])
    return params
Esempio n. 3
0
    def update_cdnendpoint(self):
        '''
        Updates a Azure CDN endpoint.

        :return: deserialized Azure CDN endpoint instance state dictionary
        '''
        self.log("Updating the Azure CDN endpoint instance {0}".format(self.name))

        endpoint_update_properties = EndpointUpdateParameters(
            tags=self.tags,
            origin_host_header=self.origin_host_header,
            origin_path=self.origin_path,
            content_types_to_compress=default_content_types() if self.is_compression_enabled and not self.content_types_to_compress
            else self.content_types_to_compress,
            is_compression_enabled=self.is_compression_enabled,
            is_http_allowed=self.is_http_allowed,
            is_https_allowed=self.is_https_allowed,
            query_string_caching_behavior=self.query_string_caching_behavior,
        )

        try:
            poller = self.cdn_client.endpoints.update(self.resource_group, self.profile_name, self.name, endpoint_update_properties)
            response = self.get_poller_result(poller)
            return cdnendpoint_to_dict(response)
        except ErrorResponseException as exc:
            self.log('Error attempting to update Azure CDN endpoint instance.')
            self.fail("Error updating Azure CDN endpoint instance: {0}".format(exc.message))
Esempio n. 4
0
def add_condition(client,
                  resource_group_name,
                  profile_name,
                  endpoint_name,
                  rule_name,
                  match_variable,
                  operator,
                  match_values=None,
                  selector=None,
                  negate_condition=None,
                  transform=None):

    endpoint = client.endpoints.get(resource_group_name, profile_name,
                                    endpoint_name)
    policy = endpoint.delivery_policy
    condition = create_condition(match_variable, operator, match_values,
                                 selector, negate_condition, transform)
    for i in range(0, len(policy.rules)):
        if policy.rules[i].name == rule_name:
            policy.rules[i].conditions.append(condition)

    params = EndpointUpdateParameters(delivery_policy=policy)

    return client.endpoints.update(resource_group_name, profile_name,
                                   endpoint_name, params)
Esempio n. 5
0
def update_endpoint(instance,
                    origin_host_header=None,
                    origin_path=None,
                    content_types_to_compress=None,
                    is_compression_enabled=None,
                    is_http_allowed=None,
                    is_https_allowed=None,
                    query_string_caching_behavior=None,
                    default_origin_group=None,
                    tags=None):

    # default origin group is specified as a name, format it as an ID.
    if default_origin_group is not None:
        if '/' not in default_origin_group:
            default_origin_group = f'{instance.id}/originGroups/{default_origin_group}'
        default_origin_group = ResourceReference(id=default_origin_group)

    params = EndpointUpdateParameters(
        origin_host_header=origin_host_header,
        origin_path=origin_path,
        content_types_to_compress=content_types_to_compress,
        is_compression_enabled=is_compression_enabled,
        is_http_allowed=is_http_allowed,
        is_https_allowed=is_https_allowed,
        query_string_caching_behavior=query_string_caching_behavior,
        default_origin_group=default_origin_group,
        tags=tags
    )

    if is_compression_enabled and not instance.content_types_to_compress:
        params.content_types_to_compress = default_content_types()

    _update_mapper(instance, params, [
        'origin_host_header',
        'origin_path',
        'content_types_to_compress',
        'is_compression_enabled',
        'is_http_allowed',
        'is_https_allowed',
        'query_string_caching_behavior',
        'default_origin_group',
        'tags'
    ])
    return params
Esempio n. 6
0
def add_rule(cmd, client, resource_group_name, profile_name, endpoint_name,
             order, action_name, match_variable=None, operator=None,
             match_values=None, selector=None, negate_condition=None, transform=None,
             cache_behavior=None, cache_duration=None, header_action=None,
             header_name=None, header_value=None, query_string_behavior=None, query_parameters=None,
             redirect_type=None, redirect_protocol=None, custom_hostname=None, custom_path=None,
             custom_querystring=None, custom_fragment=None, source_pattern=None,
             destination=None, preserve_unmatched_path=None, rule_name=None, origin_group=None):

    partner_skus = [SkuName.PREMIUM_VERIZON, SkuName.CUSTOM_VERIZON, SkuName.STANDARD_AKAMAI, SkuName.STANDARD_VERIZON]
    profile = client.profiles.get(resource_group_name, profile_name)
    if rule_name is None and profile.sku.name not in partner_skus:
        raise CLIError("--rule-name is required for Microsoft SKU")

    endpoint = client.endpoints.get(resource_group_name, profile_name, endpoint_name)

    policy = endpoint.delivery_policy
    if policy is None:
        policy = EndpointPropertiesUpdateParametersDeliveryPolicy(
            description='delivery_policy',
            rules=[])

    _convert_to_unified_delivery_rules(policy)

    conditions = []
    condition = create_condition(match_variable, operator, match_values, selector, negate_condition, transform)
    if condition is not None:
        conditions.append(condition)
    actions = []
    action = create_action(action_name, cache_behavior, cache_duration, header_action, header_name,
                           header_value, query_string_behavior, query_parameters, redirect_type,
                           redirect_protocol, custom_hostname, custom_path, custom_querystring,
                           custom_fragment, source_pattern, destination, preserve_unmatched_path,
                           cmd, resource_group_name, profile_name, endpoint_name, origin_group)
    if action is not None:
        actions.append(action)

    rule = DeliveryRule(
        name=rule_name,
        order=order,
        conditions=conditions,
        actions=actions
    )

    policy.rules.append(rule)
    params = EndpointUpdateParameters(
        delivery_policy=policy
    )

    return client.endpoints.begin_update(resource_group_name, profile_name, endpoint_name, params)
Esempio n. 7
0
def remove_action(client, resource_group_name, profile_name, endpoint_name, rule_name, index):

    endpoint = client.endpoints.get(resource_group_name, profile_name, endpoint_name)
    policy = endpoint.delivery_policy
    if policy is not None:
        for i in range(0, len(policy.rules)):
            if policy.rules[i].name == rule_name:
                policy.rules[i].actions.pop(index)
    else:
        logger.warning("rule cannot be found. This command will be skipped. Please check the rule name")

    params = EndpointUpdateParameters(
        delivery_policy=policy
    )

    return client.endpoints.begin_update(resource_group_name, profile_name, endpoint_name, params)
Esempio n. 8
0
def remove_rule(client, resource_group_name, profile_name, endpoint_name, rule_name):

    endpoint = client.endpoints.get(resource_group_name, profile_name, endpoint_name)
    policy = endpoint.delivery_policy
    if policy is not None:
        for rule in policy.rules:
            if rule.name == rule_name:
                policy.rules.remove(rule)
    else:
        logger.warning("rule cannot be found. This command will be skipped. Please check the rule name")

    params = EndpointUpdateParameters(
        delivery_policy=policy
    )

    return client.endpoints.update(resource_group_name, profile_name, endpoint_name, params)
Esempio n. 9
0
def remove_rule(client,
                resource_group_name,
                profile_name,
                endpoint_name,
                rule_name=None,
                order: int = None):

    if rule_name is None and order is None:
        raise CLIError("Either --rule-name or --order must be specified")

    if order is not None and order < 0:
        raise CLIError("Order should be non-negative.")

    endpoint = client.endpoints.get(resource_group_name, profile_name,
                                    endpoint_name)
    policy = endpoint.delivery_policy
    if policy is not None:
        _convert_to_unified_delivery_rules(policy)
        pop_index = -1
        for idx, rule in enumerate(policy.rules):
            if rule_name is not None and rule.name == rule_name:
                pop_index = idx
                break
            elif order is not None and rule.order == order:
                pop_index = idx
                break

        # To guarantee the consecutive rule order, we need to make sure the rule with order larger than the deleted one
        # to decrease its order by one. Rule with order 0 is special and no rule order adjustment is required.
        if pop_index != -1:
            pop_order = policy.rules[pop_index].order
            policy.rules.pop(pop_index)
            for rule in policy.rules:
                if rule.order > pop_order and pop_order != 0:
                    rule.order -= 1

    else:
        logger.warning(
            "rule cannot be found. This command will be skipped. Please check the rule name"
        )

    params = EndpointUpdateParameters(delivery_policy=policy)

    return client.endpoints.begin_update(resource_group_name, profile_name,
                                         endpoint_name, params)
Esempio n. 10
0
def add_action(client,
               resource_group_name,
               profile_name,
               endpoint_name,
               rule_name,
               action_name,
               cache_behavior=None,
               cache_duration=None,
               header_action=None,
               header_name=None,
               header_value=None,
               query_string_behavior=None,
               query_parameters=None,
               redirect_type=None,
               redirect_protocol=None,
               custom_hostname=None,
               custom_path=None,
               custom_querystring=None,
               custom_fragment=None,
               source_pattern=None,
               destination=None,
               preserve_unmatched_path=None):

    endpoint = client.endpoints.get(resource_group_name, profile_name,
                                    endpoint_name)
    policy = endpoint.delivery_policy
    action = create_action(action_name, cache_behavior, cache_duration,
                           header_action, header_name, header_value,
                           query_string_behavior, query_parameters,
                           redirect_type, redirect_protocol, custom_hostname,
                           custom_path, custom_querystring, custom_fragment,
                           source_pattern, destination,
                           preserve_unmatched_path)
    for i in range(0, len(policy.rules)):
        if policy.rules[i].name == rule_name:
            policy.rules[i].actions.append(action)

    params = EndpointUpdateParameters(delivery_policy=policy)

    return client.endpoints.update(resource_group_name, profile_name,
                                   endpoint_name, params)
Esempio n. 11
0
def add_rule(client, resource_group_name, profile_name, endpoint_name,
             order, rule_name, action_name, match_variable=None, operator=None,
             match_values=None, selector=None, negate_condition=None, transform=None,
             cache_behavior=None, cache_duration=None, header_action=None,
             header_name=None, header_value=None, query_string_behavior=None, query_parameters=None,
             redirect_type=None, redirect_protocol=None, custom_hostname=None, custom_path=None,
             custom_querystring=None, custom_fragment=None, source_pattern=None,
             destination=None, preserve_unmatched_path=None):
    endpoint = client.endpoints.get(resource_group_name, profile_name, endpoint_name)
    policy = endpoint.delivery_policy
    if policy is None:
        policy = EndpointPropertiesUpdateParametersDeliveryPolicy(
            description='delivery_policy',
            rules=[])

    conditions = []
    condition = create_condition(match_variable, operator, match_values, selector, negate_condition, transform)
    if condition is not None:
        conditions.append(condition)
    actions = []
    action = create_action(action_name, cache_behavior, cache_duration, header_action, header_name,
                           header_value, query_string_behavior, query_parameters, redirect_type,
                           redirect_protocol, custom_hostname, custom_path, custom_querystring,
                           custom_fragment, source_pattern, destination, preserve_unmatched_path)
    if action is not None:
        actions.append(action)

    rule = DeliveryRule(
        name=rule_name,
        order=order,
        conditions=conditions,
        actions=actions
    )

    policy.rules.append(rule)
    params = EndpointUpdateParameters(
        delivery_policy=policy
    )

    return client.endpoints.update(resource_group_name, profile_name, endpoint_name, params)