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)
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)
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)
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 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)
def list_cache_settings(self, configuration_id): """List cache settings of the configuration.""" url = self.session.build_url('content_delivery', 'configurations', configuration_id, 'cache_settings') response = self.session.get(url) json = decode_json(response, 200) return many_of(CacheSettings, json)
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)
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)
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)
def list_rules_engine(self, configuration_id, phase): """List rules from a phase of rules engine of the configuration.""" url = self.session.build_url('content_delivery', 'configurations', configuration_id, 'rules_engine', phase, 'rules') response = self.session.get(url) json = decode_json(response, 200) return many_of(Rule, json)
def list_origins(self, configuration_id): """List origins of the given configuration. :param int configuration_id: Configuration ID """ url = self.session.build_url('content_delivery', 'configurations', configuration_id, 'origins') response = self.session.get(url) data = decode_json(response, 200) return many_of(Origin, data)
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)
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)
def purge_url(self, urls, method='delete'): """Purge content of the given URLs inside the `urls` list. :param list urls: List of URLs to be purged. :param str method: How the content will be purged. Default to 'delete'. """ url = self.session.build_url('purge', 'url') response = self.session.post(url, json={ 'urls': urls, 'method': method }) data = decode_json(response, 207) return handle_multi_status(data, 'urls')
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)
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)
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)
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)
def list_configurations(self): """List configurations.""" url = self.session.build_url('content_delivery', 'configurations') response = self.session.get(url) json = decode_json(response, 200) return many_of(Configuration, json)
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)