Beispiel #1
0
    def update_configuration(self,
                             configuration_id,
                             name=None,
                             cname=None,
                             cname_access_only=None,
                             delivery_protocol=None,
                             digital_certificate=None,
                             rawlogs=None,
                             active=None,
                             application_aceleration=None):

        data = {
            'name': name,
            'cname': cname,
            'cname_access_only': cname_access_only,
            'delivery_protocol': delivery_protocol,
            'digital_certificate': digital_certificate,
            'rawlogs': rawlogs,
            'active': active,
            'application_aceleration': application_aceleration
        }

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id)
        response = self.session.patch(url, json=filter_none(data))
        json = decode_json(response, 200)
        return instance_from_data(Configuration, json)
    def test_instance_from_data(self):
        class DummyModel(object):
            def __init__(self, data):
                self.data = data

        instance = models.instance_from_data(DummyModel, {'foobar': 1})
        assert isinstance(instance, DummyModel)
Beispiel #3
0
    def create_configuration(self,
                             name,
                             origin_address,
                             origin_host_header,
                             cname=None,
                             cname_access_only=False,
                             delivery_protocol='http',
                             digital_certificate=None,
                             origin_protocol_policy='preserve',
                             browser_cache_settings=False,
                             browser_cache_settings_maximum_ttl=0,
                             cdn_cache_settings='honor',
                             cdn_cache_settings_maximum_ttl=0):

        data = {
            'name': name,
            'origin_address': origin_address,
            'origin_host_header': origin_host_header,
            'cname': cname,
            'cname_access_only': cname_access_only,
            'delivery_protocol': delivery_protocol,
            'digital_certificate': digital_certificate,
            'origin_protocol_policy': origin_protocol_policy,
            'browser_cache_settings': browser_cache_settings,
            'browser_cache_settings_maximum_ttl':
            browser_cache_settings_maximum_ttl,
            'cdn_cache_settings': cdn_cache_settings,
            'cdn_cache_settings_maximum_ttl': cdn_cache_settings_maximum_ttl
        }

        url = self.session.build_url('content_delivery', 'configurations')
        response = self.session.post(url, json=filter_none(data))
        json = decode_json(response, 201)
        return instance_from_data(Configuration, json)
Beispiel #4
0
 def get_configuration(self, configuration_id):
     """Get configuration."""
     url = self.session.build_url('content_delivery', 'configurations',
                                  configuration_id)
     response = self.session.get(url)
     json = decode_json(response, 200)
     return instance_from_data(Configuration, json)
Beispiel #5
0
    def update_error_responses(self,
                               configuration_id,
                               cache_error_400=None,
                               cache_error_403=None,
                               cache_error_404=None,
                               cache_error_405=None,
                               cache_error_414=None,
                               cache_error_416=None,
                               cache_error_501=None):
        """Update error responses of the configuration."""

        data = {
            'cache_error_400': cache_error_400,
            'cache_error_403': cache_error_403,
            'cache_error_404': cache_error_404,
            'cache_error_405': cache_error_405,
            'cache_error_414': cache_error_414,
            'cache_error_416': cache_error_416,
            'cache_error_501': cache_error_501,
        }

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id, 'error_responses')
        response = self.session.patch(url, json=filter_none(data))

        response = self.session.get(url)
        json = decode_json(response, 200)
        json.update({'id': configuration_id})
        return instance_from_data(ErrorResponses, json)
Beispiel #6
0
    def create_configuration(self,
                             name,
                             origin_address,
                             origin_host_header,
                             cname=None,
                             cname_access_only=False,
                             delivery_protocol='http',
                             digital_certificate=None,
                             origin_protocol_policy='preserve',
                             browser_cache_settings=False,
                             browser_cache_settings_maximum_ttl=0,
                             cdn_cache_settings='honor',
                             cdn_cache_settings_maximum_ttl=0):
        """Create a configuration.

        :param str name: human-readable name for the configuration.
        :param str origin_address: origin address that can be an IP
            or a hostname (FQDN)
        :param str origin_host_header: host header will be sent to the origin.
        :param list cname: a list os strings containing all cnames.
            Default empty string.
        :param bool cname_access_only: defines whether the content delivery
            should be done only through cnames. Default to False.
        :param str delivery_protocol: defines the HTTP protocol used
            to deliver content. Default to http.
        :param int digital_certificate: Digital Certificate ID.
            Check `Digital Certificates`_ for more info.
        :param str origin_protocol_policy: Protocol policy used to connect
            to the origin.
        :param bool browser_cache_settings: whether the user browser should
            respect the cache headers sent from the origin. Default to False.
        :param int browser_cache_settings_maximum_ttl: used within
            `browser_cache_settings`, defines how many seconds
            browser cache object will live. Default to 0.

        .. _Digital Certificates:
            https://www.azion.com.br/developers/documentacao/produtos/content-delivery/digital-certificates/
        """
        data = {
            'name': name,
            'origin_address': origin_address,
            'origin_host_header': origin_host_header,
            'cname': cname,
            'cname_access_only': cname_access_only,
            'delivery_protocol': delivery_protocol,
            'digital_certificate': digital_certificate,
            'origin_protocol_policy': origin_protocol_policy,
            'browser_cache_settings': browser_cache_settings,
            'browser_cache_settings_maximum_ttl':
            browser_cache_settings_maximum_ttl,
            'cdn_cache_settings': cdn_cache_settings,
            'cdn_cache_settings_maximum_ttl': cdn_cache_settings_maximum_ttl
        }

        url = self.session.build_url('content_delivery', 'configurations')
        response = self.session.post(url, json=filter_none(data))
        json = decode_json(response, 201)
        return instance_from_data(Configuration, json)
Beispiel #7
0
    def list_error_responses(self, configuration_id):
        """List error responses of the configuration."""
        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id, 'error_responses')

        response = self.session.get(url)
        json = decode_json(response, 200)
        json.update({'id': configuration_id})
        return instance_from_data(ErrorResponses, json)
Beispiel #8
0
    def get_rules_engine(self, configuration_id, phase, rule_id):
        """Get rule from a phase of rules engine of the configuration."""

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id, 'rules_engine', phase,
                                     'rules', rule_id)

        response = self.session.get(url)
        json = decode_json(response, 200)
        return instance_from_data(Rule, json)
Beispiel #9
0
    def get_cache_settings(self, configuration_id, cache_id):
        """Get a cache settings of the configuration."""

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id, 'cache_settings',
                                     cache_id)

        response = self.session.get(url)
        json = decode_json(response, 200)
        return instance_from_data(CacheSettings, json)
Beispiel #10
0
    def authorize(self, username, password):
        """Obtain a fresh token to handle Azion's API protected calls.

        :param str username:
            username
        :param str password:
            password
        """
        url = self.session.build_url('tokens')
        response = self.session.post(url, data={}, auth=(username, password))
        json = decode_json(response, 201)
        return instance_from_data(Token, json)
Beispiel #11
0
    def replace_configuration(self,
                              configuration_id,
                              name=None,
                              cname=None,
                              cname_access_only=None,
                              delivery_protocol=None,
                              digital_certificate=None,
                              rawlogs=None,
                              active=None):
        """Replace a configuration.

        One or more fields can be updated. Fields that were not specificed
        in the request will be replaced for default values. Consider using
        :func:`~partial_update_configuration`

        :param int configuration_id:
            Configuration ID
        :param str name: human-readable name for the configuration.
        :param list cname: a list os strings containing all cnames.
            Default empty string.
        :param bool cname_access_only: defines whether the content delivery
            should be done only through cnames. Default to False.
        :param str delivery_protocol: defines the HTTP protocol used
            to deliver content. Default to http.
        :param int digital_certificate: Digital Certificate ID.
            Check `Digital Certificates`_ for more info.
        :param boolean rawlogs:
            Whether this configuration will store logs in the Cloud Storage.
        :param boolean active:
            Whether this configuration is active.

        .. _Digital Certificates:
            https://www.azion.com.br/developers/documentacao/produtos/content-delivery/digital-certificates/
        """

        data = {
            'name': name,
            'cname': cname,
            'cname_access_only': cname_access_only,
            'delivery_protocol': delivery_protocol,
            'digital_certificate': digital_certificate,
            'rawlogs': rawlogs,
            'active': active
        }

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id)
        response = self.session.put(url, json=filter_none(data))
        json = decode_json(response, 200)
        return instance_from_data(Configuration, json)
Beispiel #12
0
 def create_origin(self, configuration_id, name, origin_type, method,
                   host_header, origin_protocol_policy, addresses,
                   connection_timeout, timeout_between_bytes):
     """Create an origin.
     """
     data = {
         'name': name,
         'origin_type': origin_type,
         'method': method,
         'host_header': host_header,
         'origin_protocol_policy': origin_protocol_policy,
         'addresses': addresses,
         'connection_timeout': connection_timeout,
         'timeout_between_bytes': timeout_between_bytes
     }
     url = self.session.build_url('content_delivery', 'configurations',
                                  configuration_id, 'origins')
     response = self.session.post(url, json=filter_none(data))
     data = decode_json(response, 201)
     return instance_from_data(Origin, data)
Beispiel #13
0
    def update_cache_settings(self,
                              configuration_id,
                              cache_id,
                              name=None,
                              browser_cache_settings=None,
                              browser_cache_settings_maximum_ttl=None,
                              cdn_cache_settings=None,
                              cdn_cache_settings_maximum_ttl=None,
                              cache_by_query_string=None,
                              query_string_fields=None,
                              enable_query_string_sort=None,
                              cache_by_cookies=None,
                              cookie_names=None,
                              adaptive_delivery_action=None,
                              device_group=None,
                              enable_caching_for_post=None):

        data = {
            'name': name,
            'browser_cache_settings': browser_cache_settings,
            'browser_cache_settings_maximum_ttl':
            browser_cache_settings_maximum_ttl,
            'cdn_cache_settings': cdn_cache_settings,
            'cdn_cache_settings_maximum_ttl': cdn_cache_settings_maximum_ttl,
            'cache_by_query_string': cache_by_query_string,
            'query_string_fields': query_string_fields,
            'enable_query_string_sort': enable_query_string_sort,
            'cache_by_cookies': cache_by_cookies,
            'cookie_names': cookie_names,
            'adaptive_delivery_action': adaptive_delivery_action,
            'device_group': device_group,
            'enable_caching_for_post': enable_caching_for_post
        }

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id, 'cache_settings',
                                     cache_id)

        response = self.session.patch(url, json=filter_none(data))
        json = decode_json(response, 200)
        return instance_from_data(CacheSettings, json)
Beispiel #14
0
    def create_rules_engine(self,
                            configuration_id,
                            name,
                            phase,
                            criteria,
                            behaviors,
                            order=None):

        data = {
            'name': name,
            'phase': phase,
            'criteria': criteria,
            'behaviors': behaviors,
            'order': order
        }

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id, 'rules_engine', phase,
                                     'rules')

        response = self.session.post(url, json=filter_none(data))
        json = decode_json(response, 201)
        return instance_from_data(Configuration, json)
Beispiel #15
0
    def update_rules_engine(self,
                            configuration_id,
                            phase,
                            rule_id,
                            name,
                            criteria=None,
                            behaviors=None,
                            order=None):

        data = {
            'name': name,
            'phase': phase,
            'criteria': criteria,
            'behaviors': behaviors,
            'order': order
        }

        url = self.session.build_url('content_delivery', 'configurations',
                                     configuration_id, 'rules_engine', phase,
                                     'rule', rule_id)

        response = self.session.patch(url, json=filter_none(data))
        json = decode_json(response, 200)
        return instance_from_data(CacheSettings, json)
Beispiel #16
0
    def auth(self, username, password):
        url = self.session.build_url('tokens')
        response = self.session.post(url, data={}, auth=(username, password))
        json = decode_json(response, 201)

        return instance_from_data(Token, json)