import os from functools import cache from pathlib import Path from typing import Any import tomli def _get_src_directory() -> str: """ Get the absolute path to the src directory. This function traverses up the directory tree from the current file's location until it finds the 'src' directory. Returns: str: The absolute path to the src directory. Raises: FileNotFoundError: If the src directory cannot be found. """ current_path = Path(__file__).resolve() for parent in current_path.parents: if parent.name == "src": return str(parent) raise FileNotFoundError("Could not find 'src' directory in the path.") def _get_config() -> dict[str, Any]: """ Read and parse the config.toml file. This function looks for the config.toml file in the src/vsp/shared directory, regardless of where it's being called from. Returns: dict[str, Any]: The parsed contents of the config.toml file. Raises: FileNotFoundError: If the config.toml file cannot be found. """ src_dir = _get_src_directory() config_path = os.path.join(src_dir, "vsp", "shared", "config.toml") if not os.path.exists(config_path): raise FileNotFoundError(f"Config file not found at {config_path}") with open(config_path, "rb") as f: return tomli.load(f) @cache def get_role_arn() -> str: """ Reads the Github role ARN from the TOML configuration file. """ config = _get_config() role_name = config["aws"]["role_name"] account = get_aws_account() return f"arn:aws:iam::{account}:role/{role_name}" @cache def get_aws_account() -> str: """ Reads the AWS account from the TOML configuration file. """ config = _get_config() return str(config["aws"]["aws_account"]) @cache def get_bedrock_account() -> str: """ Reads the Bedrock account from the TOML configuration file. """ config = _get_config() return str(config["aws"]["bedrock_aws_account"]) def get_aws_region() -> str: """ Always us-east-1 for now """ return "us-east-1" @cache def get_openai_api_key_path() -> str: """ Reads the OpenAI API key path from the TOML configuration file. Key is in AWS parameter store """ config = _get_config() return str(config["openai"]["openai_api_key_parameter_store_path"]) @cache def get_openrouter_api_key_path() -> str: """ Reads the OpenRouter API key path from the TOML configuration file. Key is in AWS parameter store """ config = _get_config() return str(config["openrouter"]["openrouter_api_key_parameter_store_path"]) @cache def get_linkedin_key_path() -> str: """ Reads the RapidAPI key path from the TOML configuration file for Linkedin. Key is in AWS parameter store """ config = _get_config() return str(config["linkedin"]["linkedin_api_key_parameter_store_path"])