Exemple #1
0
def test_unauthenticated_push_and_require_browser_auth():
    with pytest.raises(ValueError):
        klaus.make_app([],
                       None,
                       use_smarthttp=True,
                       unauthenticated_push=True,
                       require_browser_auth=True)
 def app(environ, start_response):
     if S.should_reload:
         # Refresh inner application with new repo list
         print("Reloading repository list...")
         S.inner_app = make_app(glob.glob(repos_root + "/*"), *args,
                                **kwargs)
         S.should_reload = False
     return S.inner_app(environ, start_response)
def application(environ, start_response):
    global inner_app
    global reload
    if reload:
        inner_app = make_app(
            [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
            "unrelenting.technology/git", "1", None)
        reload = False
    return inner_app(environ, start_response)
Exemple #4
0
 def app(environ, start_response):
     if _.should_reload:
         # Refresh inner application with new repo list
         print "Reloading repository list..."
         _.inner_app = make_app(
             [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
             *args, **kwargs)
         _.should_reload = False
     return _.inner_app(environ, start_response)
Exemple #5
0
 def app(environ, start_response):
     if _.should_reload:
         # Refresh inner application with new repo list
         print "Reloading repository list..."
         _.inner_app = make_app(
             [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
             *args, **kwargs
         )
         _.should_reload = False
     return _.inner_app(environ, start_response)
Exemple #6
0
def serve(*args, **kwargs):
    app = klaus.make_app(ALL_TEST_REPOS, TEST_SITE_NAME, *args, **kwargs)
    server = werkzeug.serving.make_server("localhost", 9876, app)
    thread = threading.Thread(target=server.serve_forever)
    thread.start()
    try:
        yield
    finally:
        server.server_close()
        if 'TRAVIS' in os.environ:
            # This fixes some "Address already in use" cases on Travis.
            time.sleep(1)
Exemple #7
0
def serve(*args, **kwargs):
    app = klaus.make_app(ALL_TEST_REPOS, TEST_SITE_NAME, *args, **kwargs)
    server = werkzeug.serving.make_server("localhost", 9876, app)
    thread = threading.Thread(target=server.serve_forever)
    thread.start()
    try:
        yield
    finally:
        server.server_close()
        if 'TRAVIS' in os.environ:
            # This fixes some "Address already in use" cases on Travis.
            time.sleep(1)
Exemple #8
0
def application(environ, start_response):
    global inner_app
    global reload
    if reload:
        inner_app = make_app(
            [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
            "unrelenting.technology/git",
            "1",
            None
        )
        reload = False
    return inner_app(environ, start_response)
Exemple #9
0
def make_autodetecting_app(
    repos_root,
    *args,
    detect_removals=None,
    export_ok_path=None,
    **kwargs,
):
    return klaus.make_app(
        repos_root,
        *args,
        repo_container_factory=functools.partial(
            AutodetectingRepoContainer,
            detect_removals=detect_removals,
            export_ok_path=export_ok_path,
        ),
        **kwargs,
    )
Exemple #10
0
    def app(environ, start_response):
        if _.should_reload:
            # Refresh inner application with new repo list
            print("Reloading repository list...")
            inner_app = make_app(
                [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
                *args, **kwargs)

            @inner_app.errorhandler(404)
            def not_found(e):
                # defining function
                return render_template("404.html")

            _.inner_app = inner_app
            _.should_reload = False

        return _.inner_app(environ, start_response)
Exemple #11
0
def test_make_app_using_list():
    app = klaus.make_app(REPOS, TEST_SITE_NAME)
    with serve_app(app):
        response = requests.get(UNAUTH_TEST_SERVER).text
        assert TEST_REPO_NO_NEWLINE_BASE_URL in response
Exemple #12
0
def test_unauthenticated_push_with_disable_push():
    with pytest.raises(ValueError):
        klaus.make_app([], None, unauthenticated_push=True, disable_push=True)
Exemple #13
0
def test_unauthenticated_push_without_use_smarthttp():
    with pytest.raises(ValueError):
        klaus.make_app([], None, unauthenticated_push=True)
Exemple #14
0
from klaus import make_app
from .app_args import get_args_from_env

args, kwargs = get_args_from_env()

if kwargs['htdigest_file']:
    with open(kwargs['htdigest_file']) as file:
        kwargs['htdigest_file'] = file
        application = make_app(*args, **kwargs)
else:
    application = make_app(*args, **kwargs)
Exemple #15
0
def test_htdigest_file_without_smarthttp_or_require_browser_auth():
    with pytest.raises(ValueError):
        klaus.make_app([], None, htdigest_file=object())
Exemple #16
0
# make sure to end with "/"
PATH_TO_REPOS = u"/home/git/" 

# search for git repos in path_to_repos
def isGit(path):
	ends_with_git = len(path) > 4 and path[-4:] == '.git'
	blacklisted = False
	return ends_with_git and not blacklisted

from os import listdir
REPOSITORIES = [PATH_TO_REPOS+repo for repo in filter(isGit, listdir(PATH_TO_REPOS))]

# don't include private repos
from private import PRIVATE_REPOS
for repo in PRIVATE_REPOS:
	R = PATH_TO_REPOS+repo
	if R in REPOSITORIES:
		REPOSITORIES.remove(R)

# klaus provides a make_app function that creates a WSGI application
# Don't forget to add the path to klaus to WSGIPythonPath in your Apache config
import sys
sys.path.append('/usr/local/lib/python2.6/dist-packages')
sys.path.append('/usr/local/lib/python2.6/dist-packages/klaus')
sys.path.append('/usr/local/lib/python2.6/dist-packages/klaus/klaus')

# Export WSGI application
from klaus import make_app
application = make_app(REPOSITORIES, TITLE)
Exemple #17
0
import os
from klaus import make_app

if 'KLAUS_HTDIGEST_FILE' in os.environ:
    with open(os.environ['KLAUS_HTDIGEST_FILE']) as file:
        application = make_app(
            os.environ['KLAUS_REPOS'].split(),
            os.environ['KLAUS_SITE_NAME'],
            os.environ.get('KLAUS_USE_SMARTHTTP'),
            file,
        )
else:
    application = make_app(
        os.environ['KLAUS_REPOS'].split(),
        os.environ['KLAUS_SITE_NAME'],
        os.environ.get('KLAUS_USE_SMARTHTTP'),
        None,
    )
Exemple #18
0
    ends_with_git = len(path) > 4 and path[-4:] == '.git'
    blacklisted = False
    return ends_with_git and not blacklisted


from os import listdir

REPOSITORIES = [
    PATH_TO_REPOS + repo for repo in filter(isGit, listdir(PATH_TO_REPOS))
]

# don't include private repos
from private import PRIVATE_REPOS
for repo in PRIVATE_REPOS:
    R = PATH_TO_REPOS + repo
    if R in REPOSITORIES:
        REPOSITORIES.remove(R)

# klaus provides a make_app function that creates a WSGI application
# Don't forget to add the path to klaus to WSGIPythonPath in your Apache config
import sys

sys.path.append('/usr/local/lib/python2.6/dist-packages')
sys.path.append('/usr/local/lib/python2.6/dist-packages/klaus')
sys.path.append('/usr/local/lib/python2.6/dist-packages/klaus/klaus')

# Export WSGI application
from klaus import make_app

application = make_app(REPOSITORIES, TITLE)
Exemple #19
0
import os
from klaus import make_app

application = make_app(
    os.environ['KLAUS_REPOS'].split(),
    os.environ['KLAUS_SITE_TITLE'],
    os.environ.get('KLAUS_USE_SMARTHTTP'),
    os.environ.get('KLAUS_HTDIGEST_FILE'),
)
Exemple #20
0
def test_unauthenticated_push_without_use_smarthttp():
    with pytest.raises(ValueError):
        klaus.make_app([], None, unauthenticated_push=True)
Exemple #21
0
from klaus import make_app
from .app_args import get_args_from_env
from flask import render_template

args, kwargs = get_args_from_env()

if kwargs['htdigest_file']:
    with open(kwargs['htdigest_file']) as file:
        kwargs['htdigest_file'] = file
        application = make_app(*args, **kwargs)
else:
    application = make_app(*args, **kwargs)


@application.errorhandler(404)
def not_found(e):
    # defining function
    return render_template("404.html")
Exemple #22
0
import os
from klaus import make_app

if 'KLAUS_HTDIGEST_FILE' in os.environ:
    with open(os.environ['KLAUS_HTDIGEST_FILE']) as file:
        application = make_app(
            os.environ['KLAUS_REPOS'].split(),
            os.environ['KLAUS_SITE_NAME'],
            os.environ['KLAUS_GIT_BIN'],
            os.environ['KLAUS_CLONE_URLS'].split(),
            os.environ.get('KLAUS_USE_SMARTHTTP'),
            file,
        )
else:
    application = make_app(
        os.environ['KLAUS_REPOS'].split(),
        os.environ['KLAUS_SITE_NAME'],
        os.environ['KLAUS_GIT_BIN'],
        os.environ['KLAUS_CLONE_URLS'].split(),
        os.environ.get('KLAUS_USE_SMARTHTTP'),
        None,
    )
Exemple #23
0
def test_htdigest_file_without_smarthttp_or_require_browser_auth():
    with pytest.raises(ValueError):
        klaus.make_app([], None, htdigest_file=object())
Exemple #24
0
            _.inner_app = make_app(
                [os.path.join(repos_root, x) for x in os.listdir(repos_root)],
                *args, **kwargs
            )
            _.should_reload = False
        return _.inner_app(environ, start_response)

    # Background thread that polls the directory for changes
    poller_thread = threading.Thread(target=(lambda: poll_for_changes(10, repos_root)))
    poller_thread.daemon = True
    poller_thread.start()

    return app


if 'KLAUS_HTDIGEST_FILE' in os.environ:
    with open(os.environ['KLAUS_HTDIGEST_FILE']) as file:
        application = make_app(
            os.environ['KLAUS_REPOS'],
            os.environ['KLAUS_SITE_NAME'],
            os.environ.get('KLAUS_USE_SMARTHTTP'),
            file,
        )
else:
    application = make_autoreloading_app(
        os.environ['KLAUS_REPOS'],
        os.environ['KLAUS_SITE_NAME'],
        os.environ.get('KLAUS_USE_SMARTHTTP'),
        None,
    )
Exemple #25
0
def test_unauthenticated_push_and_require_browser_auth():
    with pytest.raises(ValueError):
        klaus.make_app([], None, use_smarthttp=True, unauthenticated_push=True, require_browser_auth=True)
Exemple #26
0
def serve(*args, **kwargs):
    app = klaus.make_app(ALL_TEST_REPOS, TEST_SITE_NAME, *args, **kwargs)
    with serve_app(app):
        yield
Exemple #27
0
def test_unauthenticated_push_with_disable_push():
    with pytest.raises(ValueError):
        klaus.make_app([], None, unauthenticated_push=True, disable_push=True)
Exemple #28
0
def serve(*args, **kwargs):
    app = klaus.make_app(ALL_TEST_REPOS, TEST_SITE_NAME, *args, **kwargs)
    with serve_app(app):
        yield