- 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.
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
func statusCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "status",
|
|
Usage: "show the resolved profile, address, and token status",
|
|
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
|
|
}
|
|
s := a.Settings
|
|
out := map[string]string{
|
|
"profile": s.Profile,
|
|
"address": fmt.Sprintf("%s (%s)", s.Address, s.OriginOf("address").Key),
|
|
"namespace": valueOr(s.Namespace, "(none)"),
|
|
"read_only": fmt.Sprint(s.ReadOnly),
|
|
"auth_method": valueOr(s.Auth.Method, "(unset)"),
|
|
"token_store": fmt.Sprintf("%s (%s)", a.Store.Kind(), a.Store.Location()),
|
|
}
|
|
|
|
info, err := a.EnsureLoggedIn(ctx, cmd.String("token"))
|
|
if err != nil {
|
|
out["token"] = fmt.Sprintf("none/invalid: %v", err)
|
|
if cmd.Bool("json") {
|
|
return printJSON(os.Stdout, out)
|
|
}
|
|
printKV(os.Stdout, out)
|
|
return nil
|
|
}
|
|
out["token_accessor"] = info.Accessor
|
|
out["token_policies"] = fmt.Sprint(info.Policies)
|
|
out["token_ttl"] = info.TTL.String()
|
|
out["token_renewable"] = fmt.Sprint(info.Renewable)
|
|
|
|
if cmd.Bool("json") {
|
|
return printJSON(os.Stdout, out)
|
|
}
|
|
printKV(os.Stdout, out)
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
func valueOr(v, fallback string) string {
|
|
if v == "" {
|
|
return fallback
|
|
}
|
|
return v
|
|
}
|