mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-27 04:36:12 +08:00
Merge pull request #1449 from amarshall/credentials-dir
Read from credential files
This commit is contained in:
@@ -19,15 +19,15 @@ go2rtc -c log.format=text -c /config/go2rtc.yaml -c rtsp.listen='' -c /usr/local
|
|||||||
|
|
||||||
## Environment variables
|
## Environment variables
|
||||||
|
|
||||||
Also go2rtc support templates for using environment variables in any part of config:
|
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.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
streams:
|
streams:
|
||||||
camera1: rtsp://rtsp:${CAMERA_PASSWORD}@192.168.1.123/av_stream/ch0
|
camera1: rtsp://rtsp:${CAMERA_PASSWORD}@192.168.1.123/av_stream/ch0
|
||||||
|
|
||||||
rtsp:
|
rtsp:
|
||||||
username: ${RTSP_USER:admin} # "admin" if env "RTSP_USER" not set
|
username: ${RTSP_USER:admin} # "admin" if "RTSP_USER" not set
|
||||||
password: ${RTSP_PASS:secret} # "secret" if env "RTSP_PASS" not set
|
password: ${RTSP_PASS:secret} # "secret" if "RTSP_PASS" not set
|
||||||
```
|
```
|
||||||
|
|
||||||
## JSON Schema
|
## JSON Schema
|
||||||
|
@@ -3,6 +3,7 @@ package shell
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -51,6 +52,13 @@ func ReplaceEnvVars(text string) string {
|
|||||||
dok = true
|
dok = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dir, vok := os.LookupEnv("CREDENTIALS_DIRECTORY"); vok {
|
||||||
|
value, err := os.ReadFile(filepath.Join(dir, key))
|
||||||
|
if err == nil {
|
||||||
|
return strings.TrimSpace(string(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if value, vok := os.LookupEnv(key); vok {
|
if value, vok := os.LookupEnv(key); vok {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user