(m KeyManager, prod bool)
| 173 | } |
| 174 | |
| 175 | func getGetKeysHandler(m KeyManager, prod bool) gin.HandlerFunc { |
| 176 | return func(c *gin.Context) { |
| 177 | log := util.GetLogFromCtx(c) |
| 178 | telemetry.Incr("bricksllm.admin.get_get_keys_handler.requests", nil, 1) |
| 179 | |
| 180 | start := time.Now() |
| 181 | defer func() { |
| 182 | dur := time.Since(start) |
| 183 | telemetry.Timing("bricksllm.admin.get_get_keys_handler.latency", dur, nil, 1) |
| 184 | }() |
| 185 | |
| 186 | tag := c.Query("tag") |
| 187 | tags := c.QueryArray("tags") |
| 188 | keyIds := c.QueryArray("keyIds") |
| 189 | provider := c.Query("provider") |
| 190 | |
| 191 | path := "/api/key-management/keys" |
| 192 | |
| 193 | if len(tags) == 0 && len(tag) == 0 && len(provider) == 0 && len(keyIds) == 0 { |
| 194 | c.JSON(http.StatusBadRequest, &ErrorResponse{ |
| 195 | Type: "/errors/missing-filteres", |
| 196 | Title: "filters are not found", |
| 197 | Status: http.StatusBadRequest, |
| 198 | Detail: "filters are missing from the request url. it is required for retrieving keys.", |
| 199 | Instance: path, |
| 200 | }) |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | selected := []string{} |
| 205 | |
| 206 | if len(tag) != 0 { |
| 207 | selected = append(selected, tag) |
| 208 | } |
| 209 | |
| 210 | for _, t := range tags { |
| 211 | if len(t) != 0 && t != tag { |
| 212 | selected = append(selected, t) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | keys, err := m.GetKeys(selected, keyIds, provider) |
| 217 | if err != nil { |
| 218 | telemetry.Incr("bricksllm.admin.get_get_keys_handler.get_keys_by_tag_err", nil, 1) |
| 219 | |
| 220 | logError(log, "error when getting api keys by tag", prod, err) |
| 221 | c.JSON(http.StatusInternalServerError, &ErrorResponse{ |
| 222 | Type: "/errors/getting-keys", |
| 223 | Title: "getting keys errored out", |
| 224 | Status: http.StatusInternalServerError, |
| 225 | Detail: err.Error(), |
| 226 | Instance: path, |
| 227 | }) |
| 228 | return |
| 229 | } |
| 230 | |
| 231 | telemetry.Incr("bricksllm.admin.get_get_keys_handler.success", nil, 1) |
| 232 | c.JSON(http.StatusOK, keys) |
no test coverage detected