-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
130 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
package status | ||
|
||
import "github.com/spf13/cobra" | ||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/vulncheck-oss/cli/pkg/config" | ||
"github.com/vulncheck-oss/cli/pkg/session" | ||
"github.com/vulncheck-oss/cli/pkg/ui" | ||
) | ||
|
||
func Command() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "status", | ||
Short: "Check authentication status", | ||
Long: "Check if you're currently authenticated and if so, display the account information". | ||
Long: "Check if you're currently authenticated and if so, display the account information", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
config.Init() | ||
|
||
if !config.HasConfig() { | ||
ui.Danger("No configuration found. Please run `vc auth login` to authenticate.") | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
session.DisableAuthCheck(cmd) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ui | ||
|
||
import ( | ||
"fmt" | ||
"github.com/charmbracelet/bubbles/textinput" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"log" | ||
) | ||
|
||
type tokenModel struct { | ||
TextInput textinput.Model | ||
err error | ||
} | ||
|
||
type ( | ||
errMsg error | ||
) | ||
|
||
func initialModel() tokenModel { | ||
ti := textinput.New() | ||
ti.Placeholder = "vulncheck_***********" | ||
ti.Focus() | ||
ti.CharLimit = 74 | ||
ti.Width = 74 | ||
ti.EchoMode = textinput.EchoPassword | ||
|
||
return tokenModel{ | ||
TextInput: ti, | ||
err: nil, | ||
} | ||
} | ||
|
||
func (m tokenModel) Init() tea.Cmd { | ||
return textinput.Blink | ||
} | ||
|
||
func (m tokenModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
|
||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch msg.Type { | ||
case tea.KeyEnter, tea.KeyCtrlC, tea.KeyEsc: | ||
return m, tea.Quit | ||
} | ||
|
||
// We handle errors just like any other message | ||
case errMsg: | ||
m.err = msg | ||
return m, nil | ||
} | ||
|
||
m.TextInput, cmd = m.TextInput.Update(msg) | ||
return m, cmd | ||
} | ||
|
||
func (m tokenModel) View() string { | ||
return fmt.Sprintf( | ||
"Paste your authentication token\n\n%s\n\n%s", | ||
m.TextInput.View(), | ||
"(esc to equit)", | ||
) + "\n" | ||
|
||
} | ||
|
||
func TokenPrompt() (string, error) { | ||
p := tea.NewProgram(initialModel()) | ||
result, err := p.Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
return "", err | ||
} | ||
return result.(tokenModel).TextInput.Value(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters