Skip to content

Commit

Permalink
fix: revert ENV expansion in the config file
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Chodur <[email protected]>
  • Loading branch information
FUSAKLA committed Oct 31, 2024
1 parent 606441b commit c20d2b5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Added: New validation `expressionDoesNotUseClassicHistogramBucketOperations` to avoid queries fragile because of the classic histogram bucket operations.
See the docs for more info [expressionDoesNotUseClassicHistogramBucketOperations](docs/validations.md#expressiondoesnotuseclassichistogrambucketoperations)
- Changed: :warning: revert the ENV expansion in config file since it was breaking and caused issues (it was a stupid idea)

## [3.4.0] - 2024-10-30
- Fixed: :warning: Ignore white spaces around rule names in the `disabled_validation_rules` annotation CSV format (Thanks @jmichalek13 !)
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ For a complete list of supported validations see the [docs/validations.md](docs/

If you want to see example configuration see the [`examples/validation.yaml`](examples/validation.yaml).

#### ENV expansion
You can use ENV variable expansion in the configuration file. Just use the `$ENV` or `${ENV_VAR}` syntax and it will be replaced with the value of the `ENV_VAR` environment variable.

### How to run it

If you downloaded the [prebuilt binary](https://github.com/FUSAKLA/promruval/releases/latest) or built it on your own:
Expand Down
7 changes: 3 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -49,18 +48,18 @@ type Loader struct {
}

func (l *Loader) Load() (*Config, error) {
configFileData, err := os.ReadFile(l.ConfigPath)
configFile, err := os.Open(l.ConfigPath)
if err != nil {
return nil, fmt.Errorf("open config file: %w", err)
}
defer configFile.Close()
configDirMtx.Lock()
configDir = path.Dir(l.ConfigPath)
defer func() {
configDirMtx.Unlock()
}()
validationConfig := Config{}
expandedConfigFileData := os.ExpandEnv(string(configFileData))
decoder := yaml.NewDecoder(strings.NewReader(expandedConfigFileData))
decoder := yaml.NewDecoder(configFile)
decoder.KnownFields(true)
if err := decoder.Decode(&validationConfig); err != nil {
return nil, fmt.Errorf("loading config file: %w", err)
Expand Down

0 comments on commit c20d2b5

Please sign in to comment.