-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
As identified in PR #32 review, magic numbers and constants like TOKEN_EXPIRY_BUFFER = 60 could be made configurable to allow users to adjust behavior for their specific needs.
Current Constants to Make Configurable
OAuth2 Module
TOKEN_EXPIRY_BUFFER = 60- seconds before token expiry to refreshSTATE_LENGTH = 32- length of CSRF state parameterDEFAULT_TIMEOUT = 30- HTTP request timeoutCALLBACK_PORT = 8765- default OAuth2 callback port
Client Module
DEFAULT_RETRY_COUNT = 3- number of retries for failed requestsDEFAULT_RETRY_DELAY = 1.0- delay between retriesCONNECTION_POOL_SIZE = 10- HTTP connection pool size
Proposed Configuration System
1. Environment Variables
import os
TOKEN_EXPIRY_BUFFER = int(os.getenv('ESOLOGS_TOKEN_EXPIRY_BUFFER', '60'))
DEFAULT_TIMEOUT = float(os.getenv('ESOLOGS_DEFAULT_TIMEOUT', '30'))2. Configuration Class
from dataclasses import dataclass
from typing import Optional
@dataclass
class ESOLogsConfig:
token_expiry_buffer: int = 60
state_length: int = 32
default_timeout: float = 30.0
callback_port: int = 8765
retry_count: int = 3
retry_delay: float = 1.0
connection_pool_size: int = 10
@classmethod
def from_env(cls) -> 'ESOLogsConfig':
'''Load configuration from environment variables'''
# Implementation
@classmethod
def from_file(cls, path: str) -> 'ESOLogsConfig':
'''Load configuration from JSON/YAML file'''
# Implementation
# Global config instance
config = ESOLogsConfig.from_env()3. Usage Pattern
from esologs.config import config
# Use in code
if token.expires_in <= config.token_expiry_buffer:
# Refresh tokenBenefits
- Users can tune behavior for their environment
- Easier testing with different configurations
- Better documentation of tunable parameters
- Follows 12-factor app principles
Implementation Notes
- Maintain backward compatibility
- Document all configuration options
- Validate configuration values
- Consider using pydantic for validation
References
- PR Release v0.2.0b1 - First Beta Release #32 review feedback
- 12-factor app configuration principles
Metadata
Metadata
Assignees
Labels
No labels