added get loop and new key type xor
This commit is contained in:
parent
8f350b4b02
commit
9e68b46346
8 changed files with 122 additions and 24 deletions
|
|
@ -83,6 +83,16 @@ func (c *Client) GetKey(ctx context.Context, id string) (key schema.Key, err err
|
|||
return
|
||||
}
|
||||
|
||||
func (c *Client) GetKeyLoop(ctx context.Context, id string) (key schema.Key, err error) {
|
||||
path := fmt.Sprintf("%s/%s", keyPath, id)
|
||||
req, err := c.c.NewRequest(ctx, "GET", path, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = c.c.FollowRedirectLoop(req, &key, time.Second*2)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) CreateKey(ctx context.Context, newKey schema.NewKey) (key schema.Key, err error) {
|
||||
buf := new(bytes.Buffer)
|
||||
path := keyPath
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ 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 Size\t Encoding\t Type"
|
||||
return "Key ID\t Name\t Size\t Encoding\t Type"
|
||||
}
|
||||
func (k Keys) Values() []string {
|
||||
vals := make([]string, len(k))
|
||||
|
|
@ -128,7 +128,7 @@ 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 IP"
|
||||
return "Key ID\t Approval ID\t Name\t Status\t IP"
|
||||
}
|
||||
func (a Approvals) Values() []string {
|
||||
vals := make([]string, len(a))
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func keyHandler(ctx *types.Context) {
|
|||
if err != nil {
|
||||
ctx.Log.Error(err, "error reading key", "id", id)
|
||||
if err == store.ErrKeyNotFound {
|
||||
ctx.Err(types.ErrNotFound)
|
||||
ctx.Err(types.ErrKeyNotFound)
|
||||
return
|
||||
}
|
||||
ctx.Err(types.ErrISE)
|
||||
|
|
@ -77,7 +77,7 @@ func keyHandler(ctx *types.Context) {
|
|||
aid, err = ctx.Data.Approver.New(id, k.Name, ip)
|
||||
if err != nil {
|
||||
ctx.Log.Error(err, "error creating approval", "id", id, "name", k.Name)
|
||||
ctx.Err(types.ErrISE)
|
||||
ctx.Err(types.ErrTooManyApprovals)
|
||||
return
|
||||
}
|
||||
ctx.Redirect(schema.ApproveURL(id, aid), http.StatusFound)
|
||||
|
|
@ -91,6 +91,9 @@ func keyHandler(ctx *types.Context) {
|
|||
case types.Rejected:
|
||||
ctx.Err(types.ErrKeyRequestRejected)
|
||||
return
|
||||
case types.NotFound:
|
||||
ctx.Err(types.ErrReqNotFound)
|
||||
return
|
||||
}
|
||||
k, err := ctx.Data.DB.GetKeyWithSecret(id)
|
||||
if err != nil {
|
||||
|
|
@ -142,6 +145,11 @@ func reqHandler(ctx *types.Context) {
|
|||
case "DELETE":
|
||||
status = types.Rejected
|
||||
}
|
||||
ctx.Data.Approver.Update(id, status)
|
||||
err := ctx.Data.Approver.Update(id, status)
|
||||
if err != nil {
|
||||
ctx.Log.Error(err, "error updating key request")
|
||||
ctx.Err(types.ErrReqNotFound)
|
||||
return
|
||||
}
|
||||
ctx.OK()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue