first compiling version
This commit is contained in:
parent
60fb40d61a
commit
3d54199faa
27 changed files with 908 additions and 243 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"git.giftfish.de/ston1th/keyctl/pkg/api/types"
|
||||
"git.giftfish.de/ston1th/keyctl/pkg/api/v1/schema"
|
||||
"git.giftfish.de/ston1th/keyctl/pkg/store"
|
||||
)
|
||||
|
||||
func local(h types.CtxHandler) types.CtxHandler {
|
||||
|
|
@ -53,7 +54,7 @@ func newHandler(ctx *types.Context) {
|
|||
}
|
||||
key, err := ctx.Data.DB.CreateKey(newKey.Name, newKey.Size, newKey.Encoding)
|
||||
if err != nil {
|
||||
ctx.Log.Error(err, "error writing loadbalancer", "cluster", cl, "name", n)
|
||||
ctx.Log.Error(err, "error writing key", "name", newKey.Name)
|
||||
ctx.Err(types.ErrISE)
|
||||
return
|
||||
}
|
||||
|
|
@ -65,8 +66,11 @@ func keyHandler(ctx *types.Context) {
|
|||
id := ctx.Var("id")
|
||||
k, err := ctx.Data.DB.GetKey(id)
|
||||
if err != nil {
|
||||
//TODO error 404
|
||||
ctx.Log.Error(err, "error reading key", "id", id)
|
||||
if err == store.ErrKeyNotFound {
|
||||
ctx.Err(types.ErrNotFound)
|
||||
return
|
||||
}
|
||||
ctx.Err(types.ErrISE)
|
||||
return
|
||||
}
|
||||
|
|
@ -74,7 +78,7 @@ func keyHandler(ctx *types.Context) {
|
|||
case "GET":
|
||||
aid := ctx.Var("aid")
|
||||
if aid == "" {
|
||||
aid, err = ctx.Data.Approvals.New(id, k.Name)
|
||||
aid, err = ctx.Data.Approver.New(id, k.Name)
|
||||
if err != nil {
|
||||
ctx.Log.Error(err, "error creating approval", "id", id, "name", k.Name)
|
||||
ctx.Err(types.ErrISE)
|
||||
|
|
@ -83,14 +87,22 @@ func keyHandler(ctx *types.Context) {
|
|||
ctx.Redirect(schema.ApproveURL(id, aid), http.StatusFound)
|
||||
return
|
||||
}
|
||||
if !ctx.Data.Approvals.Approved(id, aid) {
|
||||
s := ctx.Data.Approver.Status(id, aid)
|
||||
switch s {
|
||||
case types.Pending:
|
||||
ctx.Redirect(schema.ApproveURL(id, aid), http.StatusFound)
|
||||
return
|
||||
case types.Rejected:
|
||||
ctx.Err(types.ErrKeyRequestRejected)
|
||||
return
|
||||
}
|
||||
k, err := ctx.Data.DB.GetKeyWithSecret(id)
|
||||
if err != nil {
|
||||
//TODO error 404
|
||||
ctx.Log.Error(err, "error reading key", "id", id)
|
||||
if err == store.ErrKeyNotFound {
|
||||
ctx.Err(types.ErrNotFound)
|
||||
return
|
||||
}
|
||||
ctx.Err(types.ErrISE)
|
||||
return
|
||||
}
|
||||
|
|
@ -99,6 +111,10 @@ func keyHandler(ctx *types.Context) {
|
|||
err = ctx.Data.DB.DeleteKey(id)
|
||||
if err != nil {
|
||||
ctx.Log.Error(err, "error deleting key", "id", id, "name", k.Name)
|
||||
if err == store.ErrKeyNotFound {
|
||||
ctx.Err(types.ErrNotFound)
|
||||
return
|
||||
}
|
||||
ctx.Err(types.ErrISE)
|
||||
return
|
||||
}
|
||||
|
|
@ -107,14 +123,13 @@ func keyHandler(ctx *types.Context) {
|
|||
}
|
||||
|
||||
func reqListHandler(ctx *types.Context) {
|
||||
l := ctx.Data.Approvals.List()
|
||||
l := ctx.Data.Approver.List()
|
||||
ctx.JSON(schema.NewApprovals(l))
|
||||
}
|
||||
|
||||
func keyListHandler(ctx *types.Context) {
|
||||
k, err := ctx.Data.DB.GetKeys()
|
||||
if err != nil {
|
||||
//TODO error 404
|
||||
ctx.Log.Error(err, "error reading keys")
|
||||
ctx.Err(types.ErrISE)
|
||||
return
|
||||
|
|
@ -131,6 +146,6 @@ func reqHandler(ctx *types.Context) {
|
|||
case "DELETE":
|
||||
status = types.Rejected
|
||||
}
|
||||
ctx.Data.Approvals.Update(id, status)
|
||||
ctx.Data.Approver.Update(id, status)
|
||||
ctx.OK()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue