Expose API approval prompts to app state and UI
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.julianfamily.org/keepassgo/apiapproval"
|
||||
"git.julianfamily.org/keepassgo/apitokens"
|
||||
"git.julianfamily.org/keepassgo/vault"
|
||||
"git.julianfamily.org/keepassgo/webdav"
|
||||
)
|
||||
@@ -81,8 +83,14 @@ type RemoteOpenableSession interface {
|
||||
OpenRemote(webdav.Client, string, vault.MasterKey) error
|
||||
}
|
||||
|
||||
type ApprovalManager interface {
|
||||
Pending() []apiapproval.Request
|
||||
Resolve(string, apiapproval.Outcome) (apiapproval.Request, *apitokens.PolicyRule, error)
|
||||
}
|
||||
|
||||
type State struct {
|
||||
Session CurrentSession
|
||||
Approvals ApprovalManager
|
||||
Section Section
|
||||
CurrentPath []string
|
||||
SearchQuery string
|
||||
@@ -92,6 +100,21 @@ type State struct {
|
||||
ErrorMessage string
|
||||
}
|
||||
|
||||
func (s *State) PendingApprovals() []apiapproval.Request {
|
||||
if s.Approvals == nil {
|
||||
return nil
|
||||
}
|
||||
return s.Approvals.Pending()
|
||||
}
|
||||
|
||||
func (s *State) ResolveApproval(id string, outcome apiapproval.Outcome) error {
|
||||
if s.Approvals == nil {
|
||||
return fmt.Errorf("approval manager is not configured")
|
||||
}
|
||||
_, _, err := s.Approvals.Resolve(id, outcome)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *State) ShowSection(section Section) {
|
||||
s.Section = section
|
||||
s.CurrentPath = nil
|
||||
|
||||
Reference in New Issue
Block a user