remove parse
This commit is contained in:
@@ -2,8 +2,6 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/yaml"
|
"github.com/AlexxIT/go2rtc/pkg/yaml"
|
||||||
@@ -12,8 +10,6 @@ import (
|
|||||||
var secrets = make(map[string]*Secret)
|
var secrets = make(map[string]*Secret)
|
||||||
var secretsMu sync.Mutex
|
var secretsMu sync.Mutex
|
||||||
|
|
||||||
var templateRegex = regexp.MustCompile(`\{\{\s*([^\}]+)\s*\}\}`)
|
|
||||||
|
|
||||||
type Secrets interface {
|
type Secrets interface {
|
||||||
Get(key string) any
|
Get(key string) any
|
||||||
Set(key string, value any)
|
Set(key string, value any)
|
||||||
@@ -76,33 +72,6 @@ func (s *Secret) Set(key string, value any) {
|
|||||||
secrets[s.Name] = s
|
secrets[s.Name] = s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Secret) Parse(template string) string {
|
|
||||||
if !templateRegex.MatchString(template) {
|
|
||||||
return template
|
|
||||||
}
|
|
||||||
|
|
||||||
secretsMu.Lock()
|
|
||||||
defer secretsMu.Unlock()
|
|
||||||
|
|
||||||
if _, exists := secrets[s.Name]; !exists {
|
|
||||||
return template
|
|
||||||
}
|
|
||||||
|
|
||||||
result := templateRegex.ReplaceAllStringFunc(template, func(match string) string {
|
|
||||||
varName := strings.TrimSpace(templateRegex.FindStringSubmatch(match)[1])
|
|
||||||
pathParts := strings.Split(varName, ".")
|
|
||||||
value := getNestedValue(s.Values, pathParts)
|
|
||||||
|
|
||||||
if value != nil {
|
|
||||||
return stringify(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
})
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Secret) Marshal(v any) ([]byte, error) {
|
func (s *Secret) Marshal(v any) ([]byte, error) {
|
||||||
secretsMu.Lock()
|
secretsMu.Lock()
|
||||||
defer secretsMu.Unlock()
|
defer secretsMu.Unlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user