def post(self, send_build): """ launch build """ project_name = pecan.request.context['project_name'] user = User.fetch(pecan.request.context['username']) project = Project.fetch(user.username, project_name) if project is None: # The project doesn't exist # We have to create it # TODO Maybe it's better to force users to create project before # they can create builds sent_project = {"name": project_name, "username": user.username} project = Project(sent_project, sub_objects=False) if not project.create(): # Handle error return {"result": "Error creating %s project" % project_name} build = Build(send_build) build.username = user.username build.project_name = project.name build.create() carrier = Carrier(pecan.conf.rabbit_server, pecan.conf.rabbit_port, pecan.conf.rabbit_user, pecan.conf.rabbit_password, pecan.conf.rabbit_vhost, pecan.conf.rabbit_db) carrier.declare_queue('builds.queue') # carrier.declare_builds() if not carrier.send_message(build.dumps(), 'builds.queue'): return None return {"result": {"build": int(build.id_)}}
def post(self, send_build): """ launch build """ project_name = pecan.request.context['project_name'] user = User.fetch(pecan.request.context['username']) project = Project.fetch(user.username, project_name) if project is None: # The project doesn't exist # We have to create it # TODO Maybe it's better to force users to create project before # they can create builds sent_project = {"name": project_name, "username": user.username} project = Project(sent_project, sub_objects=False) if not project.create(): # Handle error return {"result": "Error creating %s project" % project_name} build = Build(send_build) build.username = user.username build.project_name = project.name build.create() carrier = Carrier( pecan.conf.rabbit_server, pecan.conf.rabbit_port, pecan.conf.rabbit_user, pecan.conf.rabbit_password, pecan.conf.rabbit_vhost, pecan.conf.rabbit_db ) carrier.declare_queue('builds.queue') # carrier.declare_builds() if not carrier.send_message(build.dumps(), 'builds.queue'): return None return {"result": {"build": int(build.id_)}}
def post(self): """ launch build from gitlab webhook""" body = pecan.request.json # Get use if not body.get('user_id'): abort(403) # Get token token = pecan.request.GET.get('token') if token is None: abort(403) # Get project project = Project.fetch_from_token(token, False) if project is None: abort(403) if body.get('project_id') != project.gitlab_project_id: abort(403) if body.get('object_kind') not in ['push', 'tag']: abort(403) else: # If it's a TAG event we DON'T make snaphot snapshot = False if body.get('object_kind') == 'push': # If it's a PUSH event we make snapshot snapshot = True if not body.get('repository'): abort(403) repository = body.get('repository') project_name = repository.get('name') if project_name != project.name: abort(403) new_build = { "source_url": repository.get('git_http_url'), #"source_type": "gitlab", "source_type": "git", "commit": body.get('after'), # TODO Find how decide if is a snapshot or not "snapshot": snapshot, # TODO Check if branch ~= ref "branch": body.get('ref'), } build = Build(new_build) build.username = project.username build.project_name = project.name build.create() carrier = Carrier(pecan.conf.rabbit_server, pecan.conf.rabbit_port, pecan.conf.rabbit_user, pecan.conf.rabbit_password, pecan.conf.rabbit_vhost, pecan.conf.rabbit_db) carrier.declare_queue('builds.queue') # carrier.declare_builds() if not carrier.send_message(build.dumps(), 'builds.queue'): return None return json.dumps({"result": True, "build": int(build.id_)}) abort(403)
def post(self): """Launch build from github webhook""" body = pecan.request.json # Get user if not body.get('sender'): abort(403) # Get username username = body.get('repository').get('owner').get('name') if username is None: username = body.get('repository').get('owner').get('login') user = User.fetch(username) if user is None: abort(403) # Check signature signature = pecan.request.headers.get('X-Hub-Signature') sha_name, signature = signature.split("=") if sha_name != 'sha1': abort(403) mac = hmac.new(user.token.encode("utf-8"), pecan.request.text, digestmod=hashlib.sha1) if not hmac.compare_digest(mac.hexdigest(), signature): abort(403) # Ping event if pecan.request.headers.get('X-Github-Event') == 'ping': return json.dumps({"result": True, "event": "ping"}) # TODO handle tag event # Push Event if pecan.request.headers.get('X-Github-Event') == 'push': if not body.get('repository'): abort(403) repository = body.get('repository') project_name = repository.get('name') if not project_name: abort(403) project = Project.fetch(user.username, project_name) if project is None: # Error project doesn't exits # Maybe We should create it return json.dumps({"result": False , "error": "project not found"}) new_build = {"source_url": repository.get('clone_url'), #"source_type": "github", "source_type": "git", "commit": repository.get('commit'), # TODO Find how decide if is a snapshot or not # Answer: on tag event => NOT "snapshot": True, # TODO Check if branch ~= ref "branch": repository.get('ref'), } build = Build(new_build) build.username = user.username build.project_name = project.name build.create() carrier = Carrier( pecan.conf.rabbit_server, pecan.conf.rabbit_port, pecan.conf.rabbit_user, pecan.conf.rabbit_password, pecan.conf.rabbit_vhost, pecan.conf.rabbit_db ) carrier.declare_queue('builds.queue') # carrier.declare_builds() if not carrier.send_message(build.dumps(), 'builds.queue'): return None return json.dumps({"result": True, "build": int(build.id_)}) abort(403)
def post(self): """ launch build from gitlab webhook""" body = pecan.request.json # Get use if not body.get('user_id'): abort(403) # Get token token = pecan.request.GET.get('token') if token is None: abort(403) # Get project project = Project.fetch_from_token(token, False) if project is None: abort(403) if body.get('project_id') != project.gitlab_project_id: abort(403) if body.get('object_kind') not in ['push', 'tag']: abort(403) else: # If it's a TAG event we DON'T make snaphot snapshot = False if body.get('object_kind') == 'push': # If it's a PUSH event we make snapshot snapshot = True if not body.get('repository'): abort(403) repository = body.get('repository') project_name = repository.get('name') if project_name != project.name: abort(403) new_build = {"source_url": repository.get('git_http_url'), #"source_type": "gitlab", "source_type": "git", "commit": body.get('after'), # TODO Find how decide if is a snapshot or not "snapshot": snapshot, # TODO Check if branch ~= ref "branch": body.get('ref'), } build = Build(new_build) build.username = project.username build.project_name = project.name build.create() carrier = Carrier( pecan.conf.rabbit_server, pecan.conf.rabbit_port, pecan.conf.rabbit_user, pecan.conf.rabbit_password, pecan.conf.rabbit_vhost, pecan.conf.rabbit_db ) carrier.declare_queue('builds.queue') # carrier.declare_builds() if not carrier.send_message(build.dumps(), 'builds.queue'): return None return json.dumps({"result": True, "build": int(build.id_)}) abort(403)