Files
trufflehog/pkg/tui/pages/source_configure/source_configure.go
Honandmcastorina 47c2b6bed9
Lint / lint (push) Waiting to run
Release / Release (push) Waiting to run
Scan for secrets / test (push) Waiting to run
Snifftest / Run Snifftest (push) Waiting to run
Test / test (push) Waiting to run
Test / test-detectors (push) Waiting to run
Test / test-community (push) Waiting to run
Add terminal UI (#1593)
* Init attempt at tui with bubble tea.

Co-authored-by: mcastorina <[email protected]>

* Add starting and source selection options

Co-authored-by: mcastorina <[email protected]>

* Rewrite models into a state machine

* Update source descriptions

* Make subpages implement tea.Model

* Rename page0 and page1 to be more descriptive

* Adjust styling and adding color consts

Co-authored-by: mcastorina <[email protected]>

* Add helper generic function to call Update and type cast

* Setup plumbing for source configuration page

* Use CLI introspection for source configuration (WIP)

* Experiment with table view

* Replace table with form fields

Co-authored-by: mcastorina <[email protected]>

* Change 🔒 to 💸

* Copy components from soft-serve

Co-authored-by: hxnyk <[email protected]>

* Copy styles from soft-serve

Co-authored-by: hxnyk <[email protected]>

* Copy common from soft-serve

Co-authored-by: hxnyk <[email protected]>

* Refactor into pages

This is still a WIP, but the main structure is there.

Co-authored-by: hxnyk <[email protected]>

* Trying out selector for wizard intro

Co-authored-by: mcastorina <[email protected]>

* Use selector with custom View

Co-authored-by: hxnyk <[email protected]>

* Change Item to be an enum

Co-authored-by: hxnyk <[email protected]>

* Add link pages

Co-authored-by: mcastorina <[email protected]>

* Update source select to use selector

Co-authored-by: mcastorina <[email protected]>

* Delete source configure page and add blank tabs

Co-authored-by: hxnyk <[email protected]>

* Add tab placeholder pages for configurationi

Co-authored-by: mcastorina <[email protected]>

* Added headers and style to each tab

Co-authored-by: hxnyk <[email protected]>

* Update with new sources

* Remove kingpin attribute from SourceItem

* Add basic form field and source structuring

* Hookup git form fields with an underlying textinput component

Co-authored-by: hxnyk <[email protected]>

* Update forms for git and github

Co-authored-by: mcastorina <[email protected]>

* Add labels per text input

* Add sources and adjust styling

* add basic trufflehog configuration page

* Add skip button to textinputs component

* Emit and handle textinputs skip/submit button commands

* Don't quit when q is pressed on the sourceConfigurePage

* Build trufflehog command based on source config vals

Co-authored-by: mcastorina <[email protected]>

* Build flags based on truffle config inputs

* Update summary section

* Add generated truffle fields

Co-authored-by: mcastorina <[email protected]>

* update summary to correctly print info

* Go back a page when escape key is pressed

* WIP run page list

Co-authored-by: hxnyk <[email protected]>

* Allow running trufflehog from the run page

Co-authored-by: hxnyk <[email protected]>

* Add option to view help docs

Co-authored-by: mcastorina <[email protected]>

* comment out unused styles and remove unused types

* Capitalize H in TruffleHog

* remove unneeded fmt.Sprintf

---------

Co-authored-by: mcastorina <[email protected]>
2023-08-09 13:13:55 -07:00

140 lines
3.2 KiB
Go

package source_configure
import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/components/tabs"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/components/textinputs"
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/sources"
)
type SetSourceMsg struct {
Source string
}
type tab int
const (
configTab tab = iota
truffleConfigTab
runTab
)
func (t tab) String() string {
return []string{
"1. Source Configuration",
"2. TruffleHog Configuration",
"3. Run",
}[t]
}
type SourceConfigure struct {
common.Common
activeTab tab
tabs *tabs.Tabs
configTabSource string
tabComponents []common.Component
sourceFields sources.CmdModel
truffleFields sources.CmdModel
}
func (m SourceConfigure) Init() tea.Cmd {
return m.tabs.Init()
}
func New(c common.Common) *SourceConfigure {
conf := SourceConfigure{Common: c, truffleFields: GetTrufflehogConfiguration()}
conf.tabs = tabs.New(c, []string{configTab.String(), truffleConfigTab.String(), runTab.String()})
conf.tabComponents = []common.Component{
configTab: NewSourceComponent(c, &conf),
truffleConfigTab: NewTrufflehogComponent(c, &conf),
runTab: NewRunComponent(c, &conf),
}
return &conf
}
func (m *SourceConfigure) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
for i := range m.tabComponents {
model, cmd := m.tabComponents[i].Update(msg)
m.tabComponents[i] = model.(common.Component)
cmds = append(cmds, cmd)
}
case tabs.ActiveTabMsg:
m.activeTab = tab(msg)
t, cmd := m.tabs.Update(msg)
m.tabs = t.(*tabs.Tabs)
if cmd != nil {
cmds = append(cmds, cmd)
}
case tabs.SelectTabMsg:
m.activeTab = tab(msg)
t, cmd := m.tabs.Update(msg)
m.tabs = t.(*tabs.Tabs)
if cmd != nil {
cmds = append(cmds, cmd)
}
case tea.KeyMsg:
t, cmd := m.tabs.Update(msg)
m.tabs = t.(*tabs.Tabs)
if cmd != nil {
cmds = append(cmds, cmd)
}
case SetSourceMsg:
m.configTabSource = msg.Source
// TODO: Use actual messages or something?
m.tabComponents[truffleConfigTab].(*TrufflehogComponent).SetForm(m.truffleFields)
fields := sources.GetSourceFields(m.configTabSource)
if fields != nil {
m.sourceFields = fields
m.tabComponents[configTab].(*SourceComponent).SetForm(fields)
}
case textinputs.SelectNextMsg, textinputs.SelectSkipMsg:
if m.activeTab < runTab {
m.activeTab++
}
t, cmd := m.tabs.Update(tabs.SelectTabMsg(int(m.activeTab)))
m.tabs = t.(*tabs.Tabs)
if cmd != nil {
cmds = append(cmds, cmd)
}
}
tab, cmd := m.tabComponents[m.activeTab].Update(msg)
m.tabComponents[m.activeTab] = tab.(common.Component)
if cmd != nil {
cmds = append(cmds, cmd)
}
return m, tea.Batch(cmds...)
}
func (m *SourceConfigure) View() string {
return lipgloss.JoinVertical(lipgloss.Top,
m.tabs.View(),
m.tabComponents[m.activeTab].View(),
)
}
func (m *SourceConfigure) ShortHelp() []key.Binding {
// TODO: actually return something
return nil
}
func (m *SourceConfigure) FullHelp() [][]key.Binding {
// TODO: actually return something
return nil
}