FileContent: tolerant base64 reader

This commit is contained in:
Mikaël Cluseau
2026-02-10 15:14:01 +01:00
parent 56f78e083a
commit 4d5661fa8e
2 changed files with 13 additions and 2 deletions

10
base64/base64.go Normal file
View File

@ -0,0 +1,10 @@
package base64
import (
"encoding/base64"
"strings"
)
func Decode(s string) ([]byte, error) {
return base64.RawStdEncoding.DecodeString(strings.TrimRight(s, "="))
}

View File

@ -1,7 +1,6 @@
package config package config
import ( import (
"encoding/base64"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -9,6 +8,8 @@ import (
"time" "time"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
"novit.tech/direktil/pkg/base64"
) )
// Load a config from a file. // Load a config from a file.
@ -161,7 +162,7 @@ func (c *Config) FileContent(filePath string) []byte {
for _, f := range c.Files { for _, f := range c.Files {
if f.Path == filePath { if f.Path == filePath {
if f.Content64 != "" { if f.Content64 != "" {
decoded, err := base64.StdEncoding.DecodeString(f.Content64) decoded, err := base64.Decode(f.Content64)
if err != nil { if err != nil {
panic(fmt.Errorf("invalid base64 content in file %s", f.Path)) panic(fmt.Errorf("invalid base64 content in file %s", f.Path))
} }