cornflow 1.2.1__py3-none-any.whl → 1.2.3a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cornflow/app.py +3 -1
- cornflow/cli/__init__.py +4 -0
- cornflow/cli/actions.py +4 -0
- cornflow/cli/config.py +4 -0
- cornflow/cli/migrations.py +13 -8
- cornflow/cli/permissions.py +4 -0
- cornflow/cli/roles.py +4 -0
- cornflow/cli/schemas.py +5 -0
- cornflow/cli/service.py +235 -131
- cornflow/cli/tools/api_generator.py +13 -10
- cornflow/cli/tools/endpoint_tools.py +191 -196
- cornflow/cli/tools/models_tools.py +87 -60
- cornflow/cli/tools/schema_generator.py +161 -67
- cornflow/cli/tools/schemas_tools.py +4 -5
- cornflow/cli/users.py +8 -0
- cornflow/cli/views.py +4 -0
- cornflow/commands/dag.py +3 -2
- cornflow/commands/permissions.py +3 -3
- cornflow/commands/schemas.py +6 -4
- cornflow/commands/users.py +12 -17
- cornflow/endpoints/dag.py +27 -25
- cornflow/endpoints/data_check.py +128 -165
- cornflow/endpoints/example_data.py +9 -3
- cornflow/endpoints/execution.py +40 -34
- cornflow/endpoints/health.py +7 -7
- cornflow/endpoints/instance.py +39 -12
- cornflow/endpoints/meta_resource.py +4 -5
- cornflow/schemas/execution.py +9 -1
- cornflow/schemas/health.py +1 -0
- cornflow/shared/authentication/auth.py +73 -42
- cornflow/shared/const.py +10 -1
- cornflow/shared/exceptions.py +3 -1
- cornflow/shared/utils_tables.py +36 -8
- cornflow/shared/validators.py +1 -1
- cornflow/tests/const.py +1 -0
- cornflow/tests/custom_test_case.py +4 -4
- cornflow/tests/unit/test_alarms.py +1 -2
- cornflow/tests/unit/test_cases.py +4 -7
- cornflow/tests/unit/test_commands.py +90 -0
- cornflow/tests/unit/test_executions.py +22 -1
- cornflow/tests/unit/test_health.py +4 -1
- cornflow/tests/unit/test_log_in.py +46 -9
- cornflow/tests/unit/test_tables.py +3 -3
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/METADATA +1 -1
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/RECORD +48 -48
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/WHEEL +1 -1
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/entry_points.txt +0 -0
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/top_level.txt +0 -0
cornflow/app.py
CHANGED
@@ -51,6 +51,8 @@ def create_app(env_name="development", dataconn=None):
|
|
51
51
|
"""
|
52
52
|
dictConfig(log_config(app_config[env_name].LOG_LEVEL))
|
53
53
|
|
54
|
+
# Note: Explicit CSRF protection is not configured as the application uses
|
55
|
+
# JWT for authentication via headers, mitigating standard CSRF vulnerabilities.
|
54
56
|
app = Flask(__name__)
|
55
57
|
app.json.sort_keys = False
|
56
58
|
app.logger.setLevel(app_config[env_name].LOG_LEVEL)
|
@@ -103,7 +105,7 @@ def create_app(env_name="development", dataconn=None):
|
|
103
105
|
else:
|
104
106
|
raise ConfigurationError(
|
105
107
|
error="Invalid authentication type",
|
106
|
-
log_txt="Error while configuring authentication. The authentication type is not valid."
|
108
|
+
log_txt="Error while configuring authentication. The authentication type is not valid.",
|
107
109
|
)
|
108
110
|
|
109
111
|
initialize_errorhandlers(app)
|
cornflow/cli/__init__.py
CHANGED
cornflow/cli/actions.py
CHANGED
cornflow/cli/config.py
CHANGED
cornflow/cli/migrations.py
CHANGED
@@ -3,6 +3,7 @@ import os.path
|
|
3
3
|
|
4
4
|
import click
|
5
5
|
from cornflow.shared import db
|
6
|
+
from cornflow.shared.const import MIGRATIONS_DEFAULT_PATH
|
6
7
|
from flask_migrate import Migrate, migrate, upgrade, downgrade, init
|
7
8
|
|
8
9
|
from .utils import get_app
|
@@ -10,6 +11,10 @@ from .utils import get_app
|
|
10
11
|
|
11
12
|
@click.group(name="migrations", help="Commands to manage the migrations")
|
12
13
|
def migrations():
|
14
|
+
"""
|
15
|
+
This method is empty but it serves as the building block
|
16
|
+
for the rest of the commands
|
17
|
+
"""
|
13
18
|
pass
|
14
19
|
|
15
20
|
|
@@ -18,12 +23,12 @@ def migrate_migrations():
|
|
18
23
|
app = get_app()
|
19
24
|
external = int(os.getenv("EXTERNAL_APP", 0))
|
20
25
|
if external == 0:
|
21
|
-
path =
|
26
|
+
path = MIGRATIONS_DEFAULT_PATH
|
22
27
|
else:
|
23
28
|
path = f"./{os.getenv('EXTERNAL_APP_MODULE', 'external_app')}/migrations"
|
24
29
|
|
25
30
|
with app.app_context():
|
26
|
-
|
31
|
+
Migrate(app=app, db=db, directory=path)
|
27
32
|
migrate()
|
28
33
|
|
29
34
|
|
@@ -35,12 +40,12 @@ def upgrade_migrations(revision="head"):
|
|
35
40
|
app = get_app()
|
36
41
|
external = int(os.getenv("EXTERNAL_APP", 0))
|
37
42
|
if external == 0:
|
38
|
-
path =
|
43
|
+
path = MIGRATIONS_DEFAULT_PATH
|
39
44
|
else:
|
40
45
|
path = f"./{os.getenv('EXTERNAL_APP_MODULE', 'external_app')}/migrations"
|
41
46
|
|
42
47
|
with app.app_context():
|
43
|
-
|
48
|
+
Migrate(app=app, db=db, directory=path)
|
44
49
|
upgrade(revision=revision)
|
45
50
|
|
46
51
|
|
@@ -52,12 +57,12 @@ def downgrade_migrations(revision="-1"):
|
|
52
57
|
app = get_app()
|
53
58
|
external = int(os.getenv("EXTERNAL_APP", 0))
|
54
59
|
if external == 0:
|
55
|
-
path =
|
60
|
+
path = MIGRATIONS_DEFAULT_PATH
|
56
61
|
else:
|
57
62
|
path = f"./{os.getenv('EXTERNAL_APP_MODULE', 'external_app')}/migrations"
|
58
63
|
|
59
64
|
with app.app_context():
|
60
|
-
|
65
|
+
Migrate(app=app, db=db, directory=path)
|
61
66
|
downgrade(revision=revision)
|
62
67
|
|
63
68
|
|
@@ -69,10 +74,10 @@ def init_migrations():
|
|
69
74
|
app = get_app()
|
70
75
|
external = int(os.getenv("EXTERNAL_APP", 0))
|
71
76
|
if external == 0:
|
72
|
-
path =
|
77
|
+
path = MIGRATIONS_DEFAULT_PATH
|
73
78
|
else:
|
74
79
|
path = f"./{os.getenv('EXTERNAL_APP_MODULE', 'external_app')}/migrations"
|
75
80
|
|
76
81
|
with app.app_context():
|
77
|
-
|
82
|
+
Migrate(app=app, db=db, directory=path)
|
78
83
|
init()
|
cornflow/cli/permissions.py
CHANGED
cornflow/cli/roles.py
CHANGED
cornflow/cli/schemas.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"""
|
2
2
|
File that implements the generate from schema cli command
|
3
3
|
"""
|
4
|
+
|
4
5
|
import click
|
5
6
|
from .tools.api_generator import APIGenerator
|
6
7
|
from .tools.schema_generator import SchemaGenerator
|
@@ -20,6 +21,10 @@ METHOD_OPTIONS = [
|
|
20
21
|
|
21
22
|
@click.group(name="schemas", help="Commands to manage the schemas")
|
22
23
|
def schemas():
|
24
|
+
"""
|
25
|
+
This method is empty but it serves as the building block
|
26
|
+
for the rest of the commands
|
27
|
+
"""
|
23
28
|
pass
|
24
29
|
|
25
30
|
|
cornflow/cli/service.py
CHANGED
@@ -29,30 +29,107 @@ from cornflow.shared import db
|
|
29
29
|
from cryptography.fernet import Fernet
|
30
30
|
from flask_migrate import Migrate, upgrade
|
31
31
|
|
32
|
+
MAIN_WD = "/usr/src/app"
|
33
|
+
|
32
34
|
|
33
35
|
@click.group(name="service", help="Commands to run the cornflow service")
|
34
36
|
def service():
|
37
|
+
"""
|
38
|
+
This method is empty but it serves as the building block
|
39
|
+
for the rest of the commands
|
40
|
+
"""
|
35
41
|
pass
|
36
42
|
|
37
43
|
|
38
44
|
@service.command(name="init", help="Initialize the service")
|
39
45
|
def init_cornflow_service():
|
40
46
|
click.echo("Starting the service")
|
41
|
-
os.chdir(
|
47
|
+
os.chdir(MAIN_WD)
|
48
|
+
|
49
|
+
config = _setup_environment_variables()
|
50
|
+
_configure_logging(config["cornflow_logging"])
|
51
|
+
|
52
|
+
external_application = config["external_application"]
|
53
|
+
environment = config["environment"]
|
54
|
+
cornflow_db_conn = config["cornflow_db_conn"]
|
55
|
+
external_app_module = config["external_app_module"]
|
56
|
+
|
57
|
+
app = None # Initialize app to None
|
58
|
+
|
59
|
+
if external_application == 0:
|
60
|
+
click.echo("Initializing standard Cornflow application")
|
61
|
+
app = create_app(environment, cornflow_db_conn)
|
62
|
+
with app.app_context():
|
63
|
+
_initialize_database(app)
|
64
|
+
_create_initial_users(
|
65
|
+
config["auth"],
|
66
|
+
config["cornflow_admin_user"],
|
67
|
+
config["cornflow_admin_email"],
|
68
|
+
config["cornflow_admin_pwd"],
|
69
|
+
config["cornflow_service_user"],
|
70
|
+
config["cornflow_service_email"],
|
71
|
+
config["cornflow_service_pwd"],
|
72
|
+
)
|
73
|
+
_sync_with_airflow(
|
74
|
+
config["airflow_url"],
|
75
|
+
config["airflow_user"],
|
76
|
+
config["airflow_pwd"],
|
77
|
+
config["open_deployment"],
|
78
|
+
external_app=False,
|
79
|
+
)
|
80
|
+
_start_application(external_application, environment)
|
81
|
+
|
82
|
+
elif external_application == 1:
|
83
|
+
click.echo(f"Initializing Cornflow with external app: {external_app_module}")
|
84
|
+
if not external_app_module:
|
85
|
+
sys.exit("FATAL: EXTERNAL_APP is 1 but EXTERNAL_APP_MODULE is not set.")
|
86
|
+
|
87
|
+
_setup_external_app()
|
88
|
+
from importlib import import_module
|
89
|
+
|
90
|
+
external_app_lib = import_module(external_app_module)
|
91
|
+
app = external_app_lib.create_wsgi_app(environment, cornflow_db_conn)
|
92
|
+
|
93
|
+
with app.app_context():
|
94
|
+
_initialize_database(app, external_app_module)
|
95
|
+
_create_initial_users(
|
96
|
+
config["auth"],
|
97
|
+
config["cornflow_admin_user"],
|
98
|
+
config["cornflow_admin_email"],
|
99
|
+
config["cornflow_admin_pwd"],
|
100
|
+
config["cornflow_service_user"],
|
101
|
+
config["cornflow_service_email"],
|
102
|
+
config["cornflow_service_pwd"],
|
103
|
+
)
|
104
|
+
_sync_with_airflow(
|
105
|
+
config["airflow_url"],
|
106
|
+
config["airflow_user"],
|
107
|
+
config["airflow_pwd"],
|
108
|
+
config["open_deployment"],
|
109
|
+
external_app=True,
|
110
|
+
)
|
111
|
+
_start_application(external_application, environment, external_app_module)
|
112
|
+
|
113
|
+
else:
|
114
|
+
# This case should ideally be caught earlier or handled differently
|
115
|
+
sys.exit(f"FATAL: Invalid EXTERNAL_APP value: {external_application}")
|
116
|
+
|
117
|
+
|
118
|
+
def _setup_environment_variables():
|
119
|
+
"""Reads environment variables, sets defaults, and returns config values."""
|
42
120
|
environment = os.getenv("FLASK_ENV", "development")
|
43
121
|
os.environ["FLASK_ENV"] = environment
|
44
122
|
|
45
|
-
|
46
|
-
# Global defaults and back-compat #
|
47
|
-
###################################
|
48
|
-
# Airflow global default conn
|
123
|
+
# Airflow details
|
49
124
|
airflow_user = os.getenv("AIRFLOW_USER", "admin")
|
50
125
|
airflow_pwd = os.getenv("AIRFLOW_PWD", "admin")
|
51
126
|
airflow_url = os.getenv("AIRFLOW_URL", "http://webserver:8080")
|
52
|
-
cornflow_url = os.environ.setdefault("cornflow_url", "http://cornflow:5000")
|
53
127
|
os.environ["AIRFLOW_USER"] = airflow_user
|
54
128
|
os.environ["AIRFLOW_PWD"] = airflow_pwd
|
55
129
|
os.environ["AIRFLOW_URL"] = airflow_url
|
130
|
+
|
131
|
+
# Cornflow app config
|
132
|
+
os.environ.setdefault("cornflow_url", "http://cornflow:5000")
|
56
133
|
os.environ["FLASK_APP"] = "cornflow.app"
|
57
134
|
os.environ["SECRET_KEY"] = os.getenv("FERNET_KEY", Fernet.generate_key().decode())
|
58
135
|
|
@@ -74,10 +151,9 @@ def init_cornflow_service():
|
|
74
151
|
)
|
75
152
|
cornflow_service_pwd = os.getenv("CORNFLOW_SERVICE_PWD", "Service_user1234")
|
76
153
|
|
77
|
-
# Cornflow logging and
|
154
|
+
# Cornflow logging and deployment config
|
78
155
|
cornflow_logging = os.getenv("CORNFLOW_LOGGING", "console")
|
79
156
|
os.environ["CORNFLOW_LOGGING"] = cornflow_logging
|
80
|
-
|
81
157
|
open_deployment = os.getenv("OPEN_DEPLOYMENT", 1)
|
82
158
|
os.environ["OPEN_DEPLOYMENT"] = str(open_deployment)
|
83
159
|
signup_activated = os.getenv("SIGNUP_ACTIVATED", 1)
|
@@ -88,160 +164,188 @@ def init_cornflow_service():
|
|
88
164
|
os.environ["DEFAULT_ROLE"] = str(default_role)
|
89
165
|
|
90
166
|
# Check LDAP parameters for active directory and show message
|
91
|
-
if
|
92
|
-
|
93
|
-
"WARNING: Cornflow will be deployed with LDAP Authorization.
|
167
|
+
if auth == AUTH_LDAP:
|
168
|
+
click.echo(
|
169
|
+
"WARNING: Cornflow will be deployed with LDAP Authorization. "
|
170
|
+
"Please review your ldap auth configuration."
|
94
171
|
)
|
95
172
|
|
96
173
|
# check database param from docker env
|
97
|
-
if
|
174
|
+
if cornflow_db_conn is None:
|
98
175
|
sys.exit("FATAL: you need to provide a postgres database for Cornflow")
|
99
176
|
|
100
|
-
|
177
|
+
external_application = int(os.getenv("EXTERNAL_APP", 0))
|
178
|
+
external_app_module = os.getenv("EXTERNAL_APP_MODULE")
|
179
|
+
|
180
|
+
return {
|
181
|
+
"environment": environment,
|
182
|
+
"auth": auth,
|
183
|
+
"airflow_user": airflow_user,
|
184
|
+
"airflow_pwd": airflow_pwd,
|
185
|
+
"airflow_url": airflow_url,
|
186
|
+
"cornflow_db_conn": cornflow_db_conn,
|
187
|
+
"cornflow_admin_user": cornflow_admin_user,
|
188
|
+
"cornflow_admin_email": cornflow_admin_email,
|
189
|
+
"cornflow_admin_pwd": cornflow_admin_pwd,
|
190
|
+
"cornflow_service_user": cornflow_service_user,
|
191
|
+
"cornflow_service_email": cornflow_service_email,
|
192
|
+
"cornflow_service_pwd": cornflow_service_pwd,
|
193
|
+
"cornflow_logging": cornflow_logging,
|
194
|
+
"open_deployment": open_deployment,
|
195
|
+
"external_application": external_application,
|
196
|
+
"external_app_module": external_app_module,
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
def _configure_logging(cornflow_logging):
|
201
|
+
"""Configures log rotation if logging to file."""
|
101
202
|
if cornflow_logging == "file":
|
102
203
|
try:
|
103
|
-
conf = "/usr/src/app/log/*.log {
|
104
|
-
rotate 30
|
105
|
-
daily
|
106
|
-
compress
|
107
|
-
size 20M
|
108
|
-
postrotate
|
109
|
-
kill -HUP
|
110
|
-
endscript}"
|
204
|
+
conf = f"""/usr/src/app/log/*.log {{
|
205
|
+
rotate 30
|
206
|
+
daily
|
207
|
+
compress
|
208
|
+
size 20M
|
209
|
+
postrotate
|
210
|
+
kill -HUP $(cat {MAIN_WD}/gunicorn.pid)
|
211
|
+
endscript}}"""
|
111
212
|
logrotate = subprocess.run(
|
112
|
-
f"cat > /etc/logrotate.d/cornflow <<EOF\n {conf} \nEOF",
|
213
|
+
f"cat > /etc/logrotate.d/cornflow <<EOF\n {conf} \nEOF",
|
214
|
+
shell=True,
|
215
|
+
capture_output=True,
|
216
|
+
text=True,
|
113
217
|
)
|
114
|
-
|
115
|
-
|
218
|
+
if logrotate.returncode != 0:
|
219
|
+
error(f"Error configuring logrotate: {logrotate.stderr}")
|
220
|
+
else:
|
221
|
+
print(logrotate.stdout)
|
222
|
+
except Exception as e:
|
223
|
+
error(f"Exception during logrotate configuration: {e}")
|
116
224
|
|
117
|
-
except error:
|
118
|
-
print(error)
|
119
225
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
226
|
+
def _initialize_database(app, external_app_module=None):
|
227
|
+
"""Initializes the database and runs migrations."""
|
228
|
+
with app.app_context():
|
229
|
+
if external_app_module:
|
230
|
+
from importlib import import_module
|
231
|
+
|
232
|
+
external_app_lib = import_module(external_app_module)
|
233
|
+
migrations_path = f"{os.path.dirname(external_app_lib.__file__)}/migrations"
|
234
|
+
else:
|
235
|
+
migrations_path = f"{os.path.dirname(cornflow.__file__)}/migrations"
|
236
|
+
|
237
|
+
Migrate(app=app, db=db, directory=migrations_path)
|
238
|
+
upgrade()
|
239
|
+
access_init_command(verbose=False)
|
127
240
|
|
128
|
-
if external_application == 0:
|
129
|
-
click.echo("Starting cornflow")
|
130
|
-
app = create_app(environment, cornflow_db_conn)
|
131
|
-
with app.app_context():
|
132
|
-
path = f"{os.path.dirname(cornflow.__file__)}/migrations"
|
133
|
-
Migrate(app=app, db=db, directory=path)
|
134
|
-
upgrade()
|
135
|
-
access_init_command(verbose=False)
|
136
|
-
if auth == AUTH_DB or auth == AUTH_OID:
|
137
|
-
# create cornflow admin user
|
138
|
-
create_user_with_role(
|
139
|
-
cornflow_admin_user,
|
140
|
-
cornflow_admin_email,
|
141
|
-
cornflow_admin_pwd,
|
142
|
-
"admin",
|
143
|
-
ADMIN_ROLE,
|
144
|
-
verbose=True,
|
145
|
-
)
|
146
|
-
# create cornflow service user
|
147
|
-
create_user_with_role(
|
148
|
-
cornflow_service_user,
|
149
|
-
cornflow_service_email,
|
150
|
-
cornflow_service_pwd,
|
151
|
-
"serviceuser",
|
152
|
-
SERVICE_ROLE,
|
153
|
-
verbose=True,
|
154
|
-
)
|
155
|
-
register_deployed_dags_command(
|
156
|
-
airflow_url, airflow_user, airflow_pwd, verbose=True
|
157
|
-
)
|
158
|
-
register_dag_permissions_command(open_deployment, verbose=True)
|
159
|
-
update_schemas_command(airflow_url, airflow_user, airflow_pwd, verbose=True)
|
160
241
|
|
161
|
-
|
162
|
-
|
163
|
-
|
242
|
+
def _create_initial_users(
|
243
|
+
auth,
|
244
|
+
admin_user,
|
245
|
+
admin_email,
|
246
|
+
admin_pwd,
|
247
|
+
service_user,
|
248
|
+
service_email,
|
249
|
+
service_pwd,
|
250
|
+
):
|
251
|
+
"""Creates the initial admin and service users if using DB or OID auth."""
|
252
|
+
if auth == AUTH_DB or auth == AUTH_OID:
|
253
|
+
# create cornflow admin user
|
254
|
+
create_user_with_role(
|
255
|
+
admin_user,
|
256
|
+
admin_email,
|
257
|
+
admin_pwd,
|
258
|
+
"admin",
|
259
|
+
ADMIN_ROLE,
|
260
|
+
verbose=True,
|
261
|
+
)
|
262
|
+
# create cornflow service user
|
263
|
+
create_user_with_role(
|
264
|
+
service_user,
|
265
|
+
service_email,
|
266
|
+
service_pwd,
|
267
|
+
"serviceuser",
|
268
|
+
SERVICE_ROLE,
|
269
|
+
verbose=True,
|
164
270
|
)
|
165
271
|
|
166
|
-
elif external_application == 1:
|
167
|
-
click.echo(f"Starting cornflow + {os.getenv('EXTERNAL_APP_MODULE')}")
|
168
|
-
os.chdir("/usr/src/app")
|
169
272
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
273
|
+
def _sync_with_airflow(
|
274
|
+
airflow_url, airflow_user, airflow_pwd, open_deployment, external_app=False
|
275
|
+
):
|
276
|
+
"""Syncs DAGs, permissions, and schemas with Airflow."""
|
277
|
+
register_deployed_dags_command(airflow_url, airflow_user, airflow_pwd, verbose=True)
|
278
|
+
register_dag_permissions_command(open_deployment, verbose=True)
|
279
|
+
update_schemas_command(airflow_url, airflow_user, airflow_pwd, verbose=True)
|
280
|
+
if external_app:
|
281
|
+
update_dag_registry_command(
|
282
|
+
airflow_url, airflow_user, airflow_pwd, verbose=True
|
283
|
+
)
|
176
284
|
|
177
|
-
for _, value in env_variables.items():
|
178
|
-
register_ssh_host(value)
|
179
285
|
|
180
|
-
|
181
|
-
|
182
|
-
|
286
|
+
def _setup_external_app():
|
287
|
+
"""Performs setup steps specific to external applications."""
|
288
|
+
os.chdir(MAIN_WD)
|
289
|
+
if _register_key():
|
290
|
+
prefix = "CUSTOM_SSH_"
|
291
|
+
env_variables = {
|
292
|
+
key: value for key, value in os.environ.items() if key.startswith(prefix)
|
293
|
+
}
|
294
|
+
for _, value in env_variables.items():
|
295
|
+
_register_ssh_host(value)
|
183
296
|
|
184
|
-
|
297
|
+
# Install requirements for the external app
|
298
|
+
pip_install_cmd = "$(command -v pip) install --user -r requirements.txt"
|
299
|
+
click.echo(f"Running: {pip_install_cmd}")
|
300
|
+
result = subprocess.run(pip_install_cmd, shell=True, capture_output=True, text=True)
|
301
|
+
if result.returncode != 0:
|
302
|
+
error(f"Error installing requirements: {result.stderr}")
|
303
|
+
else:
|
304
|
+
print(result.stdout)
|
305
|
+
time.sleep(5) # Consider if this sleep is truly necessary
|
306
|
+
sys.path.append(MAIN_WD)
|
185
307
|
|
186
|
-
external_app = import_module(os.getenv("EXTERNAL_APP_MODULE"))
|
187
|
-
app = external_app.create_wsgi_app(environment, cornflow_db_conn)
|
188
|
-
with app.app_context():
|
189
|
-
path = f"{os.path.dirname(external_app.__file__)}/migrations"
|
190
|
-
migrate = Migrate(app=app, db=db, directory=path)
|
191
|
-
upgrade()
|
192
|
-
access_init_command(verbose=False)
|
193
|
-
if auth == AUTH_DB or auth == AUTH_OID:
|
194
|
-
# create cornflow admin user
|
195
|
-
create_user_with_role(
|
196
|
-
cornflow_admin_user,
|
197
|
-
cornflow_admin_email,
|
198
|
-
cornflow_admin_pwd,
|
199
|
-
"admin",
|
200
|
-
ADMIN_ROLE,
|
201
|
-
verbose=True,
|
202
|
-
)
|
203
|
-
# create cornflow service user
|
204
|
-
create_user_with_role(
|
205
|
-
cornflow_service_user,
|
206
|
-
cornflow_service_email,
|
207
|
-
cornflow_service_pwd,
|
208
|
-
"serviceuser",
|
209
|
-
SERVICE_ROLE,
|
210
|
-
verbose=True,
|
211
|
-
)
|
212
|
-
register_deployed_dags_command(
|
213
|
-
airflow_url, airflow_user, airflow_pwd, verbose=True
|
214
|
-
)
|
215
|
-
register_dag_permissions_command(open_deployment, verbose=True)
|
216
|
-
update_schemas_command(airflow_url, airflow_user, airflow_pwd, verbose=True)
|
217
|
-
update_dag_registry_command(
|
218
|
-
airflow_url, airflow_user, airflow_pwd, verbose=True
|
219
|
-
)
|
220
308
|
|
221
|
-
|
222
|
-
|
223
|
-
|
309
|
+
def _start_application(external_application, environment, external_app_module=None):
|
310
|
+
"""Starts the Gunicorn server."""
|
311
|
+
if external_application == 0:
|
312
|
+
os.environ["GUNICORN_WORKING_DIR"] = MAIN_WD
|
313
|
+
gunicorn_cmd = (
|
314
|
+
"/usr/local/bin/gunicorn -c python:cornflow.gunicorn "
|
315
|
+
f"\"cornflow.app:create_app('{environment}')\""
|
316
|
+
)
|
317
|
+
elif external_application == 1:
|
318
|
+
os.environ["GUNICORN_WORKING_DIR"] = MAIN_WD
|
319
|
+
if not external_app_module:
|
320
|
+
raise ValueError(
|
321
|
+
"EXTERNAL_APP_MODULE must be set for external applications"
|
322
|
+
)
|
323
|
+
gunicorn_cmd = (
|
324
|
+
"/usr/local/bin/gunicorn -c python:cornflow.gunicorn "
|
325
|
+
f"\"{external_app_module}:create_wsgi_app('{environment}')\""
|
224
326
|
)
|
225
|
-
|
226
327
|
else:
|
227
|
-
raise
|
328
|
+
raise ValueError(f"Invalid EXTERNAL_APP value: {external_application}")
|
228
329
|
|
330
|
+
click.echo(f"Starting application with Gunicorn: {gunicorn_cmd}")
|
331
|
+
os.system(gunicorn_cmd)
|
229
332
|
|
230
|
-
|
333
|
+
|
334
|
+
def _register_ssh_host(host):
|
231
335
|
if host is not None:
|
232
|
-
add_host = f"ssh-keyscan {host} >>
|
233
|
-
config_ssh_host = f"echo Host {host} >>
|
234
|
-
config_ssh_key =
|
336
|
+
add_host = f"ssh-keyscan {host} >> {MAIN_WD}/.ssh/known_hosts"
|
337
|
+
config_ssh_host = f"echo Host {host} >> {MAIN_WD}/.ssh/config"
|
338
|
+
config_ssh_key = (
|
339
|
+
'echo " IdentityFile {MAIN_WD}/.ssh/id_rsa" >> {MAIN_WD}/.ssh/config'
|
340
|
+
)
|
235
341
|
os.system(add_host)
|
236
342
|
os.system(config_ssh_host)
|
237
343
|
os.system(config_ssh_key)
|
238
344
|
|
239
345
|
|
240
|
-
def
|
241
|
-
if os.path.isfile("
|
242
|
-
add_key =
|
243
|
-
"chmod 0600 /usr/src/app/.ssh/id_rsa && ssh-add /usr/src/app/.ssh/id_rsa"
|
244
|
-
)
|
346
|
+
def _register_key():
|
347
|
+
if os.path.isfile(f"{MAIN_WD}/.ssh/id_rsa"):
|
348
|
+
add_key = f"chmod 0600 {MAIN_WD}/.ssh/id_rsa && ssh-add {MAIN_WD}/.ssh/id_rsa"
|
245
349
|
os.system(add_key)
|
246
350
|
return True
|
247
351
|
else:
|