do not hardcode influx token

This commit is contained in:
Joerg Lehmann 2021-03-31 20:01:32 +02:00
parent 867ae88bd3
commit 6edda45abf
1 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -32,6 +33,9 @@ type OneMetric struct {
DaysUntilDeactivated int // berechneter Wert DaysUntilDeactivated int // berechneter Wert
} }
// global variables
var INFLUX_RO_TOKEN = os.Getenv("INFLUX_RO_TOKEN")
// metrics handler // metrics handler
func string2float64(s string) float64 { func string2float64(s string) float64 {
@ -117,7 +121,7 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) {
} }
// Set headers // Set headers
req.Header.Set("Authorization", "Token TQvQxxLLAj1kTKWuEqcx7BA-KfE6WtJUeDlPa_Dnvms6Zqf6uh6lMbpXtzcsCjKO_x3PrpxxGDR5E6YnDB5PFg==") req.Header.Set("Authorization", "Token "+INFLUX_RO_TOKEN)
req.Header.Set("accept", "application/csv") req.Header.Set("accept", "application/csv")
req.Header.Set("content-type", "application/vnd.flux") req.Header.Set("content-type", "application/vnd.flux")
@ -275,7 +279,7 @@ func getLastMetrics(deveui string) OneMetric {
} }
// Set headers // Set headers
req.Header.Set("Authorization", "Token TQvQxxLLAj1kTKWuEqcx7BA-KfE6WtJUeDlPa_Dnvms6Zqf6uh6lMbpXtzcsCjKO_x3PrpxxGDR5E6YnDB5PFg==") req.Header.Set("Authorization", "Token "+INFLUX_RO_TOKEN)
req.Header.Set("accept", "application/csv") req.Header.Set("accept", "application/csv")
req.Header.Set("content-type", "application/vnd.flux") req.Header.Set("content-type", "application/vnd.flux")