예제 #1
0
    def put(self, repo_name, commit_id, tag):
        if repo_name in dms:
            dm = dms[repo_name]
            payload = PayLoad.create_by_rollback(commit_id, tag, repo_name, self.get_current_user().username)

            mongodb_client['deployment']['webhook'].insert({'event': 'rollback',
                                                            "event_id": payload.event_id,
                                                            "repoName": repo_name,
                                                            'payload': vars(payload),
                                                            'createTimeStamp': int(time.time())})
            t = threading.Thread(target=dm.handle_event,
                                 args=(payload.event_id, payload.event_type, payload))
            t.start()

            # log to db
            mongodb_client['deployment']['operation_log'].insert({
                "userId": self.get_current_user().user_id,
                "username": self.get_current_user().username,
                "repoName": repo_name,
                "operation": "rollback",
                "event_id": payload.event_id,
                "rollback_to_commit": commit_id,
                "rollback_to_tag": tag,
                "createTimeStamp": int(time.time())
            })

            self.set_status(200)
예제 #2
0
    def put(self, repo_name, branch, commit_id, tag):
        if repo_name in dmc and branch in dmc[repo_name]:
            dm = dmc[repo_name][branch]
            payload = PayLoad.create_by_rollback(commit_id, tag, repo_name, self.get_current_user().username)

            mongodb_client["deployment"]["webhook"].insert(
                {
                    "event": "rollback",
                    "event_id": payload.event_id,
                    "repoName": repo_name,
                    "branch": branch,
                    "payload": vars(payload),
                    "createTimeStamp": int(time.time()),
                }
            )
            t = threading.Thread(target=dm.handle_event, args=(payload.event_id, payload.event_type, payload))
            t.start()

            # log to db
            mongodb_client["deployment"]["operation_log"].insert(
                {
                    "userId": self.get_current_user().user_id,
                    "username": self.get_current_user().username,
                    "repoName": repo_name,
                    "operation": "rollback",
                    "event_id": payload.event_id,
                    "rollback_to_commit": commit_id,
                    "rollback_to_tag": tag,
                    "createTimeStamp": int(time.time()),
                }
            )

            self.set_status(200)
예제 #3
0
    def put(self, repo_name, commit_id, tag):
        if repo_name in dms:
            dm = dms[repo_name]
            payload = PayLoad.create_by_rollback(
                commit_id, tag, repo_name,
                self.get_current_user().username)

            mongodb_client['deployment']['webhook'].insert({
                'event':
                'rollback',
                "event_id":
                payload.event_id,
                "repoName":
                repo_name,
                'payload':
                vars(payload),
                'createTimeStamp':
                int(time.time())
            })
            t = threading.Thread(target=dm.handle_event,
                                 args=(payload.event_id, payload.event_type,
                                       payload))
            t.start()

            # log to db
            mongodb_client['deployment']['operation_log'].insert({
                "userId":
                self.get_current_user().user_id,
                "username":
                self.get_current_user().username,
                "repoName":
                repo_name,
                "operation":
                "rollback",
                "event_id":
                payload.event_id,
                "rollback_to_commit":
                commit_id,
                "rollback_to_tag":
                tag,
                "createTimeStamp":
                int(time.time())
            })

            self.set_status(200)
예제 #4
0
    def post(self):
        # Auth git request
        self.event = self.request.headers.get('X-Github-Event', None)  # event name like 'push'...
        self.signature = self.request.headers.get('X-Hub-Signature', None).split('=')[
            1]  # e.g. sha1=a8d9e5c1c6e0f19b5a508c508d5204de171cbf1b
        self.delivery_uuid = self.request.headers.get('X-Github-Delivery', None)  # deliver uuid

        if _DEBUG == True:
            logger_server.debug(
                "Post Github Delivery[{uuid}] which type is [{type}] with signature [{signature}]".format(
                    uuid=self.delivery_uuid,
                    type=self.event,
                    signature=self.signature))
        h = hmac.new(_GITHUB_CFG['SECRET'].encode('utf8'), digestmod='sha1')
        h.update(self.request.body)
        # Fail
        if h.hexdigest() != self.signature:
            self.set_status(401)
        elif not self.event or not self.signature or not self.delivery_uuid:
            self.set_status(401)
        elif self.event == 'ping':
            if _DEBUG == True:
                logger_server.debug("Ping pass..")
        else:
            # Pass
            if _DEBUG == True:
                logger_server.debug("Auth pass..")
            self.payload = json.loads(self.request.body.decode("utf8"))
            payload = PayLoad.create_by_payload(self.delivery_uuid, self.event, self.payload)
            if _DEBUG == True:
                logger_server.debug("Is Tag:{istag}".format(istag=str(payload.is_tag)))
            repo_name = payload.repository_name
            if _DEBUG == True:
                logger_server.debug("Repo Name:{repo_name}".format(repo_name=repo_name))
            if payload and repo_name in dms:
                # Logging to db
                mongodb_client['deployment']['webhook'].insert({'event': self.event,
                                                                'signature': self.signature,
                                                                'delivery_uuid': self.delivery_uuid,
                                                                'payload': self.payload})
                t = threading.Thread(target=dms[repo_name].handle_event,
                                     args=(self.delivery_uuid, self.event, payload))
                t.start()