feat: vaults, scopes and files show their details: a vault's settings, who has a scope, a file's keys and git status
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9b0329e9da
commit
5381cf5d43
14 files changed
+474
-2
No files matched your search
@@ -815,8 +815,30 @@ func anyMatch(res []*regexp.Regexp, f string) bool {
|
||||
// --- sops files ---
|
||||
|
||||
type sopsMeta struct {
|
||||
methods []string // age, azure_kv, …
|
||||
modified time.Time
|
||||
methods []string // age, azure_kv, …
|
||||
recipients []string // "age age1…", "azure_kv https://kv…/keys/sops"
|
||||
modified time.Time
|
||||
}
|
||||
|
||||
// recipient names a key a file is encrypted for, from its sops metadata:
|
||||
// public, never a secret.
|
||||
func recipient(method string, f map[string]string) string {
|
||||
var v string
|
||||
switch method {
|
||||
case "age":
|
||||
v = f["recipient"]
|
||||
case "pgp":
|
||||
v = f["fp"]
|
||||
case "kms":
|
||||
v = f["arn"]
|
||||
case "gcp_kms":
|
||||
v = f["resource_id"]
|
||||
case "azure_kv":
|
||||
v = strings.TrimSuffix(f["vault_url"], "/") + "/keys/" + f["name"]
|
||||
case "hc_vault":
|
||||
v = strings.TrimSuffix(f["vault_address"], "/") + " " + f["engine_path"] + "/" + f["key_name"]
|
||||
}
|
||||
return method + " " + v
|
||||
}
|
||||
|
||||
const maxFileSize = 4 << 20
|
||||
@@ -848,6 +870,15 @@ func readMeta(file string) (sopsMeta, bool) {
|
||||
for _, k := range known {
|
||||
if v, ok := doc.Sops[k].([]any); ok && len(v) > 0 {
|
||||
m.methods = append(m.methods, k)
|
||||
for _, e := range v {
|
||||
fields := map[string]string{}
|
||||
if em, ok := e.(map[string]any); ok {
|
||||
for fk, fv := range em {
|
||||
fields[fk] = fmt.Sprint(fv)
|
||||
}
|
||||
}
|
||||
m.recipients = append(m.recipients, recipient(k, fields))
|
||||
}
|
||||
}
|
||||
}
|
||||
if s, ok := doc.Sops["lastmodified"].(string); ok {
|
||||
@@ -864,6 +895,7 @@ func readMeta(file string) (sopsMeta, bool) {
|
||||
for _, k := range known {
|
||||
if strings.Contains(text, "sops_"+k+"__") {
|
||||
m.methods = append(m.methods, k)
|
||||
m.recipients = append(m.recipients, envRecipients(text, k)...)
|
||||
}
|
||||
}
|
||||
if i := strings.Index(text, "sops_lastmodified"); i >= 0 {
|
||||
@@ -881,6 +913,35 @@ func readMeta(file string) (sopsMeta, bool) {
|
||||
return m, true
|
||||
}
|
||||
|
||||
// envRecipients are method's keys in a dotenv or ini sops file, whose
|
||||
// metadata is flattened: sops_age__list_0__map_recipient=age1….
|
||||
func envRecipients(text, method string) []string {
|
||||
prefix := "sops_" + method + "__list_"
|
||||
var order []string
|
||||
keys := map[string]map[string]string{}
|
||||
for line := range strings.Lines(text) {
|
||||
k, v, ok := strings.Cut(strings.TrimSpace(line), "=")
|
||||
rest, found := strings.CutPrefix(strings.TrimSpace(k), prefix)
|
||||
if !ok || !found {
|
||||
continue
|
||||
}
|
||||
n, field, ok := strings.Cut(rest, "__map_")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if keys[n] == nil {
|
||||
keys[n] = map[string]string{}
|
||||
order = append(order, n)
|
||||
}
|
||||
keys[n][field] = strings.TrimSpace(v)
|
||||
}
|
||||
out := make([]string, len(order))
|
||||
for i, n := range order {
|
||||
out[i] = recipient(method, keys[n])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func formatOf(file string) string {
|
||||
switch strings.ToLower(filepath.Ext(file)) {
|
||||
case ".yaml", ".yml":
|
||||
|
||||
Reference in new issue
Block a user