Exemplo n.º 1
0
async def handle_required_auth(request):
    res = list()
    try:
        req = common_interfaces.AuthRequired_validate(
            json.loads(request.rel_url.query['authRequired']))
        availableRefs = set()
        for authRef in req['refs']:
            if common_app_server.is_valid_authRef(authRef):
                availableRefs.add(authRef['authId'])
        actionId = req['actionId']
        logger.debug("handle_required_auth for actionId '{}'".format(actionId))
        if actionId == "login":
            res.extend(
                getRequiredAuthForConfig(
                    availableRefs, getGitRepoConfig(), "RepoUrl",
                    "Please enter your {CredentialType} authentication data in order to clone the GIT Reposiory!"
                ))
        elif actionId == "bundleSync":
            cwd = None
            try:
                unused_session, cwd = validateSession(request)
            except Exception as e:
                return web.Response(text="Invalid Session: {}".format(e),
                                    status=401)
            res.extend(
                getRequiredAuthForConfig(
                    availableRefs, getTracConfig(cwd=cwd), "TracUrl",
                    "Please enter your {CredentialType} authentication data to sync with Trac!"
                ))
        elif actionId == "gitPullRebase":
            cwd = None
            try:
                unused_session, cwd = validateSession(request)
            except Exception as e:
                return web.Response(text="Invalid Session: {}".format(e),
                                    status=401)
            res.extend(
                getRequiredAuthForConfig(
                    availableRefs, getGitRepoConfig(cwd=cwd), "RepoUrl",
                    "Please enter your {CredentialType} authentication data to pull changes from the Git-Server!"
                ))
        elif actionId == "publishChanges":
            try:
                unused_session, cwd = validateSession(request)
            except Exception as e:
                return web.Response(text="Invalid Session: {}".format(e),
                                    status=401)
            res.extend(
                getRequiredAuthForConfig(
                    availableRefs, getGitRepoConfig(cwd=cwd), "RepoUrl",
                    "Please enter your {CredentialType} authentication data to publish changes to GIT!"
                ))
        return web.json_response(res)
    except Exception as e:
        return web.Response(text="Illegal Arguments Provided: {}".format(e),
                            status=400)
Exemplo n.º 2
0
async def handle_git_pull_rebase(request):
    cwd = None
    try:
        unused_session, cwd = validateSession(request)
    except Exception as e:
        return web.Response(text="Invalid Session: {}".format(e), status=401)

    logger.info("Updating git-repository from the git-server")

    repoUrl, credType, useAuthentication = None, None, None
    try:
        config = getGitRepoConfig(required=True, cwd=cwd)
        repoUrl = config["RepoUrl"]
        credType = config.get("CredentialType", "").upper()
        useAuthentication = len(credType) > 0
    except Exception as e:
        return web.Response(text="Invalid Configuration: {}".format(e),
                            status=500)

    user, password, ssId = "", "", None
    try:
        if useAuthentication:
            (user, password,
             ssId) = common_app_server.get_credentials(request, credType)
    except Exception as e:
        return web.Response(text="Illegal Arguments Provided: {}".format(e),
                            status=400)
    res, auth_ok = await asyncio.wrap_future(
        ppe.submit(git_pull_rebase, repoUrl, useAuthentication, user, password,
                   cwd))
    if not auth_ok:
        common_app_server.invalidate_credentials(ssId)
    return web.json_response(res)
Exemplo n.º 3
0
async def handle_login(request):
    logger.info("Handling 'login'")

    config, repoUrl, branch, credType, useAuthentication = None, None, None, None, None
    try:
        config = getGitRepoConfig(required=True)
        repoUrl = config["RepoUrl"]
        branch = config.get("Branch") or "master"
        credType = config.get("CredentialType", "").upper()
        useAuthentication = len(credType) > 0
    except Exception as e:
        return web.Response(text="Invalid Configuration: {}".format(e),
                            status=500)

    user, password, ssId = "", "", None
    try:
        if useAuthentication:
            (user, password,
             ssId) = common_app_server.get_credentials(request, credType)
    except Exception as e:
        return web.Response(text="Illegal Arguments Provided: {}".format(e),
                            status=400)

    res = []
    session = None
    with common_app_server.logging_redirect_for_webapp() as logs:
        try:
            tmpDir = tempfile.mkdtemp()
            logger.debug("Cloning '{}' to '{}'".format(repoUrl, tmpDir))
            await asyncio.wrap_future(
                ppe.submit(git_clone_repository, repoUrl, branch, tmpDir,
                           useAuthentication, user, password))
            logger.info(
                "Successfully cloned {} to a (temporary) local working directory, branch '{}'."
                .format(repoUrl, branch))
            session = createSession(tmpDir)
            session["RepoUrl"] = repoUrl
            session["Branch"] = branch
        except (Exception, GitCommandError) as e:
            logger.error(str(e))
            common_app_server.invalidate_credentials(ssId)
        res = logs.toBackendLogEntryList()
    response = web.json_response(res)
    emitOrCleanSessionCookie(response, session)
    return response