hibp

package
v0.0.0-...-4d10510 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

implement request scheduling in order to attempt to comply with the HIBP's rate-limiting.

Index

Constants

This section is empty.

Variables

View Source
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

func BreachForBreachName(ctx context.Context, client *ent.Client, name string) (*ent.HIBP, error)

BreachForBreachName retrieves a single HIBP breach from the database for a given name.

func CheckSaveAllBreaches

func CheckSaveAllBreaches(ctx context.Context, client *ent.Client) error

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

func RunReqScheduler(quit chan os.Signal, errCh chan error, wg *sync.WaitGroup)

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

func SaveAllBreaches(ctx context.Context, client *ent.Client, breaches *[]schema.HIBPSchema) error

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 BreachNames

type BreachNames []BreachName

BreachNames is a slice of BreachName objects.

type CtxKey

type CtxKey struct{}

CtxKey serves as a key to context values for this package.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL