Exemplo n.º 1
0
def set_alias_app(id):
    # retrieves the application from the provided identifier
    # and then retrieves its (main) domain value
    app = util.get_app(id)
    host = app.get("domain", None)

    # retrieves the alias sent by the post value
    # adds it as an alias in the app
    alias = quorum.get_field("alias", None)
    app["domains"].append(alias)

    # runs the validation process on new app created
    # structures (should meet the requirements)
    errors, app_v = quorum.validate(util.validate_app, object = app)
    if errors:
        return flask.render_template(
            "app/edit.html.tpl",
            link = "new_app",
            app = app_v,
            errors = errors
        )

    # saves the app back in the database to reflect
    # the changes that were made
    db = quorum.get_mongo_db()
    db.apps.save(app)

    # retrieves the current storage infra-structure
    # and sets the alias in it
    storage = quorum.get_redis()
    storage.set("alias:%s" % alias, host)

    return flask.redirect(
        flask.url_for("edit_app", id = id)
    )
Exemplo n.º 2
0
def new_app():
    return flask.render_template(
        "app/new.html.tpl",
        link = "new_app",
        app = {},
        errors = {}
    )
Exemplo n.º 3
0
def set_description_app(id):
    # retrieves the app from the provided identifier
    # value (this map will be updated)
    app = util.get_app(id)

    # retrieves the description value from the
    # request to be used to set the new description
    # in the app structure
    name = quorum.get_field("description")
    app["description"] = name

    # runs the validation process on new app created
    # structures (should meet the requirements)
    errors, app_v = quorum.validate(util.validate_app, object = app)
    if errors:
        return flask.render_template(
            "app/edit.html.tpl",
            link = "new_app",
            app = app_v,
            errors = errors
        )

    # saves the app back in the database to reflect
    # the changes that were made
    db = quorum.get_mongo_db()
    db.apps.save(app)

    return flask.redirect(
        flask.url_for("edit_app", id = id)
    )
Exemplo n.º 4
0
def set_env_app(id):
    # retrieves the app from the provided identifier
    # value (this map will be updated)
    app = util.get_app(id)

    # retrieves the key and value values from the
    # request to be used to set the new environment
    # variable for the app
    key = quorum.get_field("key")
    value = quorum.get_field("value")
    app["env"][key] = value

    # runs the validation process on new app created
    # structures (should meet the requirements)
    errors, app_v = quorum.validate(util.validate_app, object = app)
    if errors:
        return flask.render_template(
            "app/edit.html.tpl",
            link = "new_app",
            app = app_v,
            errors = errors
        )

    # saves the app back in the database to reflect
    # the changes that were made
    db = quorum.get_mongo_db()
    db.apps.save(app)

    return flask.redirect(
        flask.url_for("edit_app", id = id)
    )
Exemplo n.º 5
0
def help_app(id):
    app = util.get_app(id)
    return flask.render_template(
        "app/help.html.tpl",
        link = "apps",
        sub_link = "help",
        app = app
    )
Exemplo n.º 6
0
def show_app(id):
    app = util.get_app(id)
    return flask.render_template(
        "app/show.html.tpl",
        link = "apps",
        sub_link = "info",
        app = app
    )
Exemplo n.º 7
0
def list_app():
    apps = util.get_apps()

    return flask.render_template(
        "app/list.html.tpl",
        link = "apps",
        apps = apps
    )
Exemplo n.º 8
0
def delete_app_c(id):
    app = util.get_app(id)
    return flask.render_template(
        "app/delete.html.tpl",
        link = "apps",
        sub_link = "delete",
        app = app,
        errors = {}
    )
Exemplo n.º 9
0
def edit_app(id):
    app = util.get_app(id)
    return flask.render_template(
        "app/edit.html.tpl",
        link = "apps",
        sub_link = "edit",
        app = app,
        errors = {}
    )
Exemplo n.º 10
0
def about():
    return flask.render_template(
        "about.html.tpl",
        link = "about"
    )
Exemplo n.º 11
0
def index():
    return flask.render_template(
        "index.html.tpl",
        link = "home"
    )
Exemplo n.º 12
0
def create_app():
    # runs the validation process on the various arguments
    # provided to the app
    errors, app = quorum.validate(util.validate_app_new)
    if errors:
        return flask.render_template(
            "app/new.html.tpl",
            link = "new_app",
            app = app,
            errors = errors
        )

    # retrieves the name and the description attributes of
    # the app to be used in the creation
    name = quorum.get_field("name", None)
    description = quorum.get_field("description", None)

    # retrieves the current configuration structure to be able
    # to retrieve a series of configuration attributes
    config = util.get_config()
    hostname = config.get("hostname", "repo.tiberium")
    domain_suffix = config.get("domain_suffix", "tibapp")
    user = config.get("user", "git")
    group = config.get("group", "git")

    # retrieves the directory used to store the repository
    # for the various applications
    repos_folder = util.get_repos_folder()

    # creates the map containing the complete description of the
    # app from the provided parameters and configuration
    app = dict(
        id = name,
        name = name,
        description = description,
        domain = "%s.%s" % (name, domain_suffix),
        schema = "http",
        git = "git@%s:%s.git" % (hostname, name),
        env = {},
        domains = []
    )

    # retrieves the database and then saves the app in the
    # correct collection
    db = quorum.get_mongo_db()
    db.apps.save(app)

    # retrieves the (complete) repository path for the current app
    # and creates the repository in it (uses tiberium)
    repo_path = os.path.join(repos_folder, "%s.git" % name)
    tiberium.create_repo(repo_path)

    # retrieves the "proper" path to the hooks in the application
    # to copy and change their permissions
    hooks_path = os.path.join(repo_path, ".git", "hooks")

    # lists the names of the various hook files and then copies
    # each of them to the hooks folder of the application
    names = os.listdir(util.HOOKS_FOLDER)
    for _name in names:
        file_path = os.path.join(util.HOOKS_FOLDER, _name)
        target_path = os.path.join(hooks_path, _name)
        shutil.copy(file_path, target_path)
        os.chmod(target_path, 0x1ed)

    # changes the owner and group of the repository path (all the
    # applications require the same user)
    util.chown_r(repo_path, user, group)

    return flask.redirect(
        flask.url_for("show_app", id = name)
    )