(m KeyManager, prod bool)
| 659 | } |
| 660 | |
| 661 | func getUpdateKeyHandler(m KeyManager, prod bool) gin.HandlerFunc { |
| 662 | return func(c *gin.Context) { |
| 663 | log := util.GetLogFromCtx(c) |
| 664 | telemetry.Incr("bricksllm.admin.get_update_key_handler.requests", nil, 1) |
| 665 | |
| 666 | start := time.Now() |
| 667 | defer func() { |
| 668 | dur := time.Since(start) |
| 669 | telemetry.Timing("bricksllm.admin.get_update_key_handler.latency", dur, nil, 1) |
| 670 | }() |
| 671 | |
| 672 | path := "/api/key-management/keys/:id" |
| 673 | if c == nil || c.Request == nil { |
| 674 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 675 | Type: "/errors/empty-context", |
| 676 | Title: "context is empty error", |
| 677 | Status: http.StatusInternalServerError, |
| 678 | Detail: "gin context is empty", |
| 679 | Instance: path, |
| 680 | }) |
| 681 | return |
| 682 | } |
| 683 | |
| 684 | id := c.Param("id") |
| 685 | if len(id) == 0 { |
| 686 | c.JSON(http.StatusBadRequest, &ErrorResponse{ |
| 687 | Type: "/errors/missing-param-id", |
| 688 | Title: "id is empty", |
| 689 | Status: http.StatusBadRequest, |
| 690 | Detail: "id url param is missing from the request url. it is required for updating a key.", |
| 691 | Instance: path, |
| 692 | }) |
| 693 | |
| 694 | return |
| 695 | } |
| 696 | |
| 697 | data, err := io.ReadAll(c.Request.Body) |
| 698 | if err != nil { |
| 699 | logError(log, "error when reading api key update request body", prod, err) |
| 700 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 701 | Type: "/errors/request-body-read", |
| 702 | Title: "request body reader error", |
| 703 | Status: http.StatusInternalServerError, |
| 704 | Detail: err.Error(), |
| 705 | Instance: path, |
| 706 | }) |
| 707 | return |
| 708 | } |
| 709 | |
| 710 | uk := &key.UpdateKey{} |
| 711 | err = json.Unmarshal(data, uk) |
| 712 | if err != nil { |
| 713 | logError(log, "error when unmarshalling api key update request body", prod, err) |
| 714 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 715 | Type: "/errors/json-unmarshal", |
| 716 | Title: "json unmarshaller error", |
| 717 | Status: http.StatusInternalServerError, |
| 718 | Detail: err.Error(), |
no test coverage detected