feat(shoutrrr): allow setting URLs from file

This commit is contained in:
p1ksel 2020-06-10 22:09:01 +02:00
parent 12d323354f
commit 624e2a744a

View file

@ -1,6 +1,7 @@
package flags
import (
"bytes"
"io/ioutil"
"os"
"strings"
@ -380,6 +381,7 @@ func GetSecretsFromFiles(rootCmd *cobra.Command) {
"notification-slack-hook-url",
"notification-msteams-hook",
"notification-gotify-token",
"notification-url",
}
for _, secret := range secrets {
getSecretFromFile(flags, secret)
@ -397,11 +399,25 @@ func getSecretFromFile(flags *pflag.FlagSet, secret string) {
if err != nil {
log.Fatal(err)
}
flag := flags.Lookup(secret)
if flag.Value.Type() == "stringArray" {
rows := bytes.Split(file, []byte{'\n'})
for _, row := range rows {
err = flags.Set(secret, strings.TrimSpace(string(row)))
if err != nil {
log.Error(err)
}
}
} else {
err = flags.Set(secret, strings.TrimSpace(string(file)))
if err != nil {
log.Error(err)
}
}
}
}
func isFile(s string) bool {