From a31d5c382f20d1185240994d67a5a86aad5c3fda Mon Sep 17 00:00:00 2001 From: Galorhallen Date: Wed, 5 Jan 2022 21:20:06 +0100 Subject: [PATCH 1/4] Removed print of token and password in Config.String --- config/configuration.go | 8 +++++++- go.mod | 16 ---------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/config/configuration.go b/config/configuration.go index 7c03318..7fa1438 100644 --- a/config/configuration.go +++ b/config/configuration.go @@ -78,7 +78,13 @@ func (c *Config) String() string { for i := 0; i < fields.NumField(); i++ { valueField := fields.Field(i) typeField := fields.Type().Field(i) - buffer[i] = fmt.Sprintf("%s=%v", typeField.Name, valueField.Interface()) + if typeField.Name != "PIHolePassword" && typeField.Name != "PIHoleApiToken" { + buffer[i] = fmt.Sprintf("%s=%v", typeField.Name, valueField.Interface()) + } else { + if valueField.Len() > 0 { + buffer[i] = fmt.Sprintf("%s=%s", typeField.Name, "*****") + } + } } return fmt.Sprintf("", &c, strings.Join(buffer, ", ")) diff --git a/go.mod b/go.mod index 990273e..90774d7 100644 --- a/go.mod +++ b/go.mod @@ -9,19 +9,3 @@ require ( github.com/xonvanetta/shutdown v0.0.3 golang.org/x/net v0.0.0-20200625001655-4c5254603344 ) - -require ( - github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.1.1 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.4.3 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/pkg/errors v0.9.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.2.0 // indirect - github.com/prometheus/common v0.26.0 // indirect - github.com/prometheus/procfs v0.6.0 // indirect - golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect - google.golang.org/protobuf v1.26.0-rc.1 // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect -) From 1d96b5c332c8abe3e49300ce57360c54813fe12a Mon Sep 17 00:00:00 2001 From: Galorhallen Date: Wed, 5 Jan 2022 21:25:14 +0100 Subject: [PATCH 2/4] Removed fmt used as log --- internal/pihole/client.go | 2 +- main.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/pihole/client.go b/internal/pihole/client.go index c46bd53..5bb97c6 100644 --- a/internal/pihole/client.go +++ b/internal/pihole/client.go @@ -31,7 +31,7 @@ func NewClient(config *config.Config) *Client { os.Exit(1) } - fmt.Printf("Creating client with config %s\n", config) + log.Printf("Creating client with config %s\n", config) return &Client{ config: config, diff --git a/main.go b/main.go index 8bee1a8..1adb3de 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "github.com/eko/pihole-exporter/config" @@ -41,7 +40,7 @@ func main() { case <-serverDead: } - fmt.Println("pihole-exporter HTTP server stopped") + log.Println("pihole-exporter HTTP server stopped") } func buildClients(clientConfigs []config.Config) []*pihole.Client { From 98f9693ec1d60792b797723677f6dacbe6efc006 Mon Sep 17 00:00:00 2001 From: Galorhallen Date: Fri, 7 Jan 2022 22:54:02 +0100 Subject: [PATCH 3/4] Fix go.mod --- config/configuration.go | 3 +-- go.mod | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config/configuration.go b/config/configuration.go index 7fa1438..bcfbe6c 100644 --- a/config/configuration.go +++ b/config/configuration.go @@ -80,8 +80,7 @@ func (c *Config) String() string { typeField := fields.Type().Field(i) if typeField.Name != "PIHolePassword" && typeField.Name != "PIHoleApiToken" { buffer[i] = fmt.Sprintf("%s=%v", typeField.Name, valueField.Interface()) - } else { - if valueField.Len() > 0 { + } else if valueField.Len() > 0 { buffer[i] = fmt.Sprintf("%s=%s", typeField.Name, "*****") } } diff --git a/go.mod b/go.mod index 90774d7..990273e 100644 --- a/go.mod +++ b/go.mod @@ -9,3 +9,19 @@ require ( github.com/xonvanetta/shutdown v0.0.3 golang.org/x/net v0.0.0-20200625001655-4c5254603344 ) + +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/protobuf v1.4.3 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/common v0.26.0 // indirect + github.com/prometheus/procfs v0.6.0 // indirect + golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect + google.golang.org/protobuf v1.26.0-rc.1 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) From 89284bf1c44ea908dff5741fe933f8f8d3c03551 Mon Sep 17 00:00:00 2001 From: Galorhallen Date: Fri, 7 Jan 2022 22:55:31 +0100 Subject: [PATCH 4/4] Fix wrong parenthesis --- config/configuration.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/configuration.go b/config/configuration.go index bcfbe6c..5f75dbd 100644 --- a/config/configuration.go +++ b/config/configuration.go @@ -81,8 +81,7 @@ func (c *Config) String() string { if typeField.Name != "PIHolePassword" && typeField.Name != "PIHoleApiToken" { buffer[i] = fmt.Sprintf("%s=%v", typeField.Name, valueField.Interface()) } else if valueField.Len() > 0 { - buffer[i] = fmt.Sprintf("%s=%s", typeField.Name, "*****") - } + buffer[i] = fmt.Sprintf("%s=%s", typeField.Name, "*****") } }