-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·76 lines (57 loc) · 2.17 KB
/
main.py
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
import logging
import os
from flask import Flask, Blueprint, request, send_from_directory
from modules.kubeseal import Kubeseal
from modules.ui import UI
from modules.api import API
class application:
def __init__ (self):
# Set envs
self.DEBUG = os.getenv('DEBUG', 'False').lower() in ('true', '1', 't')
KUBECONF_DIR = os.getenv('KUBECONF_DIR')
DEFAULT_SCOPE = os.getenv('DEFAULT_SCOPE')
SCOPE_TOOLTIP = os.getenv('SCOPE_TOOLTIP', None)
BASE_PATH = os.getenv('BASE_PATH', "")
# Set logging
logLevel = logging.INFO if not self.DEBUG else logging.DEBUG
logging.basicConfig(level=logLevel, format='[%(levelname)s] %(name)s:%(module)s %(asctime)s -- %(message)s')
self.logger = logging.getLogger(__name__)
# Initialize kubeseal object
self.ks = Kubeseal(config_dir=KUBECONF_DIR)
# Create UI and API objects
self.apiObj = API(self.ks)
self.uiObj = UI(
self.ks,
default_scope=DEFAULT_SCOPE,
scope_tooltip=SCOPE_TOOLTIP
)
# Setup Flask
self.app = Flask(__name__)
self.api = Blueprint("api", __name__, url_prefix=BASE_PATH+"/api")
self.ui = Blueprint("ui", __name__, url_prefix=BASE_PATH)
# Define static documents route
@self.ui.route("/static/<path:path>")
def staticFiles(path):
return send_from_directory('static', path)
# Define UI Routes
@self.ui.route("/")
def uiIndex():
return self.uiObj.index()
# Define API routes
@self.api.route("/seal/raw", methods=['POST'])
def apiSealRaw():
return self.apiObj.sealRaw(request)
@self.api.route("/seal/file", methods=['POST'])
def apiSealFile():
return self.apiObj.sealFile(request)
# Register Flask Blueprints
self.app.register_blueprint(self.api)
self.app.register_blueprint(self.ui)
# Run Flask
def run(self):
self.app.run(debug=self.DEBUG, host="0.0.0.0")
# Setup for Gunicorn
app = application().app
# Run using development server
if __name__ == "__main__":
application().run()