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,68 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
|
||||
// toastKind selects which of the theme's toast styles a notification uses.
|
||||
type toastKind int
|
||||
|
||||
const (
|
||||
toastInfo toastKind = iota
|
||||
toastSuccess
|
||||
toastWarn
|
||||
toastErr
|
||||
)
|
||||
|
||||
// toast is a transient status/error message shown in the footer. Replaces
|
||||
// the old Model.statusText/errText, which never expired once set.
|
||||
type toast struct {
|
||||
kind toastKind
|
||||
text string
|
||||
seq int
|
||||
}
|
||||
|
||||
// toastExpireMsg clears the toast identified by seq — guarded so a
|
||||
// newer toast issued while an older one's timer is still running can't be
|
||||
// clobbered by the older timer firing after it.
|
||||
type toastExpireMsg struct{ seq int }
|
||||
|
||||
// notify replaces the current toast and returns the tea.Cmd that expires
|
||||
// it. Errors linger noticeably longer than routine status updates.
|
||||
func (m *Model) notify(kind toastKind, format string, args ...any) tea.Cmd {
|
||||
m.toastSeq++
|
||||
seq := m.toastSeq
|
||||
m.toast = &toast{kind: kind, text: fmt.Sprintf(format, args...), seq: seq}
|
||||
|
||||
d := 4 * time.Second
|
||||
if kind == toastErr {
|
||||
d = 8 * time.Second
|
||||
}
|
||||
return tea.Tick(d, func(time.Time) tea.Msg { return toastExpireMsg{seq: seq} })
|
||||
}
|
||||
|
||||
func (m *Model) clearExpiredToast(msg toastExpireMsg) {
|
||||
if m.toast != nil && m.toast.seq == msg.seq {
|
||||
m.toast = nil
|
||||
}
|
||||
}
|
||||
|
||||
// toastView renders the current toast, or "" if there is none.
|
||||
func (m *Model) toastView() string {
|
||||
if m.toast == nil {
|
||||
return ""
|
||||
}
|
||||
switch m.toast.kind {
|
||||
case toastSuccess:
|
||||
return m.styles.ToastSuccess.Render(symOK + " " + m.toast.text)
|
||||
case toastWarn:
|
||||
return m.styles.ToastWarn.Render(symWarn + " " + m.toast.text)
|
||||
case toastErr:
|
||||
return m.styles.ToastError.Render(symErr + " " + m.toast.text)
|
||||
default:
|
||||
return m.styles.ToastInfo.Render(m.toast.text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user