FileContent: tolerant base64 reader
This commit is contained in:
10
base64/base64.go
Normal file
10
base64/base64.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package base64
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Decode(s string) ([]byte, error) {
|
||||||
|
return base64.RawStdEncoding.DecodeString(strings.TrimRight(s, "="))
|
||||||
|
}
|
||||||
@ -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))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user