- 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.
85 lines
2.0 KiB
Go
85 lines
2.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
|
|
"git.morlana.online/f.weber/vault-tui/internal/config"
|
|
)
|
|
|
|
func configCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "config",
|
|
Usage: "manage the vault-tui config file",
|
|
Commands: []*cli.Command{
|
|
{
|
|
Name: "init",
|
|
Usage: "interactively create a new config file",
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
a, err := appFrom(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if config.Exists(a.ConfigPath) && !askOverwrite(a.ConfigPath) {
|
|
return nil
|
|
}
|
|
if !IsInteractive() {
|
|
return fmt.Errorf("config init requires an interactive terminal")
|
|
}
|
|
_, err = runWizard(a.ConfigPath)
|
|
return err
|
|
},
|
|
},
|
|
{
|
|
Name: "path",
|
|
Usage: "print the resolved config file path",
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
a, err := appFrom(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(a.ConfigPath)
|
|
return nil
|
|
},
|
|
},
|
|
{
|
|
Name: "show",
|
|
Usage: "print the fully resolved settings for the active profile",
|
|
Flags: []cli.Flag{&cli.BoolFlag{Name: "json"}},
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
a, err := appFrom(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if cmd.Bool("json") {
|
|
return printJSON(os.Stdout, a.Settings)
|
|
}
|
|
s := a.Settings
|
|
out := map[string]string{
|
|
"profile": s.Profile,
|
|
"address": s.Address,
|
|
"namespace": s.Namespace,
|
|
"read_only": fmt.Sprint(s.ReadOnly),
|
|
"auth.method": s.Auth.Method,
|
|
"auth.mount": s.Auth.Mount,
|
|
"tls.ca_cert": s.CACert,
|
|
"tls.skip_verify": fmt.Sprint(s.SkipVerify),
|
|
}
|
|
printKV(os.Stdout, out)
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func askOverwrite(path string) bool {
|
|
fmt.Fprintf(os.Stderr, "%s already exists. Overwrite? (y/N): ", path)
|
|
var resp string
|
|
fmt.Fscanln(os.Stdin, &resp)
|
|
return resp == "y" || resp == "yes"
|
|
}
|