File size: 2,954 Bytes
3b993c4 24d33b9 3b993c4 24d33b9 3b993c4 dce8143 a1ead4c dce8143 49b13c6 dce8143 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
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"])
|