haveibeenpwned

package module
v0.0.0-...-696c637 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 13 Imported by: 0

README

A Go Package Client Library for Troy Hunt's haveibeenpwned API version 3

https://haveibeenpwned.com/API/v3

Test

go test -v -run TestHaveIBeenPwned
go test -v -run TestHaveIBeenPwned_GetDataClasses
go test -v
go test ./...

Example Usage

package main

import (
	"context"
	"fmt"
    
	"github.com/klopjq/haveibeenpwned"	
)

func main()  {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	hibp := haveibeenpwned.New("123")

	// https://haveibeenpwned.com/API/v3#BreachesForAccount
	breaches, err := hibp.GetBreachedAccount(ctx, "info@example.com", "",
		false, false)
	if err != nil {
		fmt.Println(err)
	}
	for i := range breaches {
		fmt.Printf("%#v\n", breaches[i])
	}

	// https://haveibeenpwned.com/API/v3#AllBreaches
	domainBreaches, err := hibp.GetBreaches(ctx, "adobe.com")
	if err != nil {
		fmt.Println(err)
	}
	for i := range domainBreaches {
		fmt.Printf("%#v\n", domainBreaches[i])
	}

	// https://haveibeenpwned.com/API/v3#SingleBreach
	siteBreached, err := hibp.GetBreachedSite(ctx, "Adobe")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%#v\n", siteBreached)

	// https://haveibeenpwned.com/API/v3#AllDataClasses
	dataClasses, err := hibp.GetDataClasses(ctx)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%#v\n", dataClasses)

	// https://haveibeenpwned.com/API/v3#PastesForAccount
	pastes, err := hibp.GetPastedAccount(ctx, "info@example.com")
	if err != nil {
		fmt.Println(err)
	}
	for i := range pastes {
		fmt.Printf("%#v\n", pastes[i])
	}
}

Documentation

Index

Constants

View Source
const (
	UserAgent     = "haveibeenpwned-client/v0.1"
	Accept        = "application/json"
	Endpoint      = "https://haveibeenpwned.com/api/v3/"
	Domain        = `^(?:[_\-a-z0-9]+\.)*([\-a-z0-9]+\.)[\-a-z0-9]{2,63}$`
	DomainUnicode = `^(?:[_\-\p{L}\d]+\.)*([\-\p{L}\d]+\.)[\-\p{L}\d]{2,63}$`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Breach

type Breach struct {
	Name         string      `json:"Name,omitempty"`
	Title        string      `json:"Title,omitempty"`
	Domain       string      `json:"Domain,omitempty"`
	BreachDate   string      `json:"BreachDate,omitempty"`
	AddedDate    time.Time   `json:"AddedDate,omitempty"`
	ModifiedDate time.Time   `json:"ModifiedDate,omitempty"`
	PwnCount     int         `json:"PwnCount,omitempty"`
	Description  string      `json:"Description,omitempty"`
	LogoPath     string      `json:"LogoPath,omitempty"`
	DataClasses  DataClasses `json:"DataClasses,omitempty"`
	IsVerified   bool        `json:"IsVerified,omitempty"`
	IsFabricated bool        `json:"IsFabricated,omitempty"`
	IsSensitive  bool        `json:"IsSensitive,omitempty"`
	IsRetired    bool        `json:"IsRetired,omitempty"`
	IsSpamList   bool        `json:"IsSpamList,omitempty"`
}

type DataClasses

type DataClasses []string

type HIBPErrorResponse

type HIBPErrorResponse struct {
	Message     string `json:"message"`
	Description string `json:"-"`
	Code        int    `json:"statusCode"`
	RetryAfter  int    `json:"-"`
}

func (*HIBPErrorResponse) Error

func (e *HIBPErrorResponse) Error() string

type HaveIBeenPwned

type HaveIBeenPwned struct {
	// contains filtered or unexported fields
}

func New

func New(accessKey string) *HaveIBeenPwned

func (*HaveIBeenPwned) GetBreachedAccount

func (o *HaveIBeenPwned) GetBreachedAccount(ctx context.Context, email string, domain string,
	truncateResponse bool, includeUnverified bool) ([]Breach, error)

func (*HaveIBeenPwned) GetBreachedSite

func (o *HaveIBeenPwned) GetBreachedSite(ctx context.Context, site string) (*Breach, error)

func (*HaveIBeenPwned) GetBreaches

func (o *HaveIBeenPwned) GetBreaches(ctx context.Context, domain string) ([]*Breach, error)

func (*HaveIBeenPwned) GetDataClasses

func (o *HaveIBeenPwned) GetDataClasses(ctx context.Context) (*DataClasses, error)

func (*HaveIBeenPwned) GetPastedAccount

func (o *HaveIBeenPwned) GetPastedAccount(ctx context.Context, email string) ([]*Paste, error)

type Paste

type Paste struct {
	Source     string    `json:"Source,omitempty"`
	Id         string    `json:"Id,omitempty"`
	Title      string    `json:"Title,omitempty"`
	Date       time.Time `json:"Date,omitempty"`
	EmailCount int       `json:"EmailCount,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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