2021-09-19 12:00:00 +00:00
|
|
|
// Copyright (c) 2019, Drone IO Inc.
|
|
|
|
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
|
2019-02-10 19:00:16 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
package pretty
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/drone/drone-yaml/yaml"
|
|
|
|
)
|
|
|
|
|
|
|
|
// helper function to pretty prints the signature resource.
|
|
|
|
func printSecret(w writer, v *yaml.Secret) {
|
2022-04-25 10:56:05 +00:00
|
|
|
_, _ = w.WriteString("---")
|
2019-01-22 23:44:17 +00:00
|
|
|
w.WriteTagValue("version", v.Version)
|
|
|
|
w.WriteTagValue("kind", v.Kind)
|
2019-03-18 02:25:35 +00:00
|
|
|
w.WriteTagValue("type", v.Type)
|
2019-01-22 23:44:17 +00:00
|
|
|
|
|
|
|
if len(v.Data) > 0 {
|
2019-02-22 03:08:33 +00:00
|
|
|
w.WriteTagValue("name", v.Name)
|
2019-01-22 23:44:17 +00:00
|
|
|
printData(w, v.Data)
|
|
|
|
}
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2021-09-19 12:00:00 +00:00
|
|
|
if !isSecretGetEmpty(v.Get) {
|
2019-02-22 03:08:33 +00:00
|
|
|
w.WriteTagValue("name", v.Name)
|
2022-04-25 10:56:05 +00:00
|
|
|
_ = w.WriteByte('\n')
|
2019-02-22 03:08:33 +00:00
|
|
|
printGet(w, v.Get)
|
|
|
|
}
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2022-04-25 10:56:05 +00:00
|
|
|
_ = w.WriteByte('\n')
|
|
|
|
_ = w.WriteByte('\n')
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 03:08:33 +00:00
|
|
|
// helper function prints the get block.
|
|
|
|
func printGet(w writer, v yaml.SecretGet) {
|
|
|
|
w.WriteTag("get")
|
|
|
|
w.IndentIncrease()
|
|
|
|
w.WriteTagValue("path", v.Path)
|
|
|
|
w.WriteTagValue("name", v.Name)
|
|
|
|
w.WriteTagValue("key", v.Key)
|
|
|
|
w.IndentDecrease()
|
|
|
|
}
|
|
|
|
|
2019-03-18 02:25:35 +00:00
|
|
|
func printData(w writer, d string) {
|
2023-02-08 09:14:20 +00:00
|
|
|
spaceReplacer := strings.NewReplacer(" ", "", "\n", "")
|
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
w.WriteTag("data")
|
2022-04-25 10:56:05 +00:00
|
|
|
_ = w.WriteByte(' ')
|
|
|
|
_ = w.WriteByte('>')
|
2019-01-22 23:44:17 +00:00
|
|
|
w.IndentIncrease()
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-03-18 02:25:35 +00:00
|
|
|
d = spaceReplacer.Replace(d)
|
2023-02-08 09:14:20 +00:00
|
|
|
//nolint:gomnd
|
2019-03-18 02:25:35 +00:00
|
|
|
for _, s := range chunk(d, 60) {
|
2022-04-25 10:56:05 +00:00
|
|
|
_ = w.WriteByte('\n')
|
2019-03-18 02:25:35 +00:00
|
|
|
w.Indent()
|
2022-04-25 10:56:05 +00:00
|
|
|
_, _ = w.WriteString(s)
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
w.IndentDecrease()
|
|
|
|
}
|
|
|
|
|
2019-02-22 03:08:33 +00:00
|
|
|
// helper function returns true if the secret get
|
|
|
|
// object is empty.
|
|
|
|
func isSecretGetEmpty(v yaml.SecretGet) bool {
|
|
|
|
return v.Key == "" &&
|
|
|
|
v.Name == "" &&
|
|
|
|
v.Path == ""
|
|
|
|
}
|