def __init__(self, rule): super(Model, self).__init__() self['name'] = util.help_escape(rule.name) self['request_url'] = util.help_escape(rule.request_url) for attr_name in ['http_host', 'http_method', 'client_ip', 'referrer']: attr = getattr(rule, attr_name, None) if attr is not None: self[attr_name] = util.help_escape(attr)
def __init__(self, rule): super(Model, self).__init__() self['name'] = util.help_escape(rule.name) self['request_url'] = util.help_escape(rule.request_url) for attr_name in ['http_host', 'http_method', 'client_ip', 'request_url', 'referrer', 'geography']: attr = getattr(rule, attr_name, None) if attr is not None: self[attr_name] = util.help_escape(attr)
def __init__(self, ssl_certificate): super(Model, self).__init__() self["flavor_id"] = ssl_certificate.flavor_id self['domain_name'] = util.help_escape(ssl_certificate.domain_name) self['cert_type'] = ssl_certificate.cert_type self['cert_details'] = ssl_certificate.cert_details self['status'] = ssl_certificate.get_cert_status()
def __init__(self, name=None, referrer=None, http_host=None, client_ip=None, geography=None, http_method=None, request_url="/*"): self._name = name self._request_url = request_url if referrer: self._referrer = referrer.strip() if http_host: self._http_host = http_host.strip() if client_ip: self._client_ip = client_ip.strip() if http_method: self._http_method = http_method.strip() if geography: # Validate the geography should be in a list of supported # countries if geography is not None and \ geography not in geo_zones.GEO_COUNTRY_ZONES and \ geography not in geo_zones.GEO_REGION_ZONES: raise ValueError(util.help_escape( 'Country/Area %s is not supported in ' 'geo zones' % geography)) self._geography = geography if request_url: self._request_url = request_url.strip()
def patch_one(self, service_id): service_updates = json.loads(pecan.request.body.decode('utf-8')) services_controller = self._driver.manager.services_controller try: services_controller.update( self.project_id, service_id, self.auth_token, service_updates) except exceptions.ValidationFailed as e: pecan.abort(400, detail=u'{0}'.format(e)) except LookupError as e: # error handler for no flavor pecan.abort(400, detail=str(e)) except ValueError as e: # error handler for existing service name pecan.abort(400, detail=str(e)) except errors.ServiceNotFound as e: pecan.abort(404, detail=str(e)) except errors.ServiceStatusNeitherDeployedNorFailed as e: pecan.abort(400, detail=str(e)) except Exception as e: pecan.abort(400, detail=util.help_escape(str(e))) service_url = str( uri.encode(u'{0}/v1.0/services/{1}'.format( pecan.request.host_url, service_id))) return pecan.Response(None, 202, headers={"Location": service_url})
def __init__(self, name=None, referrer=None, http_host=None, client_ip=None, geography=None, http_method=None, request_url="/*"): self._name = name self._request_url = request_url if referrer: self._referrer = referrer if http_host: self._http_host = http_host if client_ip: self._client_ip = client_ip if http_method: self._http_method = http_method if geography: # Validate the geography should be in a list of supported # countries if geography is not None and \ geography not in geo_zones.GEO_COUNTRY_ZONES and \ geography not in geo_zones.GEO_REGION_ZONES: raise ValueError( util.help_escape('Country/Area %s is not supported in ' 'geo zones' % geography)) self._geography = geography if request_url: self._request_url = request_url
def patch_one(self, service_id): service_updates = json.loads(pecan.request.body.decode('utf-8')) services_controller = self._driver.manager.services_controller try: services_controller.update(self.project_id, service_id, self.auth_token, service_updates) except exceptions.ValidationFailed as e: pecan.abort(400, detail=u'{0}'.format(e)) except LookupError as e: # error handler for no flavor pecan.abort(400, detail=str(e)) except ValueError as e: # error handler for existing service name pecan.abort(400, detail=str(e)) except errors.ServiceNotFound as e: pecan.abort(404, detail=str(e)) except errors.ServiceStatusNeitherDeployedNorFailed as e: pecan.abort(400, detail=str(e)) except errors.SharedShardsExhausted as e: # domain - shared domains exhausted pecan.abort(400, detail=str(e)) except Exception as e: pecan.abort(400, detail=util.help_escape(str(e))) service_url = str( uri.encode(u'{0}/v1.0/services/{1}'.format(pecan.request.host_url, service_id))) return pecan.Response(None, 202, headers={"Location": service_url})
def geography(self, value): if value is not None and \ value not in geo_zones.GEO_COUNTRY_ZONES and \ value not in geo_zones.GEO_REGION_ZONES: raise ValueError( util.help_escape('Country/Area %s is not supported in ' 'geo zones' % value)) self._geography = value
def geography(self, value): if value is not None and \ value not in geo_zones.GEO_COUNTRY_ZONES and \ value not in geo_zones.GEO_REGION_ZONES: raise ValueError(util.help_escape( 'Country/Area %s is not supported in ' 'geo zones' % value)) self._geography = value
def __init__(self, origin): super(Model, self).__init__() self['origin'] = util.help_escape(origin.origin) self['port'] = origin.port self['ssl'] = origin.ssl self['rules'] = [rule.Model(r) for r in origin.rules] self['hostheadertype'] = origin.hostheadertype if origin.hostheadervalue is not None: self['hostheadervalue'] = origin.hostheadervalue
def __init__(self, service_obj, controller): super(Model, self).__init__() self["name"] = util.help_escape(service_obj.name) self["id"] = str(service_obj.service_id) self["domains"] = [domain.Model(d) for d in service_obj.domains] self["origins"] = [origin.Model(o) for o in service_obj.origins] self["restrictions"] = [restriction.Model(r) for r in service_obj.restrictions] self["caching"] = [cachingrules.Model(c) for c in service_obj.caching] self["flavor_id"] = service_obj.flavor_id self["log_delivery"] = log_delivery.Model(service_obj.log_delivery) self["status"] = service_obj.status if service_obj.operator_status == "disabled": self["status"] = service_obj.operator_status self["errors"] = [] self["links"] = [ link.Model( str( uri.encode(u'{0}/services/{1}'.format( controller.base_url, service_obj.service_id))), 'self'), link.Model( str( uri.encode(u'{0}/flavors/{1}'.format( controller.base_url, service_obj.flavor_id))), 'flavor')] for provider_name in service_obj.provider_details: provider_detail = service_obj.provider_details[provider_name] # add the access urls access_urls = provider_detail.access_urls for access_url in access_urls: if 'operator_url' in access_url: self['links'].append(link.Model( access_url['operator_url'], 'access_url')) elif 'log_delivery' in access_url: self['links'].append(link.Model( access_url['log_delivery'][0]['publicURL'], 'log_delivery')) # add any errors error_message = provider_detail.error_message if error_message: self["errors"].append({"message": error_message})
def patch_one(self, domain_name): ssl_certificate_controller = ( self._driver.manager.ssl_certificate_controller) certificate_updates = json.loads(pecan.request.body.decode('utf-8'))[0] try: ssl_certificate_controller.update_certificate_status( domain_name, certificate_updates) except ValueError: pecan.abort( status_code=404, detail='Certificate could not be found for domain: {0}'.format( domain_name)) except Exception as e: pecan.abort(status_code=400, detail=util.help_escape(str(e))) return pecan.Response(body=None, status=204)
def patch_one(self, domain_name): ssl_certificate_controller = ( self._driver.manager.ssl_certificate_controller ) certificate_updates = json.loads(pecan.request.body.decode('utf-8'))[0] try: ssl_certificate_controller.update_certificate_status( domain_name, certificate_updates ) except ValueError: pecan.abort( status_code=404, detail='Certificate could not be found for domain: {0}'.format( domain_name ) ) except Exception as e: pecan.abort(status_code=400, detail=util.help_escape(str(e))) return pecan.Response(body=None, status=204)
def abort_with_message(error_info): pecan.abort(400, detail=util.help_escape( getattr(error_info, "message", "")), headers={'Content-Type': "application/json"})
def __init__(self, domain): super(Model, self).__init__() self['domain'] = util.help_escape(domain.domain) self['protocol'] = domain.protocol if self['protocol'] == 'https': self['certificate'] = domain.certificate
def __init__(self, restriction): super(Model, self).__init__() self['name'] = util.help_escape(restriction.name) self['access'] = restriction.access self['rules'] = [rule.Model(r) for r in restriction.rules]
def abort_with_message(error_info): pecan.abort(400, detail=util.help_escape(getattr(error_info, "message", "")), headers={'Content-Type': "application/json"})
def __init__(self, service_obj, controller): super(Model, self).__init__() self["name"] = util.help_escape(service_obj.name) self["id"] = str(service_obj.service_id) self["project_id"] = str(service_obj.project_id) self["domains"] = [domain.Model(d) for d in service_obj.domains] # default other type of certificate domains to create_in_progress # Note(tonytan4ever): with out this piece of code # there will be a short period of time domain without certificate # status for domain_d in self["domains"]: if domain_d.get("protocol", "http") == "https": if domain_d.get("certificate") == "shared": domain_d["certificate_status"] = 'deployed' else: domain_d["certificate_status"] = 'create_in_progress' self["origins"] = [origin.Model(o) for o in service_obj.origins] self["restrictions"] = [restriction.Model(r) for r in service_obj.restrictions] self["caching"] = [cachingrules.Model(c) for c in service_obj.caching] self["flavor_id"] = service_obj.flavor_id self["log_delivery"] = log_delivery.Model(service_obj.log_delivery) self["status"] = service_obj.status if service_obj.operator_status == "disabled": self["status"] = service_obj.operator_status self["errors"] = [] self["links"] = [ link.Model( str( uri.encode(u'{0}/services/{1}'.format( controller.base_url, service_obj.service_id))), 'self'), link.Model( str( uri.encode(u'{0}/flavors/{1}'.format( controller.base_url, service_obj.flavor_id))), 'flavor')] for provider_name in service_obj.provider_details: provider_detail = service_obj.provider_details[provider_name] # add any certificate_status for non shared ssl domains # Note(tonytan4ever): for right now we only consider one provider, # in case of multiple providers we really should consider all # provider's domain certificate status for domain_d in self["domains"]: if domain_d.get("protocol", "http") == "https": if domain_d.get("certificate") != "shared": domain_d["certificate_status"] = ( provider_detail. domains_certificate_status. get_domain_certificate_status(domain_d['domain'])) # add the access urls access_urls = provider_detail.access_urls for access_url in access_urls: if ( 'operator_url' in access_url and access_url['operator_url'] is not None ): self['links'].append(link.Model( access_url['operator_url'], 'access_url')) elif 'log_delivery' in access_url: self['links'].append(link.Model( access_url['log_delivery'][0]['publicURL'], 'log_delivery')) # add any errors error_message = provider_detail.error_message if error_message: self["errors"].append({"message": error_message})
def __init__(self, origin): super(Model, self).__init__() self['origin'] = util.help_escape(origin.origin) self['port'] = origin.port self['ssl'] = origin.ssl self['rules'] = [rule.Model(r) for r in origin.rules]
def __init__(self, service_obj, controller): super(Model, self).__init__() self["name"] = util.help_escape(service_obj.name) self["id"] = str(service_obj.service_id) self["project_id"] = str(service_obj.project_id) self["domains"] = [domain.Model(d) for d in service_obj.domains] # default other type of certificate domains to create_in_progress # Note(tonytan4ever): with out this piece of code # there will be a short period of time domain without certificate # status for domain_d in self["domains"]: if domain_d.get("protocol", "http") == "https": if domain_d.get("certificate") == "shared": domain_d["certificate_status"] = 'deployed' else: domain_d["certificate_status"] = 'create_in_progress' self["origins"] = [origin.Model(o) for o in service_obj.origins] self["restrictions"] = [ restriction.Model(r) for r in service_obj.restrictions ] self["caching"] = [cachingrules.Model(c) for c in service_obj.caching] self["flavor_id"] = service_obj.flavor_id self["log_delivery"] = log_delivery.Model(service_obj.log_delivery) self["status"] = service_obj.status if service_obj.operator_status == "disabled": self["status"] = service_obj.operator_status self["errors"] = [] self["links"] = [ link.Model( str( uri.encode(u'{0}/services/{1}'.format( controller.base_url, service_obj.service_id))), 'self'), link.Model( str( uri.encode(u'{0}/flavors/{1}'.format( controller.base_url, service_obj.flavor_id))), 'flavor') ] for provider_name in service_obj.provider_details: provider_detail = service_obj.provider_details[provider_name] # add any certificate_status for non shared ssl domains # Note(tonytan4ever): for right now we only consider one provider, # in case of multiple providers we really should consider all # provider's domain certificate status for domain_d in self["domains"]: if domain_d.get("protocol", "http") == "https": if domain_d.get("certificate") != "shared": domain_d["certificate_status"] = ( provider_detail.domains_certificate_status. get_domain_certificate_status(domain_d['domain'])) # add the access urls access_urls = provider_detail.access_urls for access_url in access_urls: if ('operator_url' in access_url and access_url['operator_url'] is not None): self['links'].append( link.Model(access_url['operator_url'], 'access_url')) elif 'log_delivery' in access_url: self['links'].append( link.Model(access_url['log_delivery'][0]['publicURL'], 'log_delivery')) # add any errors error_message = provider_detail.error_message if error_message: self["errors"].append({"message": error_message})
def __init__(self, caching): super(Model, self).__init__() self['name'] = util.help_escape(caching.name) self['ttl'] = caching.ttl if caching.rules != []: self['rules'] = [rule.Model(r) for r in caching.rules]
def __init__(self, restriction): super(Model, self).__init__() self['name'] = util.help_escape(restriction.name) self['type'] = restriction.type self['rules'] = [rule.Model(r) for r in restriction.rules]