Skip to content

Commit

Permalink
Merge pull request #11 from ChrisFromCnC/ChrisFromCnC-Add-secrets-fil…
Browse files Browse the repository at this point in the history
…e-support-for-docker

Add secrets file support for docker
  • Loading branch information
janfuhrer authored Apr 11, 2024
2 parents 30386fa + 0e49d40 commit 2f81382
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"crypto/tls"
"encoding/json"
"flag"
Expand Down Expand Up @@ -234,6 +235,24 @@ type Exporter struct {
authorizationHeader string
}

func ReadSecretFile(secretfilename string) string {
file, err := os.Open(secretfilename)
// flag to check the file format
if err != nil {
log.Fatal(err)
}
// Close the file
defer func() {
if err = file.Close(); err != nil {
log.Fatal(err)
}
}()
// Read the first line
line := bufio.NewScanner(file)
line.Scan()
return line.Text()
}

func NewExporter(endpoint string, username string, apitoken string, apitokenname string) *Exporter {
return &Exporter{
endpoint: endpoint,
Expand Down Expand Up @@ -660,12 +679,24 @@ func main() {
}
if os.Getenv("PBS_USERNAME") != "" {
*username = os.Getenv("PBS_USERNAME")
} else {
if os.Getenv("PBS_USERNAME_FILE") != "" {
*username = ReadSecretFile(os.Getenv("PBS_USERNAME_FILE"))
}
}
if os.Getenv("PBS_API_TOKEN_NAME") != "" {
*apitokenname = os.Getenv("PBS_API_TOKEN_NAME")
} else {
if os.Getenv("PBS_API_TOKEN_NAME_FILE") != "" {
*apitokenname = ReadSecretFile(os.Getenv("PBS_API_TOKEN_NAME_FILE"))
}
}
if os.Getenv("PBS_API_TOKEN") != "" {
*apitoken = os.Getenv("PBS_API_TOKEN")
} else {
if os.Getenv("PBS_API_TOKEN_FILE") != "" {
*apitoken = ReadSecretFile(os.Getenv("PBS_API_TOKEN_FILE"))
}
}
if os.Getenv("PBS_TIMEOUT") != "" {
*timeout = os.Getenv("PBS_TIMEOUT")
Expand Down

0 comments on commit 2f81382

Please sign in to comment.