TokenFetcher

class openapi_client.amorphic_api_client.TokenFetcher(aws_profile=None, logger=None)[source]

Bases: object

Utility class to fetch PAT tokens from various sources for local development

__init__(aws_profile=None, logger=None)[source]

Initialize TokenFetcher

Parameters:
  • aws_profile (Optional[str]) – AWS profile name for local development

  • logger (Optional[logging.Logger]) – Logger instance for consistent logging

fetch_token_from_env(env_var_name)[source]

Fetch token from environment variable

Parameters:

env_var_name (str) – Environment variable name

Returns:

Token if found, None otherwise

Return type:

Optional[str]

fetch_token_from_ssm(parameter_name, decrypt=True)[source]

Fetch token from AWS SSM Parameter Store

Parameters:
  • parameter_name (str) – SSM parameter name

  • decrypt (bool) – Whether to decrypt SecureString parameters

Returns:

Token if found, None otherwise

Return type:

Optional[str]

fetch_token_from_secrets_manager(secret_arn)[source]

Fetch token from AWS Secrets Manager

Parameters:

secret_arn (str) – Secret ARN or name

Returns:

Token if found, None otherwise

Return type:

Optional[str]

fetch_token(env_var=None, ssm_parameter=None, secret_arn=None)[source]

Fetch token from the specified source

Parameters:
  • env_var (Optional[str]) – Environment variable name

  • ssm_parameter (Optional[str]) – SSM parameter name

  • secret_arn (Optional[str]) – Secrets Manager secret ARN

Returns:

Token from the specified source

Return type:

str

Raises:

ValueError – If no token source is specified

Overview:

The TokenFetcher class is a utility for retrieving PAT (Personal Access Tokens) from various sources including environment variables, AWS SSM Parameter Store, and AWS Secrets Manager. This provides flexibility for different deployment environments and security requirements.

Key Features:

  • Multiple Token Sources: Support for environment variables, SSM, and Secrets Manager

  • AWS Profile Support: Optional AWS profile specification for local development

  • Flexible Configuration: Easy switching between token sources

Basic Usage:

from openapi_client.amorphic_api_client import TokenFetcher

# Create token fetcher
fetcher = TokenFetcher()

# Fetch from environment variable
token = fetcher.fetch_token_from_env('PAT_TOKEN')

# Fetch from AWS SSM
token = fetcher.fetch_token_from_ssm('/myapp/api/token')

# Fetch from AWS Secrets Manager
token = fetcher.fetch_token_from_secrets_manager('arn:aws:secretsmanager:...')

AWS Profile Support:

# For local development with specific AWS profile
fetcher = TokenFetcher(aws_profile='myprofile')
token = fetcher.fetch_token_from_ssm('/myapp/api/token')

Unified Token Fetching:

# Fetch from any configured source
token = fetcher.fetch_token(env_var='PAT_TOKEN')
# OR
token = fetcher.fetch_token(ssm_parameter='/myapp/api/token')
# OR
token = fetcher.fetch_token(secret_arn='arn:aws:secretsmanager:...')