Support reading nkey from file
This commit is contained in:
parent
6ac9b1bb3a
commit
bfcf518fe0
16
main.go
16
main.go
@ -8,6 +8,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.t-juice.club/torjus/natstonotify/bus"
|
"git.t-juice.club/torjus/natstonotify/bus"
|
||||||
"git.t-juice.club/torjus/natstonotify/server"
|
"git.t-juice.club/torjus/natstonotify/server"
|
||||||
@ -16,7 +17,7 @@ import (
|
|||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Version = "v0.1.0"
|
const Version = "v0.1.1"
|
||||||
|
|
||||||
func connectNats() (*nats.Conn, error) {
|
func connectNats() (*nats.Conn, error) {
|
||||||
natsURL, ok := os.LookupEnv("NATS_URL")
|
natsURL, ok := os.LookupEnv("NATS_URL")
|
||||||
@ -25,9 +26,20 @@ func connectNats() (*nats.Conn, error) {
|
|||||||
}
|
}
|
||||||
nkey, ok := os.LookupEnv("NATS_NKEY")
|
nkey, ok := os.LookupEnv("NATS_NKEY")
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("NATS_NKEY not set")
|
path, ok := os.LookupEnv("NATS_NKEY_FILE")
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("NATS_NKEY and NATS_NKEY_FILE not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to read NATS_NKEY_FILE: %w", err)
|
||||||
|
}
|
||||||
|
nkey = strings.TrimSpace(string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Connecting to NATS at %s with nkey %s\n", natsURL, nkey)
|
||||||
|
|
||||||
kp, err := nkeys.FromSeed([]byte(nkey))
|
kp, err := nkeys.FromSeed([]byte(nkey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user