pretty secrets

This commit is contained in:
2026-01-13 14:08:45 +00:00
parent 7e1baaa2f1
commit 03033a0f53

40
main.go
View File

@@ -5,6 +5,7 @@ import (
"bufio"
"bytes"
"crypto/sha1"
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
@@ -598,6 +599,7 @@ const (
remoteWindowSize = 10
remoteIndent = " "
remoteLineColor = "\033[96m"
headerColor = "\033[95m"
localTimeColor = "\033[92m"
remoteColorReset = "\033[0m"
)
@@ -841,23 +843,47 @@ func runSecretsList(ctx *deploymentContext) error {
return err
}
var keys []string
type secretRow struct {
key string
digest string
}
var rows []secretRow
for _, line := range lines {
if key, _, ok := parseEnvLine(line); ok {
keys = append(keys, key)
if key, value, ok := parseEnvLine(line); ok {
rows = append(rows, secretRow{
key: key,
digest: secretDigest(value),
})
}
}
if len(keys) == 0 {
if len(rows) == 0 {
fmt.Println("no secrets found")
return nil
}
sort.Strings(keys)
for _, key := range keys {
fmt.Println(key)
sort.Slice(rows, func(i, j int) bool {
return rows[i].key < rows[j].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
}
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 {
key string
value string