Documentation ¶
Overview ¶
implement request scheduling in order to attempt to comply with the HIBP's rate-limiting.
Index ¶
- Variables
- func BreachForBreachName(ctx context.Context, client *ent.Client, name string) (*ent.HIBP, error)
- func CheckSaveAllBreaches(ctx context.Context, client *ent.Client) error
- func GetAllBreaches() (*[]schema.HIBPSchema, error)
- func GetBreachesForBreachNames(ctx context.Context, client *ent.Client, names []string) ([]*ent.HIBP, error)
- func RunReqScheduler(quit chan os.Signal, errCh chan error, wg *sync.WaitGroup)
- func SaveAllBreaches(ctx context.Context, client *ent.Client, breaches *[]schema.HIBPSchema) error
- type BreachName
- type BreachNames
- type CtxKey
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthKeyCheckValue = errors.New(authKeyCheckValue) ErrRateLimited = errors.New("We have been rate limited") ErrBreachNotFound = errors.New("Breach not found") ErrBreachNotSingular = errors.New("Multiple breaches for one name") ErrFailedToQueryBreaches = errors.New("Failed to query breaches") ErrNoBreachesToSave = errors.New("No breaches to save") )
Functions ¶
func BreachForBreachName ¶
BreachForBreachName retrieves a single HIBP breach from the database for a given name.
func CheckSaveAllBreaches ¶
CheckSaveAllBreaches checks if there are any in the DB and if not then queries the API and saves what it gets. TODO: have this function consolidate existing vs. new breaches.
func GetAllBreaches ¶
func GetAllBreaches() (*[]schema.HIBPSchema, error)
GetAllBreaches retrieves all breaches available in HIBP, as per https://haveibeenpwned.com/API/v3#AllBreaches. This should be run at start-up to populate the cache.
func GetBreachesForBreachNames ¶
func GetBreachesForBreachNames(ctx context.Context, client *ent.Client, names []string) ([]*ent.HIBP, error)
GetBreachesForBreachNames retrieves HIBP breaches from the database for a list of names.
func RunReqScheduler ¶
RunReqScheduler runs the HIBP requests scheduler, which schedules the request in such a fashion that it does not cross the limit defined by the used API key.
func SaveAllBreaches ¶
SaveAllBreaches saves all breaches to DB as a cache.
Types ¶
type BreachName ¶
type BreachName struct { // Name holds the actual breach name, which in HIBP is permanently unique. Name string `json:"Name" validate:"required,Name"` }
BreachName is used to represent a HIBP breach name object.
func GetAllBreachesForAccount ¶
func GetAllBreachesForAccount(account string) ([]BreachName, error)
GetAllBreachesForAccount retrieves a list of breach names for a given account.
type Subscription ¶
type Subscription struct { // The name representing the subscription being either "Pwned 1", "Pwned 2", "Pwned 3" or "Pwned 4". SubscriptionName string // A human readable sentence explaining the scope of the subscription. Description string // The date and time the current subscription ends in ISO 8601 format. SubscribedUntil time.Time // The rate limit in requests per minute. This applies to the rate the breach search by email address API can be requested. Rpm int // The size of the largest domain the subscription can search. This is expressed in the total number of breached accounts on the domain, excluding those that appear solely in spam list. DomainSearchMaxBreachedAccounts int }
Subscription models the HIBP subscription struct.
func SubscriptionStatus ¶
func SubscriptionStatus() (*Subscription, error)
SubscriptionStatus models https://haveibeenpwned.com/API/v3#SubscriptionStatus.