api_key.go 773 B

1234567891011121314151617181920212223
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package validator // import "miniflux.app/v2/internal/validator"
  4. import (
  5. "miniflux.app/v2/internal/locale"
  6. "miniflux.app/v2/internal/model"
  7. "miniflux.app/v2/internal/storage"
  8. )
  9. // ValidateAPIKeyCreation ensures API key creation requests include a description and are unique per user.
  10. func ValidateAPIKeyCreation(store *storage.Storage, userID int64, request *model.APIKeyCreationRequest) *locale.LocalizedError {
  11. if request.Description == "" {
  12. return locale.NewLocalizedError("error.fields_mandatory")
  13. }
  14. if store.APIKeyExists(userID, request.Description) {
  15. return locale.NewLocalizedError("error.api_key_already_exists")
  16. }
  17. return nil
  18. }