Esempio n. 1
0
    def get(self, parent_job_id):
        job_id = g.token['job']['id']

        if not validate_uuid4(parent_job_id):
            abort(400, "Invalid uuid")

        dependencies = g.db.execute_one(
            '''
            SELECT dependencies
            FROM job
            WHERE id = %s
        ''', [job_id])[0]

        is_valid_dependency = False
        for dep in dependencies:
            if dep['job-id'] == parent_job_id:
                is_valid_dependency = True
                break

        if not is_valid_dependency:
            abort(404, "Job not found")

        key = "%s.tar.gz" % parent_job_id
        key = key.replace('/', '_')

        g.release_db()
        f = storage.download_output(key)

        if not f:
            abort(404)

        return send_file(f)
Esempio n. 2
0
    def get(self, parent_job_id):
        job_id = g.token['job']['id']

        if not validate_uuid4(parent_job_id):
            abort(400, "Invalid uuid")

        filename = request.args.get('filename', None)

        if not filename:
            abort(400, "Invalid filename")

        dependencies = g.db.execute_one('''
            SELECT dependencies
            FROM job
            WHERE id = %s
        ''', [job_id])[0]

        is_valid_dependency = False
        for dep in dependencies:
            if dep['job-id'] == parent_job_id:
                is_valid_dependency = True
                break

        if not is_valid_dependency:
            abort(404, "Job not found")

        key = "%s/%s" % (parent_job_id, filename)

        g.release_db()
        f = storage.download_output(key)

        if not f:
            abort(404)

        return send_file(f)
Esempio n. 3
0
    def delete(self, project_id):
        if not validate_uuid4(project_id):
            abort(400, "Invalid project uuid.")

        project = g.db.execute_one_dict(
            """
            DELETE FROM project WHERE id = %s RETURNING type
        """, [project_id])

        if not project:
            abort(400, 'Project with such an id does not exist.')

        if project['type'] == 'github':
            repo = g.db.execute_one_dict(
                '''
                SELECT name, github_owner, github_hook_id
                FROM repository
                WHERE project_id = %s
            ''', [project_id])

            gh_owner = repo['github_owner']
            gh_hook_id = repo['github_hook_id']
            gh_repo_name = repo['name']

            user = g.db.execute_one_dict(
                '''
                SELECT github_api_token
                FROM "user"
                WHERE id = %s
            ''', [g.token['user']['id']])
            gh_api_token = user['github_api_token']

            headers = {
                "Authorization": "token " + gh_api_token,
                "User-Agent": "InfraBox"
            }
            url = '%s/repos/%s/%s/hooks/%s' % (
                os.environ['INFRABOX_GITHUB_API_URL'], gh_owner, gh_repo_name,
                gh_hook_id)

            # TODO(ib-steffen): allow custom ca bundles
            requests.delete(url, headers=headers, verify=False)

        # TODO: delete all tables
        g.db.execute(
            '''
            DELETE FROM repository
            WHERE project_id = %s
        ''', [project_id])

        g.db.execute(
            '''
            DELETE FROM collaborator
            WHERE project_id = %s
        ''', [project_id])

        g.db.commit()

        return OK('deleted project')
Esempio n. 4
0
    def delete(self, project_id, token_id):
        if not validate_uuid4(token_id):
            abort(400, "Invalid project-token uuid")

        num_tokens = g.db.execute_one("""
            SELECT COUNT(*) FROM auth_token
            WHERE project_id = %s and id = %s
        """, [project_id, token_id])[0]

        if num_tokens == 0:
            return abort(400, 'Such token does not exist.')

        g.db.execute("""
                     DELETE FROM auth_token
                     WHERE project_id = %s and id = %s
        """, [project_id, token_id])
        g.db.commit()

        return OK('Successfully deleted token')
Esempio n. 5
0
    def delete(self, project_id, secret_id):
        if not validate_uuid4(secret_id):
            abort(400, "Invalid secret uuid.")

        num_secrets = g.db.execute_one(
            """
            SELECT COUNT(*) FROM secret
            WHERE project_id = %s and id = %s
        """, [project_id, secret_id])[0]

        if num_secrets == 0:
            return abort(400, 'Such secret does not exist.')

        g.db.execute(
            """
            DELETE FROM secret WHERE project_id = %s and id = %s
        """, [project_id, secret_id])
        g.db.commit()

        return OK('Successfully deleted secret.')