seanpedrickcase
commited on
Commit
•
f9e3451
1
Parent(s):
7f029b5
When running on cloud now checks for relevant header details on load
Browse files
search_funcs/helper_functions.py
CHANGED
@@ -36,11 +36,14 @@ def get_or_create_env_var(var_name, default_value):
|
|
36 |
return value
|
37 |
|
38 |
# Retrieving or setting output folder
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
output_folder = get_or_create_env_var(env_var_name, default_value)
|
43 |
-
print(f'The value of {env_var_name} is {output_folder}')
|
44 |
|
45 |
def ensure_output_folder_exists(output_folder):
|
46 |
"""Checks if the output folder exists, creates it if not."""
|
@@ -70,6 +73,22 @@ def get_connection_params(request: gr.Request):
|
|
70 |
#print("Request dictionary to object:", request.request.body())
|
71 |
#print("Session hash:", request.session_hash)
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
if 'x-cognito-id' in request.headers:
|
74 |
out_session_hash = request.headers['x-cognito-id']
|
75 |
base_folder = "user-files/"
|
|
|
36 |
return value
|
37 |
|
38 |
# Retrieving or setting output folder
|
39 |
+
output_folder = get_or_create_env_var('GRADIO_OUTPUT_FOLDER', 'output/')
|
40 |
+
print(f'The value of GRADIO_OUTPUT_FOLDER is {output_folder}')
|
41 |
+
|
42 |
+
# Retrieving or setting RUNNING_ON_APP_RUNNER
|
43 |
+
running_on_app_runner_var = get_or_create_env_var('RUNNING_ON_APP_RUNNER', '0')
|
44 |
+
print(f'The value of RUNNING_ON_APP_RUNNER is {running_on_app_runner_var}')
|
45 |
+
|
46 |
|
|
|
|
|
47 |
|
48 |
def ensure_output_folder_exists(output_folder):
|
49 |
"""Checks if the output folder exists, creates it if not."""
|
|
|
73 |
#print("Request dictionary to object:", request.request.body())
|
74 |
#print("Session hash:", request.session_hash)
|
75 |
|
76 |
+
# Retrieving or setting CUSTOM_CLOUDFRONT_HEADER
|
77 |
+
CUSTOM_CLOUDFRONT_HEADER_var = get_or_create_env_var('CUSTOM_CLOUDFRONT_HEADER', '')
|
78 |
+
print(f'The value of CUSTOM_CLOUDFRONT_HEADER is {CUSTOM_CLOUDFRONT_HEADER_var}')
|
79 |
+
|
80 |
+
# Retrieving or setting CUSTOM_CLOUDFRONT_HEADER_VALUE
|
81 |
+
CUSTOM_CLOUDFRONT_HEADER_VALUE_var = get_or_create_env_var('CUSTOM_CLOUDFRONT_HEADER_VALUE', '')
|
82 |
+
print(f'The value of CUSTOM_CLOUDFRONT_HEADER_VALUE_var is {CUSTOM_CLOUDFRONT_HEADER_VALUE_var}')
|
83 |
+
|
84 |
+
if CUSTOM_CLOUDFRONT_HEADER_var and CUSTOM_CLOUDFRONT_HEADER_VALUE_var:
|
85 |
+
if CUSTOM_CLOUDFRONT_HEADER_var in request.headers:
|
86 |
+
supplied_cloudfront_custom_value = request.headers[CUSTOM_CLOUDFRONT_HEADER_var]
|
87 |
+
if supplied_cloudfront_custom_value == CUSTOM_CLOUDFRONT_HEADER_VALUE_var:
|
88 |
+
print("Custom Cloudfront header found:", supplied_cloudfront_custom_value)
|
89 |
+
else:
|
90 |
+
raise(ValueError, "Custom Cloudfront header value does not match expected value.")
|
91 |
+
|
92 |
if 'x-cognito-id' in request.headers:
|
93 |
out_session_hash = request.headers['x-cognito-id']
|
94 |
base_folder = "user-files/"
|