- refactor secrets

- add support for env in config
- redact sensitive information in logs/responses
This commit is contained in:
seydx
2025-05-26 21:56:45 +02:00
parent e8e798d955
commit bf45f64a7e
14 changed files with 202 additions and 160 deletions
+3 -1
View File
@@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"strings"
"github.com/AlexxIT/go2rtc/pkg/shell"
)
func AppendDOT(dot []byte, stream *Stream) []byte {
@@ -166,7 +168,7 @@ func (c *conn) label() string {
sb.WriteString("\nsource=" + c.Source)
}
if c.URL != "" {
sb.WriteString("\nurl=" + c.URL)
sb.WriteString("\nurl=" + shell.Redact(c.URL))
}
if c.UserAgent != "" {
sb.WriteString("\nuser_agent=" + c.UserAgent)
-13
View File
@@ -4,7 +4,6 @@ import (
"errors"
"strings"
"github.com/AlexxIT/go2rtc/internal/app"
"github.com/AlexxIT/go2rtc/pkg/core"
)
@@ -47,18 +46,6 @@ func GetProducer(url string) (core.Producer, error) {
}
if handler, ok := handlers[scheme]; ok {
index := strings.IndexByte(url, '#')
if index > 0 {
_, query := url[:index], ParseQuery(url[index+1:])
secretsName := query.Get("secrets")
if secretsName != "" {
secrets := app.GetSecret(secretsName)
if secrets != nil {
url = secrets.Parse(url)
}
}
}
return handler(url)
}
}
+6 -5
View File
@@ -8,6 +8,7 @@ import (
"time"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/shell"
)
type state byte
@@ -149,7 +150,7 @@ func (p *Producer) start() {
return
}
log.Debug().Msgf("[streams] start producer url=%s", p.url)
log.Debug().Msgf("[streams] start producer url=%s", shell.Redact(p.url))
p.state = stateStart
p.workerID++
@@ -167,7 +168,7 @@ func (p *Producer) worker(conn core.Producer, workerID int) {
return
}
log.Warn().Err(err).Str("url", p.url).Caller().Send()
log.Warn().Err(err).Str("url", shell.Redact(p.url)).Caller().Send()
}
p.reconnect(workerID, 0)
@@ -178,11 +179,11 @@ func (p *Producer) reconnect(workerID, retry int) {
defer p.mu.Unlock()
if p.workerID != workerID {
log.Trace().Msgf("[streams] stop reconnect url=%s", p.url)
log.Trace().Msgf("[streams] stop reconnect url=%s", shell.Redact(p.url))
return
}
log.Debug().Msgf("[streams] retry=%d to url=%s", retry, p.url)
log.Debug().Msgf("[streams] retry=%d to url=%s", retry, shell.Redact(p.url))
conn, err := GetProducer(p.url)
if err != nil {
@@ -257,7 +258,7 @@ func (p *Producer) stop() {
p.workerID++
}
log.Debug().Msgf("[streams] stop producer url=%s", p.url)
log.Debug().Msgf("[streams] stop producer url=%s", shell.Redact(p.url))
if p.conn != nil {
_ = p.conn.Stop()
+2 -1
View File
@@ -9,6 +9,7 @@ import (
"github.com/AlexxIT/go2rtc/internal/api"
"github.com/AlexxIT/go2rtc/internal/app"
"github.com/AlexxIT/go2rtc/pkg/shell"
"github.com/rs/zerolog"
)
@@ -127,7 +128,7 @@ func GetOrPatch(query url.Values) *Stream {
// check if name param provided
if name := query.Get("name"); name != "" {
log.Info().Msgf("[streams] create new stream url=%s", source)
log.Info().Msgf("[streams] create new stream url=%s", shell.Redact(source))
return Patch(name, source)
}