|
2 | 2 | from typing import Optional
|
3 | 3 | import yaml
|
4 | 4 |
|
| 5 | +from services.ssm_service import SSMService |
| 6 | + |
| 7 | + |
| 8 | +ENV_VAR_TO_SSM_NAME = { |
| 9 | + 'CONTENT_CAFE_USER': 'contentcafe/user', |
| 10 | + 'CONTENT_CAFE_PSWD': 'contentcafe/pswd', |
| 11 | + 'ELASTICSEARCH_PSWD': 'elasticsearch/pswd', |
| 12 | + 'ELASTICSEARCH_USER': 'elasticsearch/user', |
| 13 | + 'GITHUB_API_KEY': 'github-key', |
| 14 | + 'GOOGLE_BOOKS_KEY': 'google-books/api-key', |
| 15 | + 'HATHI_API_KEY': 'hathitrust/api-key', |
| 16 | + 'HATHI_API_SECRET': 'hathitrust/api-secret', |
| 17 | + 'NEW_RELIC_LICENSE_KEY': 'newrelic/key', |
| 18 | + 'NYPL_API_CLIENT_ID': 'nypl-api/client-id', |
| 19 | + 'NYPL_API_CLIENT_PUBLIC_KEY': 'nypl-api/public-key', |
| 20 | + 'NYPL_API_CLIENT_SECRET': 'nypl-api/client-secret', |
| 21 | + 'NYPL_BIB_PSWD': 'postgres/nypl-pswd', |
| 22 | + 'NYPL_BIB_USER': 'postgres/nypl-user', |
| 23 | + 'OCLC_METADATA_ID': 'oclc-metadata-clientid', |
| 24 | + 'OCLC_METADATA_SECRET': 'oclc-metadata-secret', |
| 25 | + 'OCLC_CLIENT_ID': 'oclc-search-clientid', |
| 26 | + 'OCLC_CLIENT_SECRET': 'oclc-search-secret', |
| 27 | + 'POSTGRES_PSWD': 'postgres/pswd', |
| 28 | + 'POSTGRES_USER': 'postgres/user', |
| 29 | + 'RABBIT_PSWD': 'rabbit-pswd', |
| 30 | + 'RABBIT_USER': 'rabbit-user', |
| 31 | +} |
| 32 | + |
5 | 33 |
|
6 | 34 | def load_env_file(run_type: str, file_string: Optional[str]=None) -> None:
|
7 | 35 | """Loads configuration details from a specific yaml file.
|
@@ -37,3 +65,12 @@ def load_env_file(run_type: str, file_string: Optional[str]=None) -> None:
|
37 | 65 | if env_dict:
|
38 | 66 | for key, value in env_dict.items():
|
39 | 67 | os.environ[key] = value
|
| 68 | + |
| 69 | + load_secrets() |
| 70 | + |
| 71 | +def load_secrets(): |
| 72 | + ssm_service = SSMService() |
| 73 | + |
| 74 | + for env_var, param_name in ENV_VAR_TO_SSM_NAME.items(): |
| 75 | + if os.environ.get(env_var, None) is None: |
| 76 | + os.environ[env_var] = ssm_service.get_parameter(param_name) |
0 commit comments