(m KeyManager, prod bool)
| 772 | } |
| 773 | |
| 774 | func getDeleteKeyHandler(m KeyManager, prod bool) gin.HandlerFunc { |
| 775 | return func(c *gin.Context) { |
| 776 | log := util.GetLogFromCtx(c) |
| 777 | path := "/api/key-management/keys/:id" |
| 778 | if c == nil || c.Request == nil { |
| 779 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 780 | Type: "/errors/empty-context", |
| 781 | Title: "context is empty error", |
| 782 | Status: http.StatusInternalServerError, |
| 783 | Detail: "gin context is empty", |
| 784 | Instance: path, |
| 785 | }) |
| 786 | return |
| 787 | } |
| 788 | |
| 789 | id := c.Param("id") |
| 790 | if len(id) == 0 { |
| 791 | c.JSON(http.StatusBadRequest, &ErrorResponse{ |
| 792 | Type: "/errors/missing-param-id", |
| 793 | Title: "id is empty", |
| 794 | Status: http.StatusBadRequest, |
| 795 | Detail: "id url param is missing from the request url. it is required for deleting a key.", |
| 796 | Instance: path, |
| 797 | }) |
| 798 | |
| 799 | return |
| 800 | } |
| 801 | |
| 802 | err := m.DeleteKey(id) |
| 803 | if err != nil { |
| 804 | logError(log, "error when deleting api key", prod, err) |
| 805 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 806 | Type: "/errors/key-manager", |
| 807 | Title: "key deletion error", |
| 808 | Status: http.StatusInternalServerError, |
| 809 | Detail: err.Error(), |
| 810 | Instance: path, |
| 811 | }) |
| 812 | return |
| 813 | } |
| 814 | |
| 815 | c.Status(http.StatusOK) |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | type notFoundError interface { |
| 820 | Error() string |
no test coverage detected