seanpedrickcase commited on
Commit
b1c3d49
1 Parent(s): 54d383e

Minor bug fix to connections parameter function

Browse files
Files changed (1) hide show
  1. search_funcs/helper_functions.py +57 -47
search_funcs/helper_functions.py CHANGED
@@ -57,56 +57,66 @@ def ensure_output_folder_exists(output_folder):
57
  print(f"The output folder already exists:", folder_name)
58
 
59
  async def get_connection_params(request: gr.Request):
60
- if request:
61
- # request_data = await request.json() # Parse JSON body
62
- # print("All request data:", request_data)
63
- #context_value = request_data.get('context')
64
- #if 'context' in request_data:
65
- # print("Request context dictionary:", request_data['context'])
66
-
67
- # print("Request headers dictionary:", request.headers)
68
- # print("All host elements", request.client)
69
- # print("IP address:", request.client.host)
70
- #print("Query parameters:", dict(request.query_params))
71
- # To get the underlying FastAPI items you would need to use await and some fancy @ stuff for a live query: https://fastapi.tiangolo.com/vi/reference/request/
72
- #print("Request dictionary to object:", request.request.body())
73
- print("Session hash:", request.session_hash)
74
-
75
- # Retrieving or setting CUSTOM_CLOUDFRONT_HEADER
76
- CUSTOM_CLOUDFRONT_HEADER_var = get_or_create_env_var('CUSTOM_CLOUDFRONT_HEADER', '')
77
- print(f'The value of CUSTOM_CLOUDFRONT_HEADER is {CUSTOM_CLOUDFRONT_HEADER_var}')
78
-
79
- # Retrieving or setting CUSTOM_CLOUDFRONT_HEADER_VALUE
80
- CUSTOM_CLOUDFRONT_HEADER_VALUE_var = get_or_create_env_var('CUSTOM_CLOUDFRONT_HEADER_VALUE', '')
81
- print(f'The value of CUSTOM_CLOUDFRONT_HEADER_VALUE_var is {CUSTOM_CLOUDFRONT_HEADER_VALUE_var}')
82
-
83
- if CUSTOM_CLOUDFRONT_HEADER_var and CUSTOM_CLOUDFRONT_HEADER_VALUE_var:
84
- if CUSTOM_CLOUDFRONT_HEADER_var in request.headers:
85
- supplied_cloudfront_custom_value = request.headers[CUSTOM_CLOUDFRONT_HEADER_var]
86
- if supplied_cloudfront_custom_value == CUSTOM_CLOUDFRONT_HEADER_VALUE_var:
87
- print("Custom Cloudfront header found:", supplied_cloudfront_custom_value)
88
- else:
89
- raise(ValueError, "Custom Cloudfront header value does not match expected value.")
90
-
91
- if 'x-cognito-id' in request.headers:
92
- out_session_hash = request.headers['x-cognito-id']
93
- base_folder = "user-files/"
94
- print("Cognito ID found:", out_session_hash)
 
 
 
 
 
 
 
 
 
 
95
 
96
- else:
97
- out_session_hash = request.session_hash
98
- base_folder = "temp-files/"
99
- # print("Cognito ID not found. Using session hash as save folder.")
100
-
101
- output_folder = base_folder + out_session_hash + "/"
102
- #if bucket_name:
103
- # print("S3 output folder is: " + "s3://" + bucket_name + "/" + output_folder)
104
-
105
- return out_session_hash, output_folder
106
  else:
107
- print("No session parameters found.")
108
- return "", ""
 
109
 
 
 
 
 
 
 
 
 
 
110
  # Attempt to delete content of gradio temp folder
111
  # def get_temp_folder_path():
112
  # username = getpass.getuser()
 
57
  print(f"The output folder already exists:", folder_name)
58
 
59
  async def get_connection_params(request: gr.Request):
60
+ base_folder = ""
61
+
62
+ if request:
63
+ #print("request user:", request.username)
64
+
65
+ #request_data = await request.json() # Parse JSON body
66
+ #print("All request data:", request_data)
67
+ #context_value = request_data.get('context')
68
+ #if 'context' in request_data:
69
+ # print("Request context dictionary:", request_data['context'])
70
+
71
+ # print("Request headers dictionary:", request.headers)
72
+ # print("All host elements", request.client)
73
+ # print("IP address:", request.client.host)
74
+ # print("Query parameters:", dict(request.query_params))
75
+ # To get the underlying FastAPI items you would need to use await and some fancy @ stuff for a live query: https://fastapi.tiangolo.com/vi/reference/request/
76
+ #print("Request dictionary to object:", request.request.body())
77
+ print("Session hash:", request.session_hash)
78
+
79
+ # Retrieving or setting CUSTOM_CLOUDFRONT_HEADER
80
+ CUSTOM_CLOUDFRONT_HEADER_var = get_or_create_env_var('CUSTOM_CLOUDFRONT_HEADER', '')
81
+ print(f'The value of CUSTOM_CLOUDFRONT_HEADER is {CUSTOM_CLOUDFRONT_HEADER_var}')
82
+
83
+ # Retrieving or setting CUSTOM_CLOUDFRONT_HEADER_VALUE
84
+ CUSTOM_CLOUDFRONT_HEADER_VALUE_var = get_or_create_env_var('CUSTOM_CLOUDFRONT_HEADER_VALUE', '')
85
+ print(f'The value of CUSTOM_CLOUDFRONT_HEADER_VALUE_var is {CUSTOM_CLOUDFRONT_HEADER_VALUE_var}')
86
+
87
+ if CUSTOM_CLOUDFRONT_HEADER_var and CUSTOM_CLOUDFRONT_HEADER_VALUE_var:
88
+ if CUSTOM_CLOUDFRONT_HEADER_var in request.headers:
89
+ supplied_cloudfront_custom_value = request.headers[CUSTOM_CLOUDFRONT_HEADER_var]
90
+ if supplied_cloudfront_custom_value == CUSTOM_CLOUDFRONT_HEADER_VALUE_var:
91
+ print("Custom Cloudfront header found:", supplied_cloudfront_custom_value)
92
+ else:
93
+ raise(ValueError, "Custom Cloudfront header value does not match expected value.")
94
+
95
+ # Get output save folder from 1 - username passed in from direct Cognito login, 2 - Cognito ID header passed through a Lambda authenticator, 3 - the session hash.
96
+
97
+ if request.username:
98
+ out_session_hash = request.username
99
+ base_folder = "user-files/"
100
+
101
+ elif 'x-cognito-id' in request.headers:
102
+ out_session_hash = request.headers['x-cognito-id']
103
+ base_folder = "user-files/"
104
+ print("Cognito ID found:", out_session_hash)
105
 
 
 
 
 
 
 
 
 
 
 
106
  else:
107
+ out_session_hash = request.session_hash
108
+ base_folder = "temp-files/"
109
+ # print("Cognito ID not found. Using session hash as save folder:", out_session_hash)
110
 
111
+ output_folder = base_folder + out_session_hash + "/"
112
+ #if bucket_name:
113
+ # print("S3 output folder is: " + "s3://" + bucket_name + "/" + output_folder)
114
+
115
+ return out_session_hash, output_folder
116
+ else:
117
+ print("No session parameters found.")
118
+ return "",""
119
+
120
  # Attempt to delete content of gradio temp folder
121
  # def get_temp_folder_path():
122
  # username = getpass.getuser()