pretty secrets
This commit is contained in:
40
main.go
40
main.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -598,6 +599,7 @@ const (
|
|||||||
remoteWindowSize = 10
|
remoteWindowSize = 10
|
||||||
remoteIndent = " "
|
remoteIndent = " "
|
||||||
remoteLineColor = "\033[96m"
|
remoteLineColor = "\033[96m"
|
||||||
|
headerColor = "\033[95m"
|
||||||
localTimeColor = "\033[92m"
|
localTimeColor = "\033[92m"
|
||||||
remoteColorReset = "\033[0m"
|
remoteColorReset = "\033[0m"
|
||||||
)
|
)
|
||||||
@@ -841,23 +843,47 @@ func runSecretsList(ctx *deploymentContext) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys []string
|
type secretRow struct {
|
||||||
|
key string
|
||||||
|
digest string
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []secretRow
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if key, _, ok := parseEnvLine(line); ok {
|
if key, value, ok := parseEnvLine(line); ok {
|
||||||
keys = append(keys, key)
|
rows = append(rows, secretRow{
|
||||||
|
key: key,
|
||||||
|
digest: secretDigest(value),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(keys) == 0 {
|
if len(rows) == 0 {
|
||||||
fmt.Println("no secrets found")
|
fmt.Println("no secrets found")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
sort.Strings(keys)
|
sort.Slice(rows, func(i, j int) bool {
|
||||||
for _, key := range keys {
|
return rows[i].key < rows[j].key
|
||||||
fmt.Println(key)
|
})
|
||||||
|
nameWidth := len("NAME")
|
||||||
|
for _, row := range rows {
|
||||||
|
if lw := len(row.key); lw > nameWidth {
|
||||||
|
nameWidth = lw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("%s%-*s %s%s\n", headerColor, nameWidth, "NAME", "DIGEST", remoteColorReset)
|
||||||
|
for _, row := range rows {
|
||||||
|
fmt.Printf("%-*s %s\n", nameWidth, row.key, row.digest)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func secretDigest(value string) string {
|
||||||
|
sum := sha256.Sum256([]byte(value))
|
||||||
|
// Return only a prefix so the table stays narrow but still reveals changes.
|
||||||
|
const shortBytes = 6
|
||||||
|
return fmt.Sprintf("%x", sum[:shortBytes])
|
||||||
|
}
|
||||||
|
|
||||||
type envAssignment struct {
|
type envAssignment struct {
|
||||||
key string
|
key string
|
||||||
value string
|
value string
|
||||||
|
|||||||
Reference in New Issue
Block a user