Beispiel #1
0
def attach_bitbucket_trigger(namespace_name, repo_name):
    permission = AdministerRepositoryPermission(namespace_name, repo_name)
    if permission.can():
        repo = model.repository.get_repository(namespace_name, repo_name)
        if not repo:
            msg = "Invalid repository: %s/%s" % (namespace_name, repo_name)
            abort(404, message=msg)
        elif repo.kind.name != "image":
            abort(501)

        trigger = model.build.create_build_trigger(
            repo, BitbucketBuildTrigger.service_name(), None,
            current_user.db_user())

        try:
            oauth_info = BuildTriggerHandler.get_handler(
                trigger).get_oauth_url()
        except TriggerProviderException:
            trigger.delete_instance()
            logger.debug("Could not retrieve Bitbucket OAuth URL")
            abort(500)

        config = {"access_token": oauth_info["access_token"]}

        access_token_secret = oauth_info["access_token_secret"]
        model.build.update_build_trigger(trigger,
                                         config,
                                         auth_token=access_token_secret)

        return redirect(oauth_info["url"])

    abort(403)
Beispiel #2
0
def attach_gitlab_build_trigger():
    state = request.args.get("state", None)
    if not state:
        abort(400)
    state = state[len("repo:") :]
    try:
        [namespace, repository] = state.split("/")
    except ValueError:
        abort(400)

    permission = AdministerRepositoryPermission(namespace, repository)
    if permission.can():
        code = request.args.get("code")
        token = gitlab_trigger.exchange_code_for_token(
            app.config, client, code, redirect_suffix="/trigger"
        )
        if not token:
            msg = "Could not exchange token. It may have expired."
            abort(404, message=msg)

        repo = model.repository.get_repository(namespace, repository)
        if not repo:
            msg = "Invalid repository: %s/%s" % (namespace, repository)
            abort(404, message=msg)
        elif repo.kind.name != "image":
            abort(501)

        trigger = model.build.create_build_trigger(repo, "gitlab", token, current_user.db_user())
        repo_path = "%s/%s" % (namespace, repository)
        full_url = url_for("web.buildtrigger", path=repo_path, trigger=trigger.uuid)

        logger.debug("Redirecting to full url: %s", full_url)
        return redirect(full_url)

    abort(403)
Beispiel #3
0
def attach_custom_build_trigger(namespace_name, repo_name):
  permission = AdministerRepositoryPermission(namespace_name, repo_name)
  if permission.can():
    repo = model.repository.get_repository(namespace_name, repo_name)
    if not repo:
      msg = 'Invalid repository: %s/%s' % (namespace_name, repo_name)
      abort(404, message=msg)
    elif repo.kind.name != 'image':
      abort(501)

    trigger = model.build.create_build_trigger(repo, CustomBuildTrigger.service_name(),
                                               None, current_user.db_user())

    repo_path = '%s/%s' % (namespace_name, repo_name)
    full_url = url_for('web.buildtrigger', path=repo_path, trigger=trigger.uuid)
    logger.debug('Redirecting to full url: %s', full_url)
    return redirect(full_url)

  abort(403)
Beispiel #4
0
def attach_gitlab_build_trigger():
    state = request.args.get('state', None)
    if not state:
        abort(400)
    state = state[len('repo:'):]
    try:
        [namespace, repository] = state.split('/')
    except ValueError:
        abort(400)

    permission = AdministerRepositoryPermission(namespace, repository)
    if permission.can():
        code = request.args.get('code')
        token = gitlab_trigger.exchange_code_for_token(
            app.config, client, code, redirect_suffix='/trigger')
        if not token:
            msg = 'Could not exchange token. It may have expired.'
            abort(404, message=msg)

        repo = model.repository.get_repository(namespace, repository)
        if not repo:
            msg = 'Invalid repository: %s/%s' % (namespace, repository)
            abort(404, message=msg)
        elif repo.kind.name != 'image':
            abort(501)

        trigger = model.build.create_build_trigger(repo, 'gitlab', token,
                                                   current_user.db_user())
        repo_path = '%s/%s' % (namespace, repository)
        full_url = url_for('web.buildtrigger',
                           path=repo_path,
                           trigger=trigger.uuid)

        logger.debug('Redirecting to full url: %s', full_url)
        return redirect(full_url)

    abort(403)
Beispiel #5
0
def attach_github_build_trigger(namespace_name, repo_name):
    permission = AdministerRepositoryPermission(namespace_name, repo_name)
    if permission.can():
        code = request.args.get('code')
        token = github_trigger.exchange_code_for_token(app.config, client,
                                                       code)
        repo = model.repository.get_repository(namespace_name, repo_name)
        if not repo:
            msg = 'Invalid repository: %s/%s' % (namespace_name, repo_name)
            abort(404, message=msg)
        elif repo.kind.name != 'image':
            abort(501)

        trigger = model.build.create_build_trigger(repo, 'github', token,
                                                   current_user.db_user())
        repo_path = '%s/%s' % (namespace_name, repo_name)
        full_url = url_for('web.buildtrigger',
                           path=repo_path,
                           trigger=trigger.uuid)

        logger.debug('Redirecting to full url: %s', full_url)
        return redirect(full_url)

    abort(403)