Skip to content

Commit

Permalink
Merge pull request #1449 from amarshall/credentials-dir
Browse files Browse the repository at this point in the history
Read from credential files
  • Loading branch information
AlexxIT authored Nov 11, 2024
2 parents ad14a5c + 7640a42 commit 172437b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ go2rtc -c log.format=text -c /config/go2rtc.yaml -c rtsp.listen='' -c /usr/local

## 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
streams:
camera1: rtsp://rtsp:${CAMERA_PASSWORD}@192.168.1.123/av_stream/ch0

rtsp:
username: ${RTSP_USER:admin} # "admin" if env "RTSP_USER" not set
password: ${RTSP_PASS:secret} # "secret" if env "RTSP_PASS" not set
username: ${RTSP_USER:admin} # "admin" if "RTSP_USER" not set
password: ${RTSP_PASS:secret} # "secret" if "RTSP_PASS" not set
```
## JSON Schema
Expand Down
8 changes: 8 additions & 0 deletions pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package shell
import (
"os"
"os/signal"
"path/filepath"
"regexp"
"strings"
"syscall"
Expand Down Expand Up @@ -51,6 +52,13 @@ func ReplaceEnvVars(text string) string {
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 {
return value
}
Expand Down

0 comments on commit 172437b

Please sign in to comment.