Add secret loading from path.
parent
b7ac7d04cc
commit
a91fb7911c
|
@ -24,6 +24,8 @@ Here's a few useful flags:
|
||||||
- `--db_path`: Path to the SQLite database. The default is `switchifier.db` in the current working directory.
|
- `--db_path`: Path to the SQLite database. The default is `switchifier.db` in the current working directory.
|
||||||
- `--bind_address`: Host/port to bind to. By default `:8080`, so port 8080 on all interfaces.
|
- `--bind_address`: Host/port to bind to. By default `:8080`, so port 8080 on all interfaces.
|
||||||
- `--secret`: The preshared secret used to authenticate the client.
|
- `--secret`: The preshared secret used to authenticate the client.
|
||||||
|
- `--secret_path`: A file to load the preshared secret from (`--secret` is ignored).
|
||||||
|
- `--logtostderr`: Log program output to stderr.
|
||||||
|
|
||||||
|
|
||||||
Future work
|
Future work
|
||||||
|
|
16
main.go
16
main.go
|
@ -29,7 +29,9 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -190,16 +192,30 @@ var (
|
||||||
dbPath string
|
dbPath string
|
||||||
bindAddress string
|
bindAddress string
|
||||||
secret string
|
secret string
|
||||||
|
secret_path string
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.StringVar(&dbPath, "db_path", "./switchifier.db", "Path to the SQlite3 database.")
|
flag.StringVar(&dbPath, "db_path", "./switchifier.db", "Path to the SQlite3 database.")
|
||||||
flag.StringVar(&bindAddress, "bind_address", ":8080", "Address to bind HTTP server to.")
|
flag.StringVar(&bindAddress, "bind_address", ":8080", "Address to bind HTTP server to.")
|
||||||
flag.StringVar(&secret, "secret", "changeme", "Secret for state updates.")
|
flag.StringVar(&secret, "secret", "changeme", "Secret for state updates.")
|
||||||
|
flag.StringVar(&secret_path, "secret_path", "", "File with secret for state updates.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if dbPath == "" {
|
if dbPath == "" {
|
||||||
glog.Exit("Please provide a database path.")
|
glog.Exit("Please provide a database path.")
|
||||||
}
|
}
|
||||||
|
if secret_path != "" {
|
||||||
|
file, err := os.Open(secret_path)
|
||||||
|
if err != nil {
|
||||||
|
glog.Exit(err)
|
||||||
|
}
|
||||||
|
secretData, err := ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
glog.Exit(err)
|
||||||
|
}
|
||||||
|
secretParts := strings.Split(string(secretData), "\n")
|
||||||
|
secret = secretParts[0]
|
||||||
|
}
|
||||||
glog.Infof("Starting switchifier...")
|
glog.Infof("Starting switchifier...")
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", dbPath)
|
db, err := sql.Open("sqlite3", dbPath)
|
||||||
|
|
Loading…
Reference in New Issue