api_key.go 666 B

12345678910111213141516171819202122
  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. func ValidateAPIKeyCreation(store *storage.Storage, userID int64, request *model.APIKeyCreationRequest) *locale.LocalizedError {
  10. if request.Description == "" {
  11. return locale.NewLocalizedError("error.fields_mandatory")
  12. }
  13. if store.APIKeyExists(userID, request.Description) {
  14. return locale.NewLocalizedError("error.api_key_already_exists")
  15. }
  16. return nil
  17. }