pumpwood_communication.config
Module to set environment variables configuration.
Reads PUMPWOOD_COMMUNICATION__* variables. Legacy typo spelling
PUMPWOOD_COMUNICATION__* is supported as fallback.
1"""Module to set environment variables configuration. 2 3Reads ``PUMPWOOD_COMMUNICATION__*`` variables. Legacy typo spelling 4``PUMPWOOD_COMUNICATION__*`` is supported as fallback. 5""" 6import os 7 8 9def _getenv(correct_name, typo_name, default=None): 10 """Read env var preferring correct spelling over legacy typo. 11 12 Args: 13 correct_name (str): 14 Environment variable name with correct spelling. 15 typo_name (str): 16 Legacy environment variable name with typo. 17 default: 18 Default when neither variable is set. 19 20 Returns: 21 str | None: 22 Value from environment or default. 23 """ 24 return os.getenv( 25 correct_name, os.getenv(typo_name, default)) 26 27 28# Legacy export name kept for backward compatibility. 29PUMPWOOD_COMUNICATION__N_PARALLEL = int(_getenv( 30 "PUMPWOOD_COMMUNICATION__N_PARALLEL", 31 "PUMPWOOD_COMUNICATION__N_PARALLEL", 4)) 32"""Number of parallel requests in parallel helper functions.""" 33 34 35# Cache associated config variables 36AUTHORIZATION_CACHE_TIMEOUT = int(_getenv( 37 "PUMPWOOD_COMMUNICATION__AUTHORIZATION_CACHE_TIMEOUT", 38 "PUMPWOOD_COMUNICATION__AUTHORIZATION_CACHE_TIMEOUT", 60)) 39"""Cache timeout for authorization and row permission cache.""" 40CACHE_BASE_PATH = _getenv( 41 "PUMPWOOD_COMMUNICATION__CACHE_BASE_PATH", 42 "PUMPWOOD_COMUNICATION__CACHE_BASE_PATH", '') 43"""Base path for cache files.""" 44CACHE_LIMIT_MB = int(_getenv( 45 "PUMPWOOD_COMMUNICATION__CACHE_LIMIT_MB", 46 "PUMPWOOD_COMUNICATION__CACHE_LIMIT_MB", 250)) * 1e8 47"""Maximum disk cache size in bytes.""" 48CACHE_DEFAULT_EXPIRE = int(_getenv( 49 "PUMPWOOD_COMMUNICATION__CACHE_DEFAULT_EXPIRE", 50 "PUMPWOOD_COMUNICATION__CACHE_DEFAULT_EXPIRE", 60)) 51"""Default cache entry expiration time in seconds.""" 52CACHE_TRANSACTION_TIMEOUT = float(_getenv( 53 "PUMPWOOD_COMMUNICATION__CACHE_TRANSACTION_TIMEOUT", 54 "PUMPWOOD_COMUNICATION__CACHE_TRANSACTION_TIMEOUT", 0.1)) 55"""Default cache transaction timeout in seconds.""" 56CACHE_N_SHARDS = int(_getenv( 57 "PUMPWOOD_COMMUNICATION__CACHE_N_SHARDS", 58 "PUMPWOOD_COMUNICATION__CACHE_N_SHARDS", 8)) 59"""Number of shards used to split the cache.""" 60CACHE_ENABLE = _getenv( 61 "PUMPWOOD_COMMUNICATION__CACHE_ENABLE", 62 "PUMPWOOD_COMUNICATION__CACHE_ENABLE", "TRUE") == "TRUE" 63"""Whether cache is enabled. Options ``TRUE`` or ``FALSE``.""" 64CACHE_RETRY_ATTEMPTS = int(_getenv( 65 "PUMPWOOD_COMMUNICATION__CACHE_RETRY_ATTEMPTS", 66 "PUMPWOOD_COMUNICATION__CACHE_RETRY_ATTEMPTS", 5)) 67"""Number of retries on SQLite lock contention.""" 68CACHE_RETRY_DELAY = float(_getenv( 69 "PUMPWOOD_COMMUNICATION__CACHE_RETRY_DELAY", 70 "PUMPWOOD_COMUNICATION__CACHE_RETRY_DELAY", 0.05)) 71"""Base delay in seconds between cache lock retries.""" 72 73 74# Parallel operations associated env. variables 75N_PARALLEL = n_parallel = PUMPWOOD_COMUNICATION__N_PARALLEL 76"""Number of parallel calls performed in parallel helpers.""" 77 78PARALLEL_CHUNK_SIZE = int(_getenv( 79 "PUMPWOOD_COMMUNICATION__PARALLEL_CHUNK_SIZE", 80 "PUMPWOOD_COMUNICATION__PARALLEL_CHUNK_SIZE", 10000)) 81"""Size of each chunk posted in parallel bulk save.""" 82 83 84# Microservice base associated env. variables 85DEFAULT_TIMEOUT = int(_getenv( 86 "PUMPWOOD_COMMUNICATION__DEFAULT_TIMEOUT", 87 "PUMPWOOD_COMUNICATION__DEFAULT_TIMEOUT", 60)) 88"""Default HTTP request timeout in seconds.""" 89DEBUG = _getenv( 90 "PUMPWOOD_COMMUNICATION__DEBUG", 91 "PUMPWOOD_COMUNICATION__DEBUG", "FALSE") == "TRUE" 92"""Whether debug mode is enabled. Options ``TRUE`` or ``FALSE``.""" 93VERIFY_SSL = _getenv( 94 "PUMPWOOD_COMMUNICATION__VERIFY_SSL", 95 "PUMPWOOD_COMUNICATION__VERIFY_SSL", "TRUE") == "TRUE" 96"""Whether HTTP requests validate the SSL certificate.""" 97 98 99# Encryption associated env. variables 100CRYPTO_FERNET_KEY = _getenv( 101 "PUMPWOOD_COMMUNICATION__CRYPTO_FERNET_KEY", 102 "PUMPWOOD_COMUNICATION__CRYPTO_FERNET_KEY", None) 103"""Fernet key used to encrypt and decrypt data."""
Number of parallel requests in parallel helper functions.
Cache timeout for authorization and row permission cache.
Base path for cache files.
Maximum disk cache size in bytes.
Default cache entry expiration time in seconds.
Default cache transaction timeout in seconds.
Number of shards used to split the cache.
Whether cache is enabled. Options TRUE or FALSE.
Number of retries on SQLite lock contention.
Base delay in seconds between cache lock retries.
Size of each chunk posted in parallel bulk save.
Default HTTP request timeout in seconds.
Whether debug mode is enabled. Options TRUE or FALSE.
Whether HTTP requests validate the SSL certificate.
Fernet key used to encrypt and decrypt data.