2
0

allowlist.go 892 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package test
  2. import (
  3. "errors"
  4. "github.com/porter-dev/porter/internal/models"
  5. "github.com/porter-dev/porter/internal/repository"
  6. )
  7. // AllowlistRepository uses gorm.DB for querying the database
  8. type AllowlistRepository struct {
  9. canQuery bool
  10. allowlist []*models.Allowlist
  11. }
  12. // NewAllowlistRepository returns a AllowListRepository which uses
  13. // gorm.DB for querying the database.
  14. func NewAllowlistRepository(canQuery bool) repository.AllowlistRepository {
  15. return &AllowlistRepository{canQuery, []*models.Allowlist{}}
  16. }
  17. func (repo *AllowlistRepository) UserEmailExists(email string) (bool, error) {
  18. if !repo.canQuery {
  19. return false, errors.New("cannot read database")
  20. }
  21. if len(repo.allowlist) == 0 {
  22. return false, nil
  23. }
  24. founded := false
  25. for _, allowed := range repo.allowlist {
  26. if allowed.UserEmail == email {
  27. founded = true
  28. break
  29. }
  30. }
  31. return founded, nil
  32. }