|
3 | 3 | from datetime import datetime |
4 | 4 | from re import match |
5 | 5 |
|
6 | | -from constants import VALID_VERSIONS |
| 6 | +from constants import EXTENDED_ATTRIBUTES_FILE_PREFIX, VALID_EA_VERSIONS, VALID_VERSIONS |
7 | 7 | from elasticache import ( |
8 | 8 | get_supplier_system_from_cache, |
9 | 9 | get_valid_vaccine_types_from_cache, |
@@ -45,8 +45,22 @@ def validate_extended_attributes_file_key(file_key: str) -> str: |
45 | 45 | if not match(r"^[^_.]*_[^_.]*_[^_.]*_[^_.]*_[^_.]*_[^_.]*_[^_.]*", file_key): |
46 | 46 | raise InvalidFileKeyError("Initial file validation failed: invalid extended attributes file key format") |
47 | 47 |
|
48 | | - file_key_parts_without_extension, _ = split_file_key(file_key) |
| 48 | + file_key_parts_without_extension, extension = split_file_key(file_key) |
| 49 | + file_type = "_".join(file_key_parts_without_extension[:3]) |
| 50 | + version = "_".join(file_key_parts_without_extension[3:5]) |
49 | 51 | organization_code = file_key_parts_without_extension[5] |
| 52 | + timestamp = file_key_parts_without_extension[6] |
| 53 | + supplier = get_supplier_system_from_cache(organization_code) |
| 54 | + |
| 55 | + if not ( |
| 56 | + file_type == EXTENDED_ATTRIBUTES_FILE_PREFIX |
| 57 | + and version == VALID_EA_VERSIONS |
| 58 | + and supplier # Note that if supplier could be identified, this also implies that ODS code is valid |
| 59 | + and is_valid_datetime(timestamp) |
| 60 | + and ((extension == "CSV") or (extension == "DAT")) # The DAT extension has been added for MESH file processing |
| 61 | + ): |
| 62 | + raise InvalidFileKeyError("Initial file validation failed: invalid file key") |
| 63 | + |
50 | 64 | return f"{organization_code}_COVID" |
51 | 65 |
|
52 | 66 |
|
|
0 commit comments