(m KeyManager, prod bool)
| 234 | } |
| 235 | |
| 236 | func getGetKeysV2Handler(m KeyManager, prod bool) gin.HandlerFunc { |
| 237 | return func(c *gin.Context) { |
| 238 | log := util.GetLogFromCtx(c) |
| 239 | telemetry.Incr("bricksllm.admin.get_get_keys_v2_handler.requests", nil, 1) |
| 240 | |
| 241 | start := time.Now() |
| 242 | defer func() { |
| 243 | dur := time.Since(start) |
| 244 | telemetry.Timing("bricksllm.admin.get_get_keys_v2_handler.latency", dur, nil, 1) |
| 245 | }() |
| 246 | |
| 247 | path := "/api/key-management/keys" |
| 248 | if c == nil || c.Request == nil { |
| 249 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 250 | Type: "/errors/empty-context", |
| 251 | Title: "context is empty error", |
| 252 | Status: http.StatusInternalServerError, |
| 253 | Detail: "gin context is empty", |
| 254 | Instance: path, |
| 255 | }) |
| 256 | return |
| 257 | } |
| 258 | |
| 259 | data, err := io.ReadAll(c.Request.Body) |
| 260 | if err != nil { |
| 261 | logError(log, "error when reading get keys request body", prod, err) |
| 262 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 263 | Type: "/errors/request-body-read", |
| 264 | Title: "get key request body reader error", |
| 265 | Status: http.StatusInternalServerError, |
| 266 | Detail: err.Error(), |
| 267 | Instance: path, |
| 268 | }) |
| 269 | return |
| 270 | } |
| 271 | |
| 272 | request := &key.KeyRequest{} |
| 273 | err = json.Unmarshal(data, request) |
| 274 | if err != nil { |
| 275 | logError(log, "error when unmarshalling get key request body", prod, err) |
| 276 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 277 | Type: "/errors/json-unmarshal", |
| 278 | Title: "json unmarshaller error", |
| 279 | Status: http.StatusInternalServerError, |
| 280 | Detail: err.Error(), |
| 281 | Instance: path, |
| 282 | }) |
| 283 | return |
| 284 | } |
| 285 | |
| 286 | keys, err := m.GetKeysV2(request.Tags, request.KeyIds, request.Revoked, request.Limit, request.Offset, request.Name, request.Order, request.ReturnCount) |
| 287 | if err != nil { |
| 288 | errType := "internal" |
| 289 | |
| 290 | defer func() { |
| 291 | telemetry.Incr("bricksllm.admin.get_get_keys_v2_handler.get_keys_v2_err", []string{ |
| 292 | "error_type:" + errType, |
| 293 | }, 1) |
no test coverage detected