Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for .yaml.local in go bouncer #44

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io"
"os"
"time"

Expand Down Expand Up @@ -42,20 +43,29 @@ type bouncerConfig struct {
PrometheusConfig PrometheusConfig `yaml:"prometheus"`
}

func NewConfig(configPath string) (*bouncerConfig, error) {
// mergedConfig() returns the byte content of the patched configuration file (with .yaml.local).
func mergedConfig(configPath string) ([]byte, error) {
patcher := yamlpatch.NewPatcher(configPath, ".local")
data, err := patcher.MergedPatchContent()
if err != nil {
return nil, err
}
return data, nil
}

func newConfig(reader io.Reader) (*bouncerConfig, error) {
var LogOutput *lumberjack.Logger //io.Writer

config := &bouncerConfig{}

patcher := yamlpatch.NewPatcher(configPath, ".local")
fcontent, err := patcher.MergedPatchContent()
fcontent, err := io.ReadAll(reader)
if err != nil {
return &bouncerConfig{}, err
}

err = yaml.Unmarshal(fcontent, &config)
if err != nil {
return &bouncerConfig{}, fmt.Errorf("failed to unmarshal %s : %v", configPath, err)
return &bouncerConfig{}, fmt.Errorf("failed to unmarshal: %w", err)
}

if config.BinPath == "" {
Expand Down
3 changes: 1 addition & 2 deletions custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -33,7 +32,7 @@ type parsedLine struct {
}

func parseFile(path string) []parsedLine {
dat, err := ioutil.ReadFile(binaryOutputFile)
dat, err := os.ReadFile(binaryOutputFile)
parsedLines := make([]parsedLine, 0)
if err != nil {
panic(err)
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
Expand Down Expand Up @@ -87,7 +88,12 @@ func main() {
},
})

config, err := NewConfig(*configPath)
configBytes, err := mergedConfig(*configPath)
if err != nil {
log.Fatalf("unable to read config file: %s", err)
}

config, err := newConfig(bytes.NewReader(configBytes))
if err != nil {
log.Fatalf("unable to load configuration: %s", err)
}
Expand Down