MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / getUpdateKeyHandler

Function getUpdateKeyHandler

internal/server/web/admin/admin.go:661–772  ·  view source on GitHub ↗
(m KeyManager, prod bool)

Source from the content-addressed store, hash-verified

659}
660
661func 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(),

Callers 1

NewAdminServerFunction · 0.85

Calls 6

GetLogFromCtxFunction · 0.92
IncrFunction · 0.92
TimingFunction · 0.92
logErrorFunction · 0.70
ErrorMethod · 0.65
UpdateKeyMethod · 0.65

Tested by

no test coverage detected