This commit is contained in:
ston1th 2023-03-21 01:00:13 +01:00
commit 05a68df896
15 changed files with 158 additions and 135 deletions

View file

@ -6,7 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"time"
"git.giftfish.de/ston1th/keyctl/pkg/api/types"
"git.giftfish.de/ston1th/keyctl/pkg/core"
@ -59,7 +58,6 @@ func ApproveURL(id, aid string) string {
type Key struct {
ID string `json:"id"`
Name string `json:"name"`
Created int64 `json:"created"`
Size int `json:"size"`
Encoding core.Encoding `json:"encoding"`
Type core.Type `json:"type"`
@ -92,15 +90,14 @@ func (Keys) Less(a, b Key) bool { return a.Name < b.Name }
func (k Keys) Sort() { slices.SortStableFunc(k, k.Less) }
func (k Keys) Len() int { return len(k) }
func (k Keys) Fields() string {
return "ID\t Name\t Created\t Size\t Encoding\t Type"
return "ID\t Name\t Size\t Encoding\t Type"
}
func (k Keys) Values() []string {
vals := make([]string, len(k))
for i, v := range k {
vals[i] = fmt.Sprintf("%s\t %s\t %s\t %d\t %s\t %s",
vals[i] = fmt.Sprintf("%s\t %s\t %d\t %s\t %s",
v.ID,
v.Name,
timeFmt(v.Created),
v.Size,
v.Encoding,
v.Type,
@ -118,12 +115,11 @@ func NewKeys(keys core.Keys) (k Keys) {
}
type Approval struct {
ID string `json:"id"`
AID string `json:"aid"`
Name string `json:"name"`
IP string `json:"ip"`
Created int64 `json:"created"`
Status types.Status `json:"status"`
ID string `json:"id"`
AID string `json:"aid"`
Name string `json:"name"`
IP string `json:"ip"`
Status types.Status `json:"status"`
}
type Approvals []Approval
@ -132,17 +128,16 @@ func (Approvals) Less(a, b Approval) bool { return a.Name < b.Name }
func (a Approvals) Sort() { slices.SortStableFunc(a, a.Less) }
func (a Approvals) Len() int { return len(a) }
func (a Approvals) Fields() string {
return "ID\t Approval ID\t Name\t Status\t Created\t IP"
return "ID\t Approval ID\t Name\t Status\t IP"
}
func (a Approvals) Values() []string {
vals := make([]string, len(a))
for i, v := range a {
vals[i] = fmt.Sprintf("%s\t %s\t %s\t %s\t %s\t %s",
vals[i] = fmt.Sprintf("%s\t %s\t %s\t %s\t %s",
v.ID,
v.AID,
v.Name,
v.Status,
timeFmt(v.Created),
v.IP,
)
}
@ -152,18 +147,13 @@ func (a Approvals) Values() []string {
func NewApprovals(m types.ApprovalMap) (a Approvals) {
for k, v := range m {
a = append(a, Approval{
ID: v.ID,
AID: k,
Name: v.Name,
IP: v.IP,
Created: v.Created,
Status: v.Status,
ID: v.ID,
AID: k,
Name: v.Name,
IP: v.IP,
Status: v.Status,
})
}
a.Sort()
return
}
func timeFmt(t int64) string {
return time.Unix(t, 0).Format(time.RFC3339)
}