#       Licensed to the Apache Software Foundation (ASF) under one
#       or more contributor license agreements.  See the NOTICE file
#       distributed with this work for additional information
#       regarding copyright ownership.  The ASF licenses this file
#       to you under the Apache License, Version 2.0 (the
#       "License"); you may not use this file except in compliance
#       with the License.  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#       Unless required by applicable law or agreed to in writing,
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

ErrorLog /dev/stderr

# see also Allura/docs/getting_started/scm_host.rst

<VirtualHost *:80>

    # /git/ requests go to the git backend binary
    SetEnv GIT_PROJECT_ROOT /allura-data/scm/git
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git/ /usr/lib/git-core/git-http-backend-wrapper.sh/

    # disable access to default web content
    <Directory /var/www>
        Require all denied
        Options None
        AllowOverride None
    </Directory>

    # any Alias here must be excluded from ProxyPass (at bottom of file)
    Alias /robots.txt /allura-data/www-misc/robots.txt
    Alias /favicon.ico /allura-data/www-misc/favicon.ico
    <Directory /allura-data/www-misc/>
        Require all granted
    </Directory>

    # apply security checks to all /git/ requests
    <Location "/git/">
        Require all granted

        AddHandler mod_python .py
        PythonAccessHandler /allura/scripts/ApacheAccessHandler.py
        PythonDebug On

        AuthType Basic
        AuthName "Git Access"
        AuthBasicAuthoritative off
        PythonOption ALLURA_PERM_URL http://web:8088/auth/repo_permissions
        PythonOption ALLURA_AUTH_URL http://web:8088/auth/do_login
        # need python 'requests' lib only, doesn't have to be full allura venv
        # PythonOption ALLURA_VIRTUALENV /some/venv/if/needed
    </Location>

    # declare what is being handled here
    ProxyPass "/robots.txt" !
    ProxyPass "/favicon.ico" !
    ProxyPass "/git/" !
    # everything else gets proxied through to the Allura webapp
    ProxyPass "/" "http://web:8088/"
    ProxyPassReverse "/" "http://web:8088/"

</VirtualHost>