2021-04-10 05:58:01 +00:00
|
|
|
package store
|
|
|
|
|
2021-11-05 23:41:27 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-01-13 08:10:36 +00:00
|
|
|
"git.t-juice.club/torjus/apiary/models"
|
2021-11-05 23:41:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ErrStoreUnhealthy = errors.New("store is unhealthy")
|
2021-04-10 05:58:01 +00:00
|
|
|
|
|
|
|
type LoginStats string
|
|
|
|
|
|
|
|
const (
|
|
|
|
LoginStatsUndefined LoginStats = ""
|
|
|
|
LoginStatsPasswords LoginStats = "password"
|
|
|
|
LoginStatsCountry LoginStats = "country"
|
2021-04-10 13:18:55 +00:00
|
|
|
LoginStatsIP LoginStats = "ip"
|
2021-04-10 05:58:01 +00:00
|
|
|
LoginStatsUsername LoginStats = "username"
|
2021-04-10 13:18:55 +00:00
|
|
|
LoginStatsTotals LoginStats = "total"
|
2021-04-10 05:58:01 +00:00
|
|
|
)
|
|
|
|
|
2021-04-13 05:30:07 +00:00
|
|
|
type AttemptQueryType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
AttemptQueryTypeUsername AttemptQueryType = "username"
|
|
|
|
AttemptQueryTypePassword AttemptQueryType = "password"
|
|
|
|
AttemptQueryTypeIP AttemptQueryType = "ip"
|
|
|
|
)
|
|
|
|
|
2021-04-10 05:58:01 +00:00
|
|
|
type StatsResult struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Count int `json:"count"`
|
|
|
|
}
|
|
|
|
|
2021-04-13 05:30:07 +00:00
|
|
|
type AttemptQuery struct {
|
|
|
|
QueryType AttemptQueryType
|
|
|
|
Query string
|
|
|
|
}
|
2021-04-10 05:58:01 +00:00
|
|
|
type LoginAttemptStore interface {
|
|
|
|
AddAttempt(l *models.LoginAttempt) error
|
2022-08-26 10:21:52 +00:00
|
|
|
All() (<-chan models.LoginAttempt, error)
|
2021-04-10 05:58:01 +00:00
|
|
|
Stats(statType LoginStats, limit int) ([]StatsResult, error)
|
2021-04-13 05:30:07 +00:00
|
|
|
Query(query AttemptQuery) ([]models.LoginAttempt, error)
|
2021-11-05 23:37:28 +00:00
|
|
|
HealthCheker
|
|
|
|
}
|
|
|
|
|
|
|
|
type HealthCheker interface {
|
2021-11-05 23:41:27 +00:00
|
|
|
IsHealthy() error
|
2021-04-10 05:58:01 +00:00
|
|
|
}
|