forked from carrier-io/theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.py
More file actions
98 lines (86 loc) · 3.82 KB
/
module.py
File metadata and controls
98 lines (86 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
# coding=utf-8
# Copyright 2021 getcarrier.io
#
# Licensed 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.
""" Module """
import logging
from queue import Empty
import flask # pylint: disable=E0401
import jinja2 # pylint: disable=E0401
from flask import request, render_template, redirect, url_for
from pylon.core.tools import log # pylint: disable=E0611,E0401
from pylon.core.tools import module # pylint: disable=E0611,E0401
from .components.commons.navbar import render_navbar
from .components.commons.page import (
render_page,
render_test,
reporting_config,
render_run_test
)
from .components.security.application import applications_scanners_config
from .components.security.common import findings_processing
from ..shared.connectors.auth import SessionProject
class Module(module.ModuleModel):
""" Galloper module """
def __init__(self, settings, root_path, context):
self.settings = settings
self.root_path = root_path
self.context = context
def init(self):
""" Init module """
log.info("Initializing module Theme")
bp = flask.Blueprint( # pylint: disable=C0103
"theme", "plugins.theme.plugin",
root_path=self.root_path,
url_prefix=f"{self.context.url_prefix}/"
)
bp.jinja_loader = jinja2.ChoiceLoader([
jinja2.loaders.PackageLoader("plugins.theme", "templates"),
])
bp.add_url_rule("/", "index", self.index)
bp.add_url_rule("/new", "create_project", self.project_wizard)
# Register in app
self.context.app.register_blueprint(bp)
# Register template slot callback
self.context.slot_manager.register_callback("navbar", render_navbar)
self.context.slot_manager.register_callback("page_content", render_page)
self.context.slot_manager.register_callback("create_test", render_test)
self.context.slot_manager.register_callback("edit_test", render_test)
self.context.slot_manager.register_callback("run_test", render_run_test)
self.context.slot_manager.register_callback("reporting_config", reporting_config)
self.context.slot_manager.register_callback("application_scanners_config", applications_scanners_config)
self.context.slot_manager.register_callback("findings_processing", findings_processing)
# Register event listener
# self.context.event_manager.register_listener("base.index", self.base_event)
def deinit(self): # pylint: disable=R0201
""" De-init module """
log.info("De-initializing module Theme")
def index(self):
chapter = request.args.get('chapter', '')
session_project = SessionProject.get()
logging.info(session_project)
if not session_project:
return redirect(url_for('theme.create_project'))
project_config = self.context.rpc_manager.call.project_get_or_404(project_id=session_project).to_json()
return render_template("base.html", active_chapter=chapter, config=project_config)
def project_wizard(self):
try:
groups = self.context.rpc_manager.timeout(5).project_keycloak_group_list()
except Empty:
groups = []
return render_template(
"project_wizard.html",
group_options=groups,
cache_prevent=None
)