Beispiel #1
0
def api_state_namespaces():
    """
    Define a route.

    This is a main routing method
    """
    #
    # Basic authentication module requirement
    # If the auth module is installed and the user is not authenticated, so go to login
    #
    session = {}
    if hasattr(app, 'auth'):
        try:
            session = get_session_data(
                transaction=transaction,
                session_id=request.cookies.get('session_id'))
        except Exception as e:
            print(e)
            return redirect(url_for('auth_blueprint.login'))
    else:
        session['kubeconfig'] = None
    # not current_user.is_authenticated:
    if hasattr(app, 'auth') and session['email'] is None:
        return redirect(url_for('auth_blueprint.login'))
    #
    # End basic authentication requirement
    #

    return jsonify(state_namespaces())
Beispiel #2
0
def route_template(template):
    #if not current_user.is_authenticated:
    #    return redirect(url_for('base_blueprint.login'))
    try:
        return render_template(template + '.html',
                               list_actions = list_actions(),
                               show_actions = show_actions(),
                               state_namespaces = state_namespaces(),
                               state_nodes = state_nodes(),
                               state_pods = state_pods(),
                               compute_allocated_resources = compute_allocated_resources(),
                               )
    except TemplateNotFound:
        return render_template('page-404.html'), 404
    except:
        return render_template('page-500.html'), 500
Beispiel #3
0
def api_state_namespaces():
    return jsonify(state_namespaces())
Beispiel #4
0
def namespaces():
    """
    Render all the templates not from base.

    This is a main method
    """
    #
    # Basic authentication module requirement
    # If the auth module is installed and the user is not authenticated, so go to login
    #
    session = {}
    if hasattr(app, 'auth'):
        try:
            session = get_session_data(
                transaction=transaction,
                session_id=request.cookies.get('session_id'))
        except Exception as e:
            return redirect(url_for('auth_blueprint.login'))
    else:
        session['kubeconfig'] = None
    # not current_user.is_authenticated:
    if hasattr(app, 'auth') and session['email'] == None:
        return redirect(url_for('auth_blueprint.login'))
    #
    # End basic authentication requirement
    #

    if not 'kubeconfig' in session or session['kubeconfig'] == None or session[
            'kubeconfig'] == '':
        kubeconfig = None
        api_client = None
    else:
        kubeconfig = session['kubeconfig']
        api_client = remote_cluster(kubeconfig=kubeconfig)

    if (not 'username' in session or session['username'] == None
            or session['username'] == '' or not 'email' in session
            or session['email'] == None or session['email'] == ''):

        username = None
        email = None
    else:
        username = session['username']
        email = session['email']

    try:
        return render_template(
            'namespaces.html',
            username=username,
            email=email,
            state_namespaces=state_namespaces(api_client=api_client),
            compute_allocated_resources=compute_allocated_resources(
                api_client=api_client),
            cluster_name_configured=cluster_name_configured(
                api_client=api_client),
            pystol_version=PYSTOL_VERSION,
        )

    except TemplateNotFound:
        return render_template('page-404.html'), 404
    except Exception as e:
        print("Exception found in %s: %s" % (blueprint.name, e))
        if current_app.config['DEBUG']:
            raise e
        return render_template('page-500.html'), 500