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)
async def handle_update_bundles(request):
    cwd = None
    try:
        unused_session, cwd = validateSession(request)
    except Exception as e:
        return web.Response(text="Invalid Session: {}".format(e), status=401)

    config = getTracConfig(cwd=cwd)
    tracUrl = config.get("TracUrl")
    credType = config.get("CredentialType", "").upper()
    parentTicketsField = config.get('UseParentTicketsFromInfoField')
    useAuthentication = len(credType) > 0
    user, password, ssId = "", "", None
    try:
        if useAuthentication:
            (user, password,
             ssId) = common_app_server.get_credentials(request, credType)
    except Exception as e:
        '''Credentials are not mandatory for update_bundles - so just pass'''

    logger.info("Handling 'Update Bundles'")
    res, auth_ok = await asyncio.wrap_future(
        ppe.submit(update_bundles, useAuthentication, user, password, tracUrl,
                   parentTicketsField, cwd))
    if not auth_ok:
        common_app_server.invalidate_credentials(ssId)
    logger.debug("Handling 'Update Bundles' finished")
    return web.json_response(res)
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