class AkamaiSanCertConfigController(base.Controller, hooks.HookController): __hooks__ = [poppy_hooks.Context(), poppy_hooks.Error()] @pecan.expose('json') @decorators.validate(san_cert_name=rule.Rule( helpers.is_valid_domain_by_name(), helpers.abort_with_message)) def get_one(self, san_cert_name): try: res = (self._driver.manager.ssl_certificate_controller. get_san_cert_configuration(san_cert_name)) except Exception as e: pecan.abort(400, str(e)) return res @pecan.expose('json') @decorators.validate( san_cert_name=rule.Rule(helpers.is_valid_domain_by_name(), helpers.abort_with_message), request=rule.Rule( helpers.json_matches_service_schema( ssl_certificate.SSLCertificateSchema.get_schema( "config", "POST")), helpers.abort_with_message, stoplight_helpers.pecan_getter)) def post(self, san_cert_name): config_json = json.loads(pecan.request.body.decode('utf-8')) try: res = (self._driver.manager.ssl_certificate_controller. update_san_cert_configuration(san_cert_name, config_json)) except Exception as e: pecan.abort(400, str(e)) return res
class DomainController(base.Controller, hooks.HookController): __hooks__ = [poppy_hooks.Context(), poppy_hooks.Error()] def __init__(self, driver): super(DomainController, self).__init__(driver) self._conf = driver.conf @pecan.expose('json') @decorators.validate(domain_name=rule.Rule( helpers.is_valid_domain_by_name(), helpers.abort_with_message)) def get_one(self, domain_name): services_controller = self._driver.manager.services_controller try: service_obj = services_controller.get_service_by_domain_name( domain_name) except LookupError: pecan.abort(404, detail='Domain %s cannot be found' % domain_name) # convert a service model into a response service model return resp_service_model.Model(service_obj, self) @pecan.expose('json') @decorators.validate(request=rule.Rule(helpers.is_valid_provider_url(), helpers.abort_with_message, stoplight_helpers.pecan_getter)) def get(self): services_controller = self._driver.manager.services_controller call_args = getattr(pecan.request.context, "call_args") provider_url = call_args.pop('provider_url') domains = services_controller.get_domains_by_provider_url(provider_url) return pecan.Response(json_body=domains, status=200)
class AdminCertController(base.Controller, hooks.HookController): __hooks__ = [poppy_hooks.Context(), poppy_hooks.Error()] def __init__(self, driver): super(AdminCertController, self).__init__(driver) @pecan.expose('json') @decorators.validate(request=rule.Rule( helpers.is_valid_certificate_status(), helpers.abort_with_message, stoplight_helpers.pecan_getter)) def get(self): ssl_certificate_controller = ( self._driver.manager.ssl_certificate_controller) call_args = getattr(pecan.request.context, "call_args") status = call_args.pop('status') cert_domains = ssl_certificate_controller.get_certs_by_status(status) return pecan.Response(json_body=cert_domains, status=200) @pecan.expose('json') @decorators.validate( domain_name=rule.Rule(helpers.is_valid_domain_by_name(), helpers.abort_with_message), request=rule.Rule( helpers.json_matches_service_schema( ssl_certificate.SSLCertificateSchema.get_schema( "admin_cert_status", "PATCH")), helpers.abort_with_message, stoplight_helpers.pecan_getter)) 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)
class DomainController(base.Controller, hooks.HookController): __hooks__ = [poppy_hooks.Context(), poppy_hooks.Error()] def __init__(self, driver): super(DomainController, self).__init__(driver) self._conf = driver.conf @pecan.expose('json') @decorators.validate(domain_name=rule.Rule( helpers.is_valid_domain_by_name(), helpers.abort_with_message)) def get_one(self, domain_name): services_controller = self._driver.manager.services_controller try: service_obj = services_controller.get_service_by_domain_name( domain_name) except LookupError: pecan.abort(404, detail='Domain %s cannot be found' % domain_name) # convert a service model into a response service model return resp_service_model.Model(service_obj, self)
class SSLCertificateController(base.Controller, hooks.HookController): __hooks__ = [poppy_hooks.Context(), poppy_hooks.Error()] @pecan.expose('json') @decorators.validate( request=rule.Rule( helpers.json_matches_service_schema( ssl_certificate_validation.SSLCertificateSchema.get_schema( "ssl_certificate", "POST")), helpers.abort_with_message, stoplight_helpers.pecan_getter)) def post(self): ssl_certificate_controller = ( self._driver.manager.ssl_certificate_controller) certificate_info_dict = json.loads(pecan.request.body.decode('utf-8')) try: project_id = certificate_info_dict.get('project_id') cert_obj = ssl_certificate.load_from_json(certificate_info_dict) cert_obj.project_id = project_id ssl_certificate_controller.create_ssl_certificate(project_id, cert_obj) except LookupError as e: pecan.abort(400, detail='Provisioning ssl certificate failed. ' 'Reason: %s' % str(e)) except ValueError as e: pecan.abort(400, detail='Provisioning ssl certificate failed. ' 'Reason: %s' % str(e)) return pecan.Response(None, 202) @pecan.expose('json') @decorators.validate( domain_name=rule.Rule( helpers.is_valid_domain_by_name(), helpers.abort_with_message) ) def delete(self, domain_name): # For now we only support 'san' cert type cert_type = pecan.request.GET.get('cert_type', 'san') certificate_controller = \ self._driver.manager.ssl_certificate_controller try: certificate_controller.delete_ssl_certificate( self.project_id, domain_name, cert_type ) except ValueError as e: pecan.abort(400, detail='Delete ssl certificate failed. ' 'Reason: %s' % str(e)) return pecan.Response(None, 202) @pecan.expose('json') @decorators.validate( domain_name=rule.Rule( helpers.is_valid_domain_by_name(), helpers.abort_with_message) ) def get_one(self, domain_name): certificate_controller = \ self._driver.manager.ssl_certificate_controller total_cert_info = [] try: # NOTE(TheSriram): we can also enforce project_id constraints certs_info = certificate_controller.get_certs_info_by_domain( domain_name=domain_name, project_id=None) except ValueError: pecan.abort(404, detail='certificate ' 'could not be found ' 'for domain : %s' % domain_name) else: # convert a cert model into a response cert model try: if iter(certs_info): for cert in certs_info: total_cert_info.append(ssl_cert_model.Model(cert)) return total_cert_info except TypeError: return ssl_cert_model.Model(certs_info)