Skip to content

Conversation

@rjocoleman
Copy link
Contributor

This PR introduces a slight refactor of the config file parsing and addresses a bug with TLS configuration parsing from config.json. It also replaces the fallback to config.sample.json with values defined directly in code.

  1. Refactor Configuration Handling:
  • Introduced a defaultConfig() function to define all default configuration values in one place.
  • Removed the fallback to config.sample.json to ensure defaults are always present and defined programmatically.
  1. TLS Configuration Parsing
  • Fixed an issue where tls_server_name and insecure_tls_skip_verify could only be set via environment variables due to these fields not being exported. As a result, they were not unmarshalled from config.json.
  • Updated clickhouseConfig to export tls_server_name and insecure_tls_skip_verify fields, enabling proper parsing from JSON configuration files.
  1. Improved Boolean Handling:
  • Fixed a bug in readEnvBool where invalid environment variable values could overwrite defaults without proper validation. Boolean values are now only updated if they are valid.
  1. Additional Tests:
  • Added config_test.go to validate:
    • Full coverage of existing behaviour.
    • Default configuration values (via defaultConfig rather than config.sample.json)
    • Environment variable overrides.
    • Correct parsing of config.json, including TLS settings that were previously not parsed.

This refactor is fully backward-compatible unless users were relying on the undocumented fallback behavior of config.sample.json. Such users will now need to either provide a valid config.json file or rely on the defined defaults.

…defaults in code

- Introduced a `defaultConfig()` function to define all default configuration values in a centralized and idiomatic way.
- Removed reliance on `config.sample.json` as a fallback, simplifying the configuration logic and reducing dependencies on external files.
- Adjusted TLS configuration handling to use centralized defaults and environment variable overrides consistently.
- Improved error handling for configuration loading and environment variable parsing.
- Added config tests (`config_test.go`) to validate default values, environment variable overrides, and configuration file structure.
… variables

- Exported `tlsServerName` and `tlsSkipVerify` fields in `clickhouseConfig` to allow configuration via `config.json`.
- Ensured environment variables can override `tlsServerName` and `tlsSkipVerify` values when set.
- Added `TestTLSConfig` to validate that TLS settings are correctly loaded from `config.json` and overridden by environment variables.
- Updated `defaultConfig` to include default values for TLS-related fields.
@nikepan nikepan merged commit 1e611f4 into nikepan:master Jan 21, 2025
@rjocoleman rjocoleman deleted the fix/tls-verify-config branch January 21, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants