Commit
·
e4c7d3c
1
Parent(s):
208e806
Fixed s3 load for allow list and cost codes
Browse files- app.py +12 -8
- tools/aws_functions.py +2 -2
- tools/config.py +5 -5
app.py
CHANGED
@@ -584,23 +584,27 @@ with app:
|
|
584 |
# Get connection details on app load
|
585 |
app.load(get_connection_params, inputs=[output_folder_textbox, input_folder_textbox], outputs=[session_hash_state, output_folder_textbox, session_hash_textbox, input_folder_textbox])
|
586 |
|
587 |
-
# If relevant environment variable is set, load in the default allow list file from S3 or locally
|
588 |
if GET_DEFAULT_ALLOW_LIST == "True" and ALLOW_LIST_PATH:
|
589 |
-
|
590 |
-
if not os.path.exists(ALLOW_LIST_PATH):
|
591 |
app.load(download_file_from_s3, inputs=[s3_default_bucket, s3_default_allow_list_file, default_allow_list_output_folder_location]).\
|
592 |
success(load_in_default_allow_list, inputs = [default_allow_list_output_folder_location], outputs=[in_allow_list])
|
593 |
-
|
|
|
|
|
594 |
app.load(load_in_default_allow_list, inputs = [default_allow_list_output_folder_location], outputs=[in_allow_list])
|
|
|
595 |
|
596 |
# If relevant environment variable is set, load in the default cost code file from S3 or locally
|
597 |
-
if GET_COST_CODES == "True" and COST_CODES_PATH:
|
598 |
-
|
599 |
-
if not os.path.exists(COST_CODES_PATH):
|
600 |
app.load(download_file_from_s3, inputs=[s3_default_bucket, s3_default_cost_codes_file, default_cost_codes_output_folder_location]).\
|
601 |
success(load_in_default_cost_codes, inputs = [default_cost_codes_output_folder_location], outputs=[cost_code_dataframe, cost_code_choice_drop])
|
602 |
-
|
|
|
|
|
603 |
app.load(load_in_default_cost_codes, inputs = [default_cost_codes_output_folder_location], outputs=[cost_code_dataframe, cost_code_choice_drop])
|
|
|
604 |
|
605 |
# Log usernames and times of access to file (to know who is using the app when running on AWS)
|
606 |
access_callback = CSVLogger_custom(dataset_file_name=log_file_name)
|
|
|
584 |
# Get connection details on app load
|
585 |
app.load(get_connection_params, inputs=[output_folder_textbox, input_folder_textbox], outputs=[session_hash_state, output_folder_textbox, session_hash_textbox, input_folder_textbox])
|
586 |
|
587 |
+
# If relevant environment variable is set, load in the default allow list file from S3 or locally. Even when setting S3 path, need to local path to give a download location
|
588 |
if GET_DEFAULT_ALLOW_LIST == "True" and ALLOW_LIST_PATH:
|
589 |
+
if not os.path.exists(ALLOW_LIST_PATH) and S3_ALLOW_LIST_PATH:
|
|
|
590 |
app.load(download_file_from_s3, inputs=[s3_default_bucket, s3_default_allow_list_file, default_allow_list_output_folder_location]).\
|
591 |
success(load_in_default_allow_list, inputs = [default_allow_list_output_folder_location], outputs=[in_allow_list])
|
592 |
+
print("Successfully loaded allow list from S3")
|
593 |
+
elif os.path.exists(ALLOW_LIST_PATH):
|
594 |
+
print("Loading allow list from default allow list output path location:", ALLOW_LIST_PATH)
|
595 |
app.load(load_in_default_allow_list, inputs = [default_allow_list_output_folder_location], outputs=[in_allow_list])
|
596 |
+
else: print("Could not load in default allow list")
|
597 |
|
598 |
# If relevant environment variable is set, load in the default cost code file from S3 or locally
|
599 |
+
if GET_COST_CODES == "True" and COST_CODES_PATH:
|
600 |
+
if not os.path.exists(COST_CODES_PATH) and S3_COST_CODES_PATH:
|
|
|
601 |
app.load(download_file_from_s3, inputs=[s3_default_bucket, s3_default_cost_codes_file, default_cost_codes_output_folder_location]).\
|
602 |
success(load_in_default_cost_codes, inputs = [default_cost_codes_output_folder_location], outputs=[cost_code_dataframe, cost_code_choice_drop])
|
603 |
+
print("Successfully loaded cost codes from S3")
|
604 |
+
elif os.path.exists(COST_CODES_PATH):
|
605 |
+
print("Loading cost codes from default cost codes path location:", COST_CODES_PATH)
|
606 |
app.load(load_in_default_cost_codes, inputs = [default_cost_codes_output_folder_location], outputs=[cost_code_dataframe, cost_code_choice_drop])
|
607 |
+
else: print("Could not load in cost code data")
|
608 |
|
609 |
# Log usernames and times of access to file (to know who is using the app when running on AWS)
|
610 |
access_callback = CSVLogger_custom(dataset_file_name=log_file_name)
|
tools/aws_functions.py
CHANGED
@@ -37,11 +37,11 @@ if RUN_AWS_FUNCTIONS == "1":
|
|
37 |
print("Could not get assumed role from STS:", e)
|
38 |
|
39 |
# Download direct from S3 - requires login credentials
|
40 |
-
def download_file_from_s3(bucket_name, key, local_file_path_and_name):
|
41 |
|
42 |
s3 = boto3.client('s3', region_name=AWS_REGION)
|
43 |
s3.download_file(bucket_name, key, local_file_path_and_name)
|
44 |
-
print(f"File downloaded from
|
45 |
|
46 |
def download_folder_from_s3(bucket_name:str, s3_folder:str, local_folder:str):
|
47 |
"""
|
|
|
37 |
print("Could not get assumed role from STS:", e)
|
38 |
|
39 |
# Download direct from S3 - requires login credentials
|
40 |
+
def download_file_from_s3(bucket_name:str, key:str, local_file_path_and_name:str):
|
41 |
|
42 |
s3 = boto3.client('s3', region_name=AWS_REGION)
|
43 |
s3.download_file(bucket_name, key, local_file_path_and_name)
|
44 |
+
print(f"File downloaded from s3://{bucket_name}/{key} to {local_file_path_and_name}")
|
45 |
|
46 |
def download_folder_from_s3(bucket_name:str, s3_folder:str, local_folder:str):
|
47 |
"""
|
tools/config.py
CHANGED
@@ -147,19 +147,19 @@ ROOT_PATH = get_or_create_env_var('ROOT_PATH', '')
|
|
147 |
|
148 |
DEFAULT_CONCURRENCY_LIMIT = get_or_create_env_var('DEFAULT_CONCURRENCY_LIMIT', '5')
|
149 |
|
150 |
-
GET_DEFAULT_ALLOW_LIST = get_or_create_env_var('GET_DEFAULT_ALLOW_LIST', '
|
151 |
|
152 |
-
ALLOW_LIST_PATH = get_or_create_env_var('ALLOW_LIST_PATH',
|
153 |
|
154 |
-
S3_ALLOW_LIST_PATH = get_or_create_env_var('S3_ALLOW_LIST_PATH', '')
|
155 |
|
156 |
SHOW_COSTS = get_or_create_env_var('SHOW_COSTS', 'True')
|
157 |
|
158 |
-
GET_COST_CODES = get_or_create_env_var('GET_COST_CODES', '
|
159 |
|
160 |
COST_CODES_PATH = get_or_create_env_var('COST_CODES_PATH', 'config/COST_CENTRES.csv') # file should be a csv file with a single table in it that has two columns with a header. First column should contain cost codes, second column should contain a name or description for the cost code
|
161 |
|
162 |
-
S3_COST_CODES_PATH = get_or_create_env_var('
|
163 |
|
164 |
ENFORCE_COST_CODES = get_or_create_env_var('ENFORCE_COST_CODES', 'False') # If you have cost codes listed, are they compulsory?
|
165 |
|
|
|
147 |
|
148 |
DEFAULT_CONCURRENCY_LIMIT = get_or_create_env_var('DEFAULT_CONCURRENCY_LIMIT', '5')
|
149 |
|
150 |
+
GET_DEFAULT_ALLOW_LIST = get_or_create_env_var('GET_DEFAULT_ALLOW_LIST', 'True')
|
151 |
|
152 |
+
ALLOW_LIST_PATH = get_or_create_env_var('ALLOW_LIST_PATH', 'config/default_allow_list.csv') #
|
153 |
|
154 |
+
S3_ALLOW_LIST_PATH = get_or_create_env_var('S3_ALLOW_LIST_PATH', 'default_allow_list.csv') # This is a path within the DOCUMENT_REDACTION_BUCKET
|
155 |
|
156 |
SHOW_COSTS = get_or_create_env_var('SHOW_COSTS', 'True')
|
157 |
|
158 |
+
GET_COST_CODES = get_or_create_env_var('GET_COST_CODES', 'True')
|
159 |
|
160 |
COST_CODES_PATH = get_or_create_env_var('COST_CODES_PATH', 'config/COST_CENTRES.csv') # file should be a csv file with a single table in it that has two columns with a header. First column should contain cost codes, second column should contain a name or description for the cost code
|
161 |
|
162 |
+
S3_COST_CODES_PATH = get_or_create_env_var('S3_COST_CODES_PATH', 'COST_CENTRES.csv') # This is a path within the DOCUMENT_REDACTION_BUCKET
|
163 |
|
164 |
ENFORCE_COST_CODES = get_or_create_env_var('ENFORCE_COST_CODES', 'False') # If you have cost codes listed, are they compulsory?
|
165 |
|