-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_apiviz.py
115 lines (87 loc) · 3.9 KB
/
run_apiviz.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- encoding: utf-8 -*-
import os
import click
from pprint import pprint, pformat
from dotenv import load_dotenv
from pathlib import Path # python3 only
debug = True
@click.command()
@click.option('--mode', default="default", nargs=1, help="The <mode> you need to run the app : default | testing | preprod | production" )
@click.option('--docker', default="docker_off", nargs=1, help="Are you running the app with <docker> : docker_off | docker_on" )
@click.option('--mongodb', default="local", nargs=1, help="The <mongodb> you need to run the app : local | distant | server" )
@click.option('--auth', default="default", nargs=1, help="The <auth> mode you need to run the app : default | default_docker | server | server_docker | distant_preprod | distant_prod" )
@click.option('--host', default="localhost", nargs=1, help="The <host> name you want the app to run on : <IP_NUMBER> " )
@click.option('--port', default="8100", nargs=1, help="The <port> number you want the app to run on : <PORT_NUMBER>")
@click.option('--https', default="false", nargs=1, help="The <https> mode you want the app to run on : true | false")
def app_runner(mode, docker, mongodb, auth, host, port, https) :
"""
app_runner
"""
print ("= "*50)
print ("= = = RERUN FLASK APP FROM APP RUNNER = = =")
print ("= "*50)
### WARNING : CLIck will treat every input as string as defaults values are string too
print ("\n=== CUSTOM CONFIG FROM CLI ===\n")
print ("=== mode : ", mode)
print ("=== docker : ", docker)
print ("=== mongodb : ", mongodb)
print ("=== host : ", host)
print ("=== port : ", port)
print ("=== auth : ", auth)
print ("=== https : ", https)
### READ ENV VARS DEPENDING ON MODE
try :
env_path_superAdmins = Path('.') / '.env.superadmins'
if env_path_superAdmins.is_file() == False :
raise FileNotFoundError
load_dotenv(env_path_superAdmins, verbose=True)
except :
env_path_superAdmins = Path('.') / 'example.env.superadmins'
load_dotenv(env_path_superAdmins, verbose=True)
if mode in ['default', 'testing']:
env_path_global = Path('.') / 'example.env.global'
if mongodb in ['local'] :
env_path_mongodb = Path('.') / 'example.env.mongodb'
else :
env_path_mongodb = Path('.') / '.env.mongodb'
else :
env_path_global = Path('.') / '.env.global'
env_path_mongodb = Path('.') / '.env.mongodb'
load_dotenv(env_path_global, verbose=True)
load_dotenv(env_path_mongodb, verbose=True)
# if https == "true" :
# http_mode = "https"
# else :
# http_mode = "http"
### apply / overwrites host configuration
if mode != "default" :
print ("=== mode : ", mode)
# os.environ["FLASK_CONFIGURATION"] = str(mode)
os.environ["RUN_MODE"] = str(mode)
# config_name = os.getenv('FLASK_CONFIGURATION', 'default') ### 'default' for local dev
config_name = os.getenv('RUN_MODE', 'default') ### 'default' for local dev
print ("=== config_name : ", config_name)
### OVERRIDE ENV VARS FROM CLI
os.environ["DOMAIN_ROOT"] = host
os.environ["DOMAIN_PORT"] = port
os.environ["DOCKER_MODE"] = docker
os.environ["MONGODB_MODE"] = mongodb
os.environ["AUTH_MODE"] = auth
# os.environ["SERVER_NAME"] = host + ":" + port
# os.environ["DOMAIN_NAME"] = http_mode + "://" + host + ":" + port
### create app by importing app.__init__
from backend import app
print ("= = = APP.CONFIG / to understand WTF is goin on ..." )
pprint({ k:v for k,v in app.config.items() } )
### simple flask runner
print ("= = = STARTING app.run = = =")
app.run( debug=debug, host=host, port=int(port), threaded=True )
if __name__ == '__main__':
"""
runner for the CIS front Flask app
- gets most of its variables at start from environment variables
-
in command line just type :
"python run_apiviz.py" + CLI args (optional)
"""
app_runner()