feat(vault-tui): implement KV client and service for managing secrets
- Added internal/vault/client.go for creating a Vault client with configuration settings. - Introduced internal/vault/errors.go to classify Vault API errors for better UI handling. - Created internal/vault/kv.go to manage KV secrets, including listing, reading, writing, and deleting operations. - Implemented internal/vault/mounts.go to list and describe secret engine mounts. - Developed internal/vault/service.go to provide a unified entry point for Vault operations. - Added internal/vault/kv_test.go for comprehensive testing of KV operations. - Introduced internal/ui/toast.go for transient notifications in the UI. - Added renovate.json for dependency management and updates.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// printJSON is the shared -format=json path for every headless command.
|
||||
func printJSON(w io.Writer, v interface{}) error {
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(v)
|
||||
}
|
||||
|
||||
// printKV renders a map as an aligned "key value" table, sorted by key.
|
||||
// Used by `status` and `read` in their default (non-JSON) output.
|
||||
func printKV(w io.Writer, m map[string]string) {
|
||||
keys := make([]string, 0, len(m))
|
||||
width := 0
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
if len(k) > width {
|
||||
width = len(k)
|
||||
}
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
fmt.Fprintf(w, "%-*s %s\n", width, k, m[k])
|
||||
}
|
||||
}
|
||||
|
||||
// parseKVArgs turns ["key=value", "other=1"] positional args into a map,
|
||||
// used by `write` and as auth method params on `login`.
|
||||
func parseKVArgs(args []string) (map[string]string, error) {
|
||||
out := map[string]string{}
|
||||
for _, a := range args {
|
||||
k, v, ok := strings.Cut(a, "=")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected key=value, got %q", a)
|
||||
}
|
||||
out[k] = v
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user