Skip to content

Commit

Permalink
remove unnecessary environment code from sweepers_driver.py
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdunnjpl committed Aug 14, 2024
1 parent 7f566d3 commit 28ac84a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
18 changes: 0 additions & 18 deletions docker/sweepers_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,6 @@

urllib3.disable_warnings()

opensearch_endpoint = os.environ.get('PROV_ENDPOINT', '')
if opensearch_endpoint.strip() == '':
raise RuntimeError('Environment variable PROV_ENDPOINT must be provided')
log.info(f'Targeting OpenSearch endpoint "{opensearch_endpoint}"')

try:
provCredentialsStr = os.environ["PROV_CREDENTIALS"]
except KeyError:
raise RuntimeError('Environment variable PROV_CREDENTIALS must be provided')

try:
provCredentials = json.loads(provCredentialsStr)
username = list(provCredentials.keys())[0]
password = provCredentials[username]
except Exception as err:
logging.error(err)
raise ValueError(f'Failed to parse username/password from PROV_CREDENTIALS value "{provCredentialsStr}": {err}')

log_level = parse_log_level(os.environ.get('LOGLEVEL', 'INFO'))


Expand Down
10 changes: 8 additions & 2 deletions src/pds/registrysweepers/utils/db/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import os

import requests
Expand Down Expand Up @@ -27,8 +28,13 @@ def get_opensearch_client_from_environment(verify_certs: bool = True) -> OpenSea
if creds_str is not None and iam_role_name is not None:
raise EnvironmentError(f'Only one of env vars ["{userpass_env_var_key}", "{iam_role_env_var_key}"] may be set')
if creds_str is not None:
creds_dict = json.loads(creds_str)
username, password = creds_dict.popitem()
try:
creds_dict = json.loads(creds_str)
username, password = creds_dict.popitem()
except Exception as err:
logging.error(err)
raise ValueError(f'Failed to parse username/password from PROV_CREDENTIALS value "{creds_str}": {err}')

return get_userpass_opensearch_client(endpoint_url, username, password, verify_certs)
elif iam_role_name is not None:
return get_aws_aoss_client_from_ssm(endpoint_url, iam_role_name)
Expand Down

0 comments on commit 28ac84a

Please sign in to comment.