Merge branch 'master' of https://github.com/AlexxIT/go2rtc into secrets-file

This commit is contained in:
seydx
2025-09-26 15:15:59 +02:00
19 changed files with 249 additions and 79 deletions
+14
View File
@@ -118,3 +118,17 @@ func TestName(t *testing.T) {
// stage3
_ = prod2.Stop()
}
func TestStripUserinfo(t *testing.T) {
s := `streams:
test:
- ffmpeg:rtsp://username:password@10.1.2.3:554/stream1
- ffmpeg:rtsp://10.1.2.3:554/stream1@#video=copy
`
s = StripUserinfo(s)
require.Equal(t, `streams:
test:
- ffmpeg:rtsp://***@10.1.2.3:554/stream1
- ffmpeg:rtsp://10.1.2.3:554/stream1@#video=copy
`, s)
}
+12
View File
@@ -2,6 +2,7 @@ package core
import (
"crypto/rand"
"regexp"
"runtime"
"strconv"
"strings"
@@ -80,6 +81,17 @@ func Caller() string {
return file + ":" + strconv.Itoa(line)
}
const (
unreserved = `A-Za-z0-9-._~`
subdelims = `!$&'()*+,;=`
userinfo = unreserved + subdelims + `%:`
)
func StripUserinfo(s string) string {
sanitizer := regexp.MustCompile(`://[` + userinfo + `]+@`)
return sanitizer.ReplaceAllString(s, `://***@`)
}
func NewSecret(name string, defaultValues interface{}) (*app.Secret, error) {
return app.NewSecret(name, defaultValues)
}