|
|
|
@ -7,7 +7,8 @@ import pytz
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
|
|
|
|
|
|
from src.config import RELIABILITY_SERVICE_API, TIMEZONE
|
|
|
|
from src.config import RELIABILITY_SERVICE_API, TIMEZONE
|
|
|
|
|
|
|
|
import hvac
|
|
|
|
|
|
|
|
from typing import Optional, Dict, List
|
|
|
|
|
|
|
|
|
|
|
|
def parse_relative_expression(date_str: str) -> Optional[datetime]:
|
|
|
|
def parse_relative_expression(date_str: str) -> Optional[datetime]:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@ -185,3 +186,47 @@ def sanitize_filename(filename: str) -> str:
|
|
|
|
filename = filename[:200]
|
|
|
|
filename = filename[:200]
|
|
|
|
|
|
|
|
|
|
|
|
return filename.strip()
|
|
|
|
return filename.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_vault_secrets(
|
|
|
|
|
|
|
|
vault_url: str,
|
|
|
|
|
|
|
|
role_id: str,
|
|
|
|
|
|
|
|
secret_id: str,
|
|
|
|
|
|
|
|
secret_path: str,
|
|
|
|
|
|
|
|
secret_keys_to_be_returned: List[str],
|
|
|
|
|
|
|
|
mount_point: str = "secret"
|
|
|
|
|
|
|
|
) -> Optional[Dict[str, str]]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
client = hvac.Client(url=vault_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Login using AppRole
|
|
|
|
|
|
|
|
client.auth.approle.login(
|
|
|
|
|
|
|
|
role_id=role_id,
|
|
|
|
|
|
|
|
secret_id=secret_id
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not client.is_authenticated():
|
|
|
|
|
|
|
|
raise Exception("Vault authentication failed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Read secret
|
|
|
|
|
|
|
|
response = client.secrets.kv.v2.read_secret_version(
|
|
|
|
|
|
|
|
path=secret_path,
|
|
|
|
|
|
|
|
mount_point=mount_point
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
secret_data = response["data"]["data"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filter only requested keys
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for key in secret_keys_to_be_returned:
|
|
|
|
|
|
|
|
if key not in secret_data:
|
|
|
|
|
|
|
|
raise KeyError(f"Key '{key}' not found in secret")
|
|
|
|
|
|
|
|
result[key] = secret_data[key]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print(f"Error retrieving secret from Vault: {str(e)}")
|
|
|
|
|
|
|
|
return None
|