Skip to content

Commit 172437b

Browse files
authored
Merge pull request #1449 from amarshall/credentials-dir
Read from credential files
2 parents ad14a5c + 7640a42 commit 172437b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/app/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ go2rtc -c log.format=text -c /config/go2rtc.yaml -c rtsp.listen='' -c /usr/local
1919

2020
## Environment variables
2121

22-
Also go2rtc support templates for using environment variables in any part of config:
22+
There is support for loading external variables into the config. First, they will be attempted to be loaded from [credential files](https://systemd.io/CREDENTIALS). If `CREDENTIALS_DIRECTORY` is not set, then the key will be loaded from an environment variable. If no environment variable is set, then the string will be left as-is.
2323

2424
```yaml
2525
streams:
2626
camera1: rtsp://rtsp:${CAMERA_PASSWORD}@192.168.1.123/av_stream/ch0
2727

2828
rtsp:
29-
username: ${RTSP_USER:admin} # "admin" if env "RTSP_USER" not set
30-
password: ${RTSP_PASS:secret} # "secret" if env "RTSP_PASS" not set
29+
username: ${RTSP_USER:admin} # "admin" if "RTSP_USER" not set
30+
password: ${RTSP_PASS:secret} # "secret" if "RTSP_PASS" not set
3131
```
3232
3333
## JSON Schema

pkg/shell/shell.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package shell
33
import (
44
"os"
55
"os/signal"
6+
"path/filepath"
67
"regexp"
78
"strings"
89
"syscall"
@@ -51,6 +52,13 @@ func ReplaceEnvVars(text string) string {
5152
dok = true
5253
}
5354

55+
if dir, vok := os.LookupEnv("CREDENTIALS_DIRECTORY"); vok {
56+
value, err := os.ReadFile(filepath.Join(dir, key))
57+
if err == nil {
58+
return strings.TrimSpace(string(value))
59+
}
60+
}
61+
5462
if value, vok := os.LookupEnv(key); vok {
5563
return value
5664
}

0 commit comments

Comments
 (0)