コード例 #1
0
ファイル: run.py プロジェクト: bourneye/cesi
def configure(config_file_path):
    cesi = Cesi(config_file_path=config_file_path)
    _ = ActivityLog(log_path=cesi.activity_log)

    app = create_app(cesi)

    signal.signal(signal.SIGHUP, lambda signum, frame: cesi.reload())

    return app, cesi
コード例 #2
0
        def wrap(*args, **kwargs):
            activity = ActivityLog.getInstance()
            if session.get("logged_in"):
                return f(*args, **kwargs)

            if not log_message == "":
                message = log_message.format(**kwargs)
                activity.logger.error(message)

            return jsonify(status="error", message="Session expired"), 401
コード例 #3
0
def configure(config_file_path):
    cesi = Cesi(config_file_path=config_file_path)
    activity = ActivityLog(log_path=cesi.activity_log)

    app = Flask(
        __name__,
        static_folder="ui/build",
        static_url_path="",
        template_folder="ui/build",
    )
    app.config.from_object(__name__)
    app.secret_key = os.urandom(24)

    app.add_url_rule("/", "index", lambda: render_template("index.html"))

    @app.before_request
    def _():
        # Open db connection
        g.db_conn = cesi.get_db_connection()

    app.teardown_appcontext(lambda _: g.db_conn.close())

    @app.errorhandler(404)
    def _(error):
        return jsonify(status="error", message=error.name), 404

    @app.errorhandler(400)
    def _(error):
        return jsonify(status="error", message=error.description), 400

    # Import and register blueprint modules dynamically
    #   from blueprints.nodes.routes import nodes
    #   app.register_blueprint(nodes, url_prefix="/{}/nodes".format(API_VERSION))
    blueprint_names = [
        "nodes",
        "activitylogs",
        "environments",
        "groups",
        "users",
        "auth",
        "profile",
    ]
    for blueprint_name in blueprint_names:
        module = importlib.import_module(
            "blueprints.{}.routes".format(blueprint_name))
        blueprint = getattr(module, blueprint_name)
        app.register_blueprint(blueprint,
                               url_prefix="/{}/{}".format(
                                   API_VERSION, blueprint_name))

    signal.signal(signal.SIGHUP, lambda signum, frame: cesi.reload())

    return app, cesi
コード例 #4
0
def configure(config_file_path):
    from core import Cesi
    from loggers import ActivityLog

    cesi = Cesi(config_file_path=config_file_path)
    _ = ActivityLog(log_path=cesi.activity_log)

    app = create_app(cesi)

    # Check database
    with app.app_context():
        cesi.check_database()

    signal.signal(signal.SIGHUP, lambda signum, frame: cesi.reload())

    return app, cesi
コード例 #5
0
        def wrap(*args, **kwargs):
            activity = ActivityLog.getInstance()
            username = session["username"]
            usertypecode = session["usertypecode"]
            if usertypecode == 0:
                return f(*args, **kwargs)

            if not log_message == "":
                message = log_message.format(**kwargs)
                activity.logger.error("{0}: {1}".format(username, message))

            return (
                jsonify(status="error",
                        message="You are not authorized this action"),
                403,
            )
コード例 #6
0
ファイル: run.py プロジェクト: GraySilver/utopia
def configure(config_file_path):
    from core import Utopia
    from loggers import ActivityLog
    from controllers import check_database

    utopia = Utopia(config_file_path=config_file_path)
    _ = ActivityLog(log_path=utopia.activity_log)

    app = create_app(utopia)

    # Check database
    with app.app_context():
        check_database()

    signal.signal(signal.SIGHUP, lambda signum, frame: utopia.reload())

    return app, utopia
コード例 #7
0
ファイル: routes.py プロジェクト: wpp666/cesi
from flask import Blueprint, jsonify, session, request

from decorators import is_user_logged_in
from loggers import ActivityLog
import controllers

profile = Blueprint("profile", __name__)
activity = ActivityLog.getInstance()


@profile.route("/", methods=["GET"])
@is_user_logged_in("Illegal request to get your own information")
def get_own_info():
    user = controllers.get_user(session["username"])
    print(user)
    return jsonify(status="success", user=user)


@profile.route("/password/", methods=["PUT"])
@is_user_logged_in("Illegal request to change your own password.")
def change_own_password():
    username = session["username"]
    data = request.get_json()
    old_password = data.get("oldPassword")
    new_password = data.get("newPassword")
    if old_password == "" or new_password == "":
        return (
            jsonify(
                status="error",
                message="Please enter valid value old password or new_password",
            ),
コード例 #8
0
ファイル: profile.py プロジェクト: gamegos/cesi
from flask import Blueprint, jsonify, request, g

from decorators import is_user_logged_in
from loggers import ActivityLog
import controllers
from models import User

profile = Blueprint("profile", __name__)
activity = ActivityLog.getInstance()


@profile.route("/", methods=["GET"])
@is_user_logged_in("Illegal request to get your own information")
def get_own_info():
    user = controllers.get_user(g.user.username)
    print(user)
    return jsonify(status="success", user=user)


@profile.route("/password/", methods=["PUT"])
@is_user_logged_in("Illegal request to change your own password.")
def change_own_password():
    username = g.user.username
    data = request.get_json()
    old_password = data.get("oldPassword")
    new_password = data.get("newPassword")
    if old_password == "" or new_password == "":
        return (
            jsonify(
                status="error",
                message="Please enter valid value old password or new_password",
コード例 #9
0
ファイル: run.py プロジェクト: Arlandrian/cesi
            template_folder="ui/build")
app.config.from_object(__name__)
app.secret_key = os.urandom(24)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Cesi web server")

    parser.add_argument("-c",
                        "--config",
                        type=str,
                        help="config file",
                        required=True)

    args = parser.parse_args()
    cesi = Cesi(config_file_path=args.config)
    activity = ActivityLog(log_path=cesi.activity_log)

    from routes import *

    # or dynamic import
    from blueprints.nodes.routes import nodes
    from blueprints.activitylogs.routes import activitylogs
    from blueprints.environments.routes import environments
    from blueprints.groups.routes import groups
    from blueprints.users.routes import users
    from blueprints.auth.routes import auth
    from blueprints.profile.routes import profile

    app.register_blueprint(nodes, url_prefix="/{}/nodes".format(VERSION))
    app.register_blueprint(activitylogs,
                           url_prefix="/{}/activitylogs".format(VERSION))