cleanup
This commit is contained in:
parent
be0f532628
commit
05a68df896
15 changed files with 158 additions and 135 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,15 +18,6 @@ func local(h types.CtxHandler) types.CtxHandler {
|
|||
h(ctx)
|
||||
return
|
||||
}
|
||||
//addr, err := netip.ParseAddr(ip)
|
||||
//if err != nil {
|
||||
// ctx.Err(types.ErrForbidden)
|
||||
// return
|
||||
//}
|
||||
//if addr.IsLoopback() {
|
||||
// h(ctx)
|
||||
// return
|
||||
//}
|
||||
ctx.Err(types.ErrForbidden)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,43 +17,43 @@ const (
|
|||
|
||||
var Routes = []types.Route{
|
||||
{
|
||||
healthz,
|
||||
healthzHandler,
|
||||
[]string{"GET"},
|
||||
Path: healthz,
|
||||
Handler: healthzHandler,
|
||||
Methods: []string{"GET"},
|
||||
},
|
||||
{
|
||||
schema.KeyPath,
|
||||
local(keyListHandler),
|
||||
[]string{"GET"},
|
||||
Path: schema.KeyPath,
|
||||
Handler: local(keyListHandler),
|
||||
Methods: []string{"GET"},
|
||||
},
|
||||
{
|
||||
schema.KeyPath,
|
||||
local(newHandler),
|
||||
[]string{"POST"},
|
||||
Path: schema.KeyPath,
|
||||
Handler: local(newHandler),
|
||||
Methods: []string{"POST"},
|
||||
},
|
||||
{
|
||||
keyID,
|
||||
keyHandler,
|
||||
[]string{"GET"},
|
||||
Path: keyID,
|
||||
Handler: keyHandler,
|
||||
Methods: []string{"GET"},
|
||||
},
|
||||
{
|
||||
keyReqID,
|
||||
keyHandler,
|
||||
[]string{"GET"},
|
||||
Path: keyReqID,
|
||||
Handler: keyHandler,
|
||||
Methods: []string{"GET"},
|
||||
},
|
||||
{
|
||||
keyID,
|
||||
local(keyHandler),
|
||||
[]string{"DELETE"},
|
||||
Path: keyID,
|
||||
Handler: local(keyHandler),
|
||||
Methods: []string{"DELETE"},
|
||||
},
|
||||
{
|
||||
schema.ReqPath,
|
||||
local(reqListHandler),
|
||||
[]string{"GET"},
|
||||
Path: schema.ReqPath,
|
||||
Handler: local(reqListHandler),
|
||||
Methods: []string{"GET"},
|
||||
},
|
||||
{
|
||||
reqID,
|
||||
local(reqHandler),
|
||||
[]string{"PUT", "DELETE"},
|
||||
Path: reqID,
|
||||
Handler: local(reqHandler),
|
||||
Methods: []string{"PUT", "DELETE"},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue