-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added separate list view for CRL details
- Loading branch information
Showing
6 changed files
with
119 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# CRL Inspector | ||
[![GoReportCard example](https://goreportcard.com/badge/github.com/pimg/certguard)](https://goreportcard.com/report/github.com/pimg/certguard) ![CI tests](https://github.com/pimg/certguard/actions/workflows/build.yml/badge.svg) | ||
|
||
A Terminal User Interface (TUI) for inspecting Certificate Revocation Lists (CRL's) |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package models | ||
|
||
import ( | ||
"crypto/x509" | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/help" | ||
"github.com/charmbracelet/bubbles/key" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/pimg/certguard/internal/ports/models/styles" | ||
) | ||
|
||
// keyMap defines a set of keybindings. To work for help it must satisfy | ||
// key.Map. It could also very easily be a map[string]key.Binding. | ||
type listKeyMap struct { | ||
Back key.Binding | ||
Quit key.Binding | ||
} | ||
|
||
// ShortHelp returns keybindings to be shown in the mini help view. It's part | ||
// of the key.Map interface. | ||
func (k *listKeyMap) ShortHelp() []key.Binding { | ||
return []key.Binding{k.Back, k.Quit} | ||
} | ||
|
||
// FullHelp returns keybindings for the expanded help view. It's part of the | ||
// key.Map interface. | ||
func (k *listKeyMap) FullHelp() [][]key.Binding { | ||
return [][]key.Binding{ | ||
{k.Back, k.Quit}, | ||
} | ||
} | ||
|
||
var listKeys = listKeyMap{ | ||
Back: key.NewBinding( | ||
key.WithKeys("esc"), | ||
key.WithHelp("esc", "back to main view"), | ||
), | ||
Quit: key.NewBinding( | ||
key.WithKeys("q", "ctrl+c"), | ||
key.WithHelp("q", "quit"), | ||
), | ||
} | ||
|
||
type ListModel struct { | ||
keys listKeyMap | ||
help help.Model | ||
styles *styles.Styles | ||
crl *x509.RevocationList | ||
} | ||
|
||
func NewListModel(crl *x509.RevocationList) ListModel { | ||
return ListModel{ | ||
keys: listKeys, | ||
help: help.New(), | ||
styles: styles.DefaultStyles(), | ||
crl: crl, | ||
} | ||
} | ||
|
||
func (l ListModel) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (l ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
return l, nil | ||
} | ||
|
||
func (l ListModel) View() string { | ||
|
||
//mainInfo := map[string]string{ | ||
// "CRL Issuer": l.crl.Issuer.String(), | ||
// "Upated at": l.crl.ThisUpdate.String(), | ||
// "Next update": l.crl.NextUpdate.String(), | ||
// "No of revoked Certificates": fmt.Sprintf("%d", len(l.crl.RevokedCertificateEntries)), | ||
//} | ||
|
||
//var renderedMainInfo string | ||
//for k, v := range mainInfo { | ||
// renderedMainInfo = renderedMainInfo + "\n" + fmt.Sprintf("%s:\t\t%s", k, v) | ||
//} | ||
issuer := fmt.Sprintf("CRL Issuer : %s", l.crl.Issuer) | ||
updatedAt := fmt.Sprintf("Updated At : %s", l.crl.ThisUpdate) | ||
nextUpdate := fmt.Sprintf("Next Update : %s", l.crl.NextUpdate) | ||
revokedCertCount := fmt.Sprintf("Revoked Certificates: %d", len(l.crl.RevokedCertificateEntries)) | ||
|
||
crlInfo := l.styles.Text.Render( | ||
fmt.Sprintf("%s\n%s\n%s\n%s", issuer, updatedAt, nextUpdate, revokedCertCount), | ||
) | ||
return crlInfo | ||
} |
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