Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions socket_basics/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ def __init__(self, config_dict: Dict[str, Any] | None = None, json_config_path:
self._config = merge_json_and_env_config()

self._config = self._config
# DEBUG: Log final configuration values

# Log where the configuration is being loaded from
logger = logging.getLogger(__name__)
config_source = self._config.get('_config_source', 'environment')
source_descriptions = {
'api': 'Socket dashboard (API)',
'json_file': 'JSON config file (--config)',
'environment': 'environment variables',
}
source_desc = source_descriptions.get(config_source, config_source)
logger.info(f"Configuration loaded from: {source_desc}")

# DEBUG: Log final configuration values
logger.debug("Final Config object created with key values:")
logger.debug(f" javascript_sast_enabled: {self._config.get('javascript_sast_enabled')}")
logger.debug(f" socket_tier_1_enabled: {self._config.get('socket_tier_1_enabled')}")
Expand Down Expand Up @@ -992,21 +1002,23 @@ def normalize_api_config(api_config: Dict[str, Any]) -> Dict[str, Any]:

def merge_json_and_env_config(json_config: Dict[str, Any] | None = None) -> Dict[str, Any]:
"""Merge JSON configuration with environment variables

Priority order (highest to lowest):
1. CLI options (handled separately via argparse, highest priority)
2. Socket Basics API config / JSON config (dashboard settings)
3. Environment variables from action.yml (lowest priority - defaults)

Args:
json_config: Optional dictionary from JSON config file

Returns:
Merged configuration dictionary
"""
# Start with environment defaults (lowest priority)
config = load_config_from_env()

# Default source is environment variables
config['_config_source'] = 'environment'

# Override with Socket Basics API config if no explicit JSON config provided
# API config takes precedence over environment defaults
if not json_config:
Expand All @@ -1027,6 +1039,7 @@ def merge_json_and_env_config(json_config: Dict[str, Any] | None = None) -> Dict
continue
filtered_config[k] = v
config.update(filtered_config)
config['_config_source'] = 'api'
logging.getLogger(__name__).info("Loaded Socket Basics API configuration (overrides environment defaults)")
else:
logger.debug(" No Socket Basics API config loaded")
Expand All @@ -1045,6 +1058,7 @@ def merge_json_and_env_config(json_config: Dict[str, Any] | None = None) -> Dict
continue
filtered_json[k] = v
config.update(filtered_json)
config['_config_source'] = 'json_file'
logging.getLogger(__name__).info("Loaded JSON configuration (overrides environment defaults)")

# Note: CLI arguments are handled separately and take highest priority
Expand Down