ListKeysInGroup handles listing all keys within a specific group with pagination.
(c *gin.Context)
| 192 | |
| 193 | // ListKeysInGroup handles listing all keys within a specific group with pagination. |
| 194 | func (s *Server) ListKeysInGroup(c *gin.Context) { |
| 195 | groupID, ok := validateGroupIDFromQuery(c) |
| 196 | if !ok { |
| 197 | return |
| 198 | } |
| 199 | |
| 200 | if _, ok := s.findGroupByID(c, groupID); !ok { |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | statusFilter := c.Query("status") |
| 205 | if statusFilter != "" && statusFilter != models.KeyStatusActive && statusFilter != models.KeyStatusInvalid { |
| 206 | response.ErrorI18nFromAPIError(c, app_errors.ErrValidation, "validation.invalid_status_filter") |
| 207 | return |
| 208 | } |
| 209 | |
| 210 | searchKeyword := c.Query("key_value") |
| 211 | searchHash := "" |
| 212 | if searchKeyword != "" { |
| 213 | searchHash = s.EncryptionSvc.Hash(searchKeyword) |
| 214 | } |
| 215 | |
| 216 | query := s.KeyService.ListKeysInGroupQuery(groupID, statusFilter, searchHash) |
| 217 | |
| 218 | var keys []models.APIKey |
| 219 | paginatedResult, err := response.Paginate(c, query, &keys) |
| 220 | if err != nil { |
| 221 | response.Error(c, app_errors.ParseDBError(err)) |
| 222 | return |
| 223 | } |
| 224 | |
| 225 | // Decrypt all keys for display |
| 226 | for i := range keys { |
| 227 | decryptedValue, err := s.EncryptionSvc.Decrypt(keys[i].KeyValue) |
| 228 | if err != nil { |
| 229 | logrus.WithError(err).WithField("key_id", keys[i].ID).Error("Failed to decrypt key value for listing") |
| 230 | keys[i].KeyValue = "failed-to-decrypt" |
| 231 | } else { |
| 232 | keys[i].KeyValue = decryptedValue |
| 233 | } |
| 234 | } |
| 235 | paginatedResult.Items = keys |
| 236 | |
| 237 | response.Success(c, paginatedResult) |
| 238 | } |
| 239 | |
| 240 | // DeleteMultipleKeys handles deleting keys from a text block within a specific group. |
| 241 | func (s *Server) DeleteMultipleKeys(c *gin.Context) { |
nothing calls this directly
no test coverage detected