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

Influxdb: add insecure option #16025

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions api/globalconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Influx struct {
Org string `json:"org"`
User string `json:"user"`
Password string `json:"password"`
Insecure bool `json:"insecure"`
}

// Redacted implements the redactor interface used by the tee publisher
Expand All @@ -98,11 +99,13 @@ func (c Influx) Redacted() any {
Database string `json:"database"`
Org string `json:"org"`
User string `json:"user"`
Insecure bool `json:"insecure"`
}{
URL: c.URL,
Database: c.Database,
Org: c.Org,
User: c.User,
Insecure: c.Insecure,
}
}

Expand Down
13 changes: 13 additions & 0 deletions assets/js/components/Config/InfluxModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
autocomplete="off"
/>
</FormRow>
<FormRow id="influxInsecure" :label="$t('config.influx.labelInsecure')">
<div class="d-flex">
<input
class="form-check-input"
id="influxInsecure"
type="checkbox"
v-model="values.insecure"
/>
<label class="form-check-label ms-2" for="influxInsecure">
{{ $t("config.influx.labelCheckInsecure") }}
</label>
</div>
</FormRow>
<p>
<button
v-if="showV1(values)"
Expand Down
1 change: 1 addition & 0 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ func configureInflux(conf *globalconfig.Influx) (*server.Influx, error) {
conf.User,
conf.Password,
conf.Database,
conf.Insecure,
)

return influx, nil
Expand Down
2 changes: 2 additions & 0 deletions i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ title = "HEMS"
description = "Schreibt Ladedaten und andere Metriken in InfluxDB. Verwende Grafana oder andere Tools, um die Daten zu visualisieren."
descriptionToken = "Siehe die InfluxDB-Dokumentation, um zu erfahren, wie du einen erstellst. https://docs.influxdata.com/influxdb/v2/admin/"
labelBucket = "Bucket"
labelCheckInsecure = "Erlaube unsichere Verbindungen"
labelDatabase = "Datenbank"
labelInsecure = "Zertifikatüberprüfung"
labelOrg = "Organisation"
labelPassword = "Passwort"
labelToken = "API-Token"
Expand Down
2 changes: 2 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ title = "HEMS"
description = "Writes charging data and other metrics to InfluxDB. Use Grafana or other tools to visualize the data."
descriptionToken = "Check the InfluxDB documentation to learn how to create one. https://docs.influxdata.com/influxdb/v2/admin/"
labelBucket = "Bucket"
labelCheckInsecure = "Allow self-signed certificates"
labelDatabase = "Database"
labelInsecure = "Certificate validation"
labelOrg = "Organization"
labelPassword = "Password"
labelToken = "API Token"
Expand Down
10 changes: 8 additions & 2 deletions server/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ type Influx struct {
}

// NewInfluxClient creates new publisher for influx
func NewInfluxClient(url, token, org, user, password, database string) *Influx {
func NewInfluxClient(url, token, org, user, password, database string, insecure bool) *Influx {
log := util.NewLogger("influx")

// InfluxDB v1 compatibility
if token == "" && user != "" {
token = fmt.Sprintf("%s:%s", user, password)
}

options := influxdb2.DefaultOptions().SetPrecision(time.Second)
options := influxdb2.DefaultOptions()

tlsConfig := options.TLSConfig()
tlsConfig.InsecureSkipVerify = insecure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andig hier ist noch irgendetwas krumm. Wenn InfluxDB konfiguriert crasht die Anwendung hier:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0xa0 pc=0x106872ae0]

goroutine 1 [running]:
github.com/evcc-io/evcc/server.NewInfluxClient({0x14002686240, 0x21}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, ...)
	/Users/michael/lab/evcc/server/influxdb.go:41 +0x240
github.com/evcc-io/evcc/cmd.configureInflux(0x109faa4f0)
	/Users/michael/lab/evcc/cmd/setup.go:566 +0xe8
github.com/evcc-io/evcc/cmd.runRoot(0x109fa89a0, {0x1069e2590?, 0x7?, 0x1069d5565?})
	/Users/michael/lab/evcc/cmd/root.go:187 +0x954
github.com/spf13/cobra.(*Command).execute(0x109fa89a0, {0x1400018c190, 0x2, 0x2})
	/Users/michael/go/pkg/mod/github.com/spf13/[email protected]/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x109fa89a0)
	/Users/michael/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/michael/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041
github.com/evcc-io/evcc/cmd.Execute()
	/Users/michael/lab/evcc/cmd/root.go:107 +0x24
main.main()
	/Users/michael/lab/evcc/main.go:44 +0x38
exit status 2

options.SetTLSConfig(tlsConfig)
options.SetPrecision(time.Second)

client := influxdb2.NewClientWithOptions(url, token, options)

// handle error logging in writer
Expand Down