def get(self): """Return this service.""" policy.check('show_service', pecan.request.security_context) handler = service_handler.ServiceHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return service.Service.from_db_model(handler.get(self._id), host_url)
def put(self): """Modify this plan.""" policy.check('update_plan', pecan.request.security_context) # make sure the plan exists before parsing the request handler = plan_handler.PlanHandler(pecan.request.security_context) handler.get(self._id) host_url = pecan.request.application_url.rstrip('/') if not pecan.request.body or len(pecan.request.body) < 1: raise exception.BadRequest(reason="No data.") if (pecan.request.content_type is not None and 'yaml' in pecan.request.content_type): data = init_yml_plan_by_version() updated_plan_yml = yamlutils.dump(yaml_content(handler.update( self._id, data.as_dict(objects.registry.Plan)))) else: data = init_json_plan_by_version() plan_obj = handler.update(self._id, data.as_dict(objects.registry.Plan)) updated_plan_yml = wsme_json.encode_result(plan.Plan.from_db_model( plan_obj, host_url), plan.Plan) pecan.response.status = 200 return updated_plan_yml
def post(self, data): """Create a new assembly.""" policy.check('create_assembly', pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') js_data = data.as_dict(objects.registry.Assembly) if data.plan_uri is not wsme.Unset: plan_uri = data.plan_uri if plan_uri.startswith(host_url): pl_uuid = plan_uri.split('/')[-1] pl = objects.registry.Plan.get_by_uuid( pecan.request.security_context, pl_uuid) js_data['plan_id'] = pl.id else: # TODO(asalkeld) we are not hosting the plan so # download the plan and insert it into our db. raise exception.BadRequest(reason=_( 'The plan was not hosted in solum')) if js_data.get('plan_id') is None: raise exception.BadRequest(reason=_( 'The plan was not given or could not be found')) handler = assembly_handler.AssemblyHandler( pecan.request.security_context) return assembly.Assembly.from_db_model( handler.create(js_data), host_url)
def delete(self): """Delete this pipeline.""" policy.check('delete_pipeline', pecan.request.security_context) handler = pipeline_handler.PipelineHandler( pecan.request.security_context) return handler.delete(self._id)
def delete(self): """Delete this component.""" policy.check('delete_component', pecan.request.security_context) handler = component_handler.ComponentHandler( pecan.request.security_context) return handler.delete(self._id)
def post(self, data): """Create a new pipeline.""" policy.check('create_pipeline', pecan.request) js_data = data.as_dict(objects.registry.Pipeline) host_url = pecan.request.application_url.rstrip('/') if data.plan_uri is not wsme.Unset: plan_uri = data.plan_uri if plan_uri.startswith(host_url): pl_uuid = plan_uri.split('/')[-1] pl = objects.registry.Plan.get_by_uuid( pecan.request.security_context, pl_uuid) js_data['plan_id'] = pl.id else: # TODO(asalkeld) we are not hosting the plan so # download the plan and insert it into our db. raise exception.BadRequest(reason=_( 'The plan was not hosted in solum')) if js_data.get('plan_id') is None: raise exception.BadRequest(reason=_( 'The plan was not given or could not be found')) handler = pipeline_handler.PipelineHandler( pecan.request.security_context) return pipeline.Pipeline.from_db_model( handler.create(js_data), host_url)
def delete(self): """Delete this service.""" policy.check('delete_service', pecan.request.security_context) handler = service_handler.ServiceHandler( pecan.request.security_context) return handler.delete(self._id)
def post(self, data): """Create a new sensor.""" policy.check('create_sensor', pecan.request.security_context) handler = sensor_handler.SensorHandler(pecan.request.security_context) obj = handler.create(data.as_dict(objects.registry.Sensor)) host_url = pecan.request.application_url.rstrip('/') return sensor.Sensor.from_db_model(obj, host_url)
def delete(self): """Delete this assembly.""" policy.check('delete_assembly', pecan.request.security_context) handler = assembly_handler.AssemblyHandler( pecan.request.security_context) return handler.delete(self._id)
def delete(self): """Delete this operation.""" policy.check('delete_operation', pecan.request.security_context) handler = operation_handler.OperationHandler( pecan.request.security_context) handler.delete(self._id)
def delete(self): """Delete this extension.""" policy.check('delete_extension', pecan.request.security_context) handler = extension_handler.ExtensionHandler( pecan.request.security_context) handler.delete(self._id)
def delete(self): """Delete a languagepack.""" policy.check('delete_languagepack', pecan.request.security_context) handler = language_pack_handler.LanguagePackHandler( pecan.request.security_context) return handler.delete(self._id)
def put(self, data): """Modify this sensor.""" policy.check('update_sensor', pecan.request.security_context) handler = sensor_handler.SensorHandler(pecan.request.security_context) obj = handler.update(self._id, data.as_dict(objects.registry.Sensor)) host_url = pecan.request.application_url.rstrip('/') return sensor.Sensor.from_db_model(obj, host_url)
def put(self, data): """Modify this assembly.""" policy.check('update_assembly', pecan.request.security_context) handler = assembly_handler.AssemblyHandler( pecan.request.security_context) res = handler.update(self._id, data.as_dict(objects.registry.Assembly)) host_url = pecan.request.application_url.rstrip('/') return assembly.Assembly.from_db_model(res, host_url)
def get(self): """Return this pipeline.""" policy.check('show_pipeline', pecan.request.security_context) handler = pipeline_handler.PipelineHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return pipeline.Pipeline.from_db_model(handler.get(self._id), host_url)
def get(self): """Return this assembly.""" policy.check('show_assembly', pecan.request.security_context) request.check_request_for_https() handler = assembly_handler.AssemblyHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return assembly.Assembly.from_db_model(handler.get(self._id), host_url)
def post(self, data): """Create a new extension.""" policy.check('create_extension', pecan.request.security_context) handler = extension_handler.ExtensionHandler( pecan.request.security_context) obj = handler.create(data.as_dict(objects.registry.Extension)) host_url = pecan.request.application_url.rstrip('/') return extension.Extension.from_db_model(obj, host_url)
def get(self): """Return this extension.""" policy.check('show_extension', pecan.request.security_context) handler = extension_handler.ExtensionHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return extension.Extension.from_db_model(handler.get(self._id), host_url)
def get(self): """Return a languagepack.""" policy.check('show_languagepack', pecan.request.security_context) handler = language_pack_handler.LanguagePackHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return language_pack.LanguagePack.from_db_model( handler.get(self._id), host_url)
def get_all(self): """Return all sensors, based on the query provided.""" policy.check('get_sensors', pecan.request.security_context) handler = sensor_handler.SensorHandler(pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [ sensor.Sensor.from_db_model(obj, host_url) for obj in handler.get_all() ]
def post(self, data): """Create a new operation.""" policy.check('create_operation', pecan.request.security_context) handler = operation_handler.OperationHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return operation.Operation.from_db_model(handler.create( data.as_dict(objects.registry.Operation)), host_url)
def delete(self): """Delete this plan.""" policy.check('delete_plan', pecan.request.security_context) p_handler = plan_handler.PlanHandler(pecan.request.security_context) try: p_handler.delete(self._id) except (db_exc.DBError): raise exception.PlanStillReferenced(name=self._id)
def get_all(self): """Return all operations, based on the query provided.""" policy.check('get_operations', pecan.request.security_context) handler = operation_handler.OperationHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [operation.Operation.from_db_model(obj, host_url) for obj in handler.get_all()]
def get_all(self): """Return all services, based on the query provided.""" policy.check('get_services', pecan.request.security_context) handler = service_handler.ServiceHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [service.Service.from_db_model(ser, host_url) for ser in handler.get_all()]
def post(self, data): """Create a new service.""" policy.check('create_service', pecan.request.security_context) handler = service_handler.ServiceHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return service.Service.from_db_model( handler.create(data.as_dict(objects.registry.Service)), host_url)
def get(self): """Return this component.""" policy.check('show_component', pecan.request.security_context) handler = component_handler.ComponentHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return component.Component.from_db_model(handler.get(self._id), host_url)
def post(self, data): """Create a new component.""" policy.check('create_component', pecan.request.security_context) handler = component_handler.ComponentHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return component.Component.from_db_model( handler.create(data.as_dict(objects.registry.Component)), host_url)
def get_all(self): """Return all components, based on the query provided.""" policy.check('get_components', pecan.request.security_context) handler = component_handler.ComponentHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [component.Component.from_db_model(ser, host_url) for ser in handler.get_all()]
def get_all(self): """Return all languagepacks, based on the query provided.""" policy.check('get_languagepacks', pecan.request.security_context) handler = language_pack_handler.LanguagePackHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [language_pack.LanguagePack.from_db_model(img, host_url) for img in handler.get_all()]
def get_all(self): """Return all extensions, based on the query provided.""" policy.check('get_extensions', pecan.request.security_context) handler = extension_handler.ExtensionHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [extension.Extension.from_db_model(obj, host_url) for obj in handler.get_all()]
def get_all(self, pipeline_id): """Return all executions, based on the provided pipeline_id.""" policy.check('get_pipeline_executions', pecan.request.security_context) handler = pipeline_handler.PipelineHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [execution.Execution.from_db_model(obj, host_url) for obj in handler.get(pipeline_id).executions]
def put(self, data): """Modify this extension.""" policy.check('update_extension', pecan.request.security_context) handler = extension_handler.ExtensionHandler( pecan.request.security_context) obj = handler.update(self._id, data.as_dict(objects.registry.Extension)) host_url = pecan.request.application_url.rstrip('/') return extension.Extension.from_db_model(obj, host_url)
def get_all(self): """Return all pipelines.""" policy.check('get_pipelines', pecan.request.security_context) handler = pipeline_handler.PipelineHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [pipeline.Pipeline.from_db_model(obj, host_url) for obj in handler.get_all()]
def post(self, trigger_id): """Trigger a new event on Solum.""" policy.check('create_trigger', pecan.request.security_context) commit_sha = '' status_url = None collab_url = None try: query = query_dict(pecan.request.query_string) workflow = self._get_workflow(query) body = json.loads(pecan.request.body) if ('sender' in body and 'url' in body['sender'] and 'api.github.com' in body['sender']['url']): action = body.get('action', None) if 'comment' in body: # Process a request for rebuilding commit_sha, collab_url = self._process_request(body) elif 'pull_request' in body: # Process a GitHub pull request commit_sha = body['pull_request']['head']['sha'] else: raise exception.NotImplemented() # An example of Github statuses_url # https://api.github.com/repos/:user/:repo/statuses/{sha} if commit_sha: status_url = body['repository']['statuses_url'].format( sha=commit_sha) else: # Request NOT from a Github repo raise exception.NotImplemented() except Exception as exc: if isinstance(exc, exception.SolumException): raise info_msg = "Expected fields not found in request body." LOG.info(info_msg) raise exception.BadRequest(reason=info_msg) try: # Trigger workflow only on PR create and on rebuild request if action in [ 'created', 'opened', 'edited', 'reopened', 'synchronize', 'closed' ]: handler = app_handler.AppHandler(None) handler.trigger_workflow(trigger_id, commit_sha, status_url, collab_url, workflow=workflow) except exception.ResourceNotFound: LOG.error("Incorrect trigger url.") raise pecan.response.status = 202
def get_all(self, pipeline_id): """Return all executions, based on the provided pipeline_id.""" policy.check('get_pipeline_executions', pecan.request.security_context) handler = pipeline_handler.PipelineHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [ execution.Execution.from_db_model(obj, host_url) for obj in handler.get(pipeline_id).executions ]
def put(self, data): """Modify this component.""" policy.check('update_component', pecan.request.security_context) handler = component_handler.ComponentHandler( pecan.request.security_context) res = handler.update(self._id, data.as_dict(objects.registry.Component)) host_url = pecan.request.application_url.rstrip('/') return component.Component.from_db_model(res, host_url)
def put(self, data): """Modify this pipeline.""" policy.check('update_pipeline', pecan.request.security_context) handler = pipeline_handler.PipelineHandler( pecan.request.security_context) res = handler.update(self._id, data.as_dict(objects.registry.Pipeline)) host_url = pecan.request.application_url.rstrip('/') return pipeline.Pipeline.from_db_model(res, host_url)
def put(self, data): """Modify this service.""" policy.check('update_service', pecan.request.security_context) handler = service_handler.ServiceHandler( pecan.request.security_context) res = handler.update(self._id, data.as_dict(objects.registry.Service)) host_url = pecan.request.application_url.rstrip('/') return service.Service.from_db_model(res, host_url)
def get_all(self): """Return all assemblies, based on the query provided.""" policy.check('get_assemblies', pecan.request.security_context) request.check_request_for_https() handler = assembly_handler.AssemblyHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [assembly.Assembly.from_db_model(assm, host_url) for assm in handler.get_all()]
def put(self, data): """Modify this operation.""" policy.check('update_operation', pecan.request.security_context) handler = operation_handler.OperationHandler( pecan.request.security_context) res = handler.update(self._id, data.as_dict(objects.registry.Operation)) host_url = pecan.request.application_url.rstrip('/') return operation.Operation.from_db_model(res, host_url)
def get(self): """Return a languagepack.""" policy.check('show_languagepack', pecan.request.security_context) handler = language_pack_handler.LanguagePackHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return language_pack.LanguagePack.from_db_model(handler.get(self._id), host_url)
def get_all(self): """Return all languagepacks, based on the query provided.""" policy.check('get_languagepacks', pecan.request.security_context) handler = language_pack_handler.LanguagePackHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [ language_pack.LanguagePack.from_db_model(img, host_url) for img in handler.get_all() ]
def get_all(self): """Return all assemblies, based on the query provided.""" policy.check('get_assemblies', pecan.request.security_context) request.check_request_for_https() handler = assembly_handler.AssemblyHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return [ assembly.Assembly.from_db_model(assm, host_url) for assm in handler.get_all() ]
def post(self, trigger_id): """Trigger a new event on Solum.""" policy.check('create_trigger', pecan.request.security_context) commit_sha = '' status_url = None collab_url = None try: query = query_dict(pecan.request.query_string) workflow = self._get_workflow(query) body = json.loads(pecan.request.body) if ('sender' in body and 'url' in body['sender'] and 'api.github.com' in body['sender']['url']): action = body.get('action', None) if 'comment' in body: # Process a request for rebuilding commit_sha, collab_url = self._process_request(body) elif 'pull_request' in body: # Process a GitHub pull request commit_sha = body['pull_request']['head']['sha'] else: raise exception.NotImplemented() # An example of Github statuses_url # https://api.github.com/repos/:user/:repo/statuses/{sha} if commit_sha: status_url = body['repository']['statuses_url'].format( sha=commit_sha) else: # Request NOT from a Github repo raise exception.NotImplemented() except Exception as exc: if isinstance(exc, exception.SolumException): raise info_msg = "Expected fields not found in request body." LOG.info(info_msg) raise exception.BadRequest(reason=info_msg) try: # Trigger workflow only on PR create and on rebuild request if action in ['created', 'opened', 'edited', 'reopened', 'synchronize', 'closed']: handler = app_handler.AppHandler(None) handler.trigger_workflow(trigger_id, commit_sha, status_url, collab_url, workflow=workflow) except exception.ResourceNotFound: LOG.error("Incorrect trigger url.") raise pecan.response.status = 202