database

package
v0.0.0-...-91f739d Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: BSD-3-Clause Imports: 8 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const (
	// NOTE: If changing (or adding) these values, also update
	// frontend/static/js/form.js.
	StatusUnknown                 = "unknown"
	StatusPending                 = "pending"
	StatusPreloaded               = "preloaded"
	StatusRejected                = "rejected"
	StatusRemoved                 = "removed"
	StatusPendingRemoval          = "pending-removal"
	StatusPendingAutomatedRemoval = "pending-automated-removal"
)

Values for PreloadStatus

Variables

This section is empty.

Functions

func MatchWanted

func MatchWanted(actual []DomainState, wanted []DomainState) bool

MatchWanted checks that:

- All `wanted` domain names are unique.

- `actual` and `wanted` have the same length.

- For every state ws in `wanted` there is a domain s in `actual` such that s.MatchesWanted(ws)

func NewMock

func NewMock() (m Mock, mc *MockController)

NewMock constructs a new mock, along with a MockController pointer to control the behaviour of the new Mock.

func SetPendingAutomatedRemoval

func SetPendingAutomatedRemoval(db Database, domains []string, logf func(fomat string, args ...interface{})) error

SetPendingAutomatedRemoval sets the status of a list of domains to StatusPendingAutoamtedRemoval

Types

type Database

type Database interface {
	PutStates([]DomainState, func(string, ...interface{})) error
	PutState(DomainState) error
	StateForDomain(string) (DomainState, error)
	StatesForDomains([]string) ([]DomainState, error)
	AllDomainStates() ([]DomainState, error)
	StatesWithStatus(PreloadStatus) ([]DomainState, error)
	GetIneligibleDomainStates(domains []string) (states []IneligibleDomainState, err error)
	SetIneligibleDomainStates(updates []IneligibleDomainState, logf func(format string, args ...interface{})) error
	DeleteIneligibleDomainStates(domains []string) (err error)
	GetAllIneligibleDomainStates() (states []IneligibleDomainState, err error)
}

A Database is an abstraction over Datastore with hstspreload-specific database functions.

type DatastoreBacked

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

DatastoreBacked is a database backed by a gcd.Backend.

func ProdDatabase

func ProdDatabase() (db DatastoreBacked)

ProdDatabase gives a Database that will call out to the real production instance of Google Cloud Datastore

func TempLocalDatabase

func TempLocalDatabase() (db DatastoreBacked, shutdown func() error, err error)

TempLocalDatabase spin up an local in-memory database based on a Google Cloud Datastore emulator.

Example
_, shutdown, err := TempLocalDatabase()
if err != nil {
	fmt.Printf("%s", err)
}
defer shutdown()
Output:

func (DatastoreBacked) AllDomainStates

func (db DatastoreBacked) AllDomainStates() (states []DomainState, err error)

AllDomainStates gets the states of all domains in the database.

func (DatastoreBacked) DeleteIneligibleDomainStates

func (db DatastoreBacked) DeleteIneligibleDomainStates(domains []string) (err error)

DeleteIneligibleDomainStates deletes the state for the given domain from the database

func (DatastoreBacked) GetAllIneligibleDomainStates

func (db DatastoreBacked) GetAllIneligibleDomainStates() (states []IneligibleDomainState, err error)

GetAllIneligibleDomainStates returns all the ineligible domains in the database

func (DatastoreBacked) GetIneligibleDomainStates

func (db DatastoreBacked) GetIneligibleDomainStates(domains []string) (states []IneligibleDomainState, err error)

GetIneligibleDomainStates returns the state for the given domain.

func (DatastoreBacked) PutState

func (db DatastoreBacked) PutState(update DomainState) error

PutState is a convenience version of PutStates for a single domain.

func (DatastoreBacked) PutStates

func (db DatastoreBacked) PutStates(updates []DomainState, logf func(format string, args ...interface{})) error

PutStates updates the given domain updates in batches. Writes updates to logf in real-time.

func (DatastoreBacked) SetIneligibleDomainStates

func (db DatastoreBacked) SetIneligibleDomainStates(updates []IneligibleDomainState, logf func(format string, args ...interface{})) error

SetIneligibleDomainStates updates the given domains updates in batches. Writes updates to logf in real-time.

func (DatastoreBacked) StateForDomain

func (db DatastoreBacked) StateForDomain(domain string) (state DomainState, err error)

StateForDomain get the state for the given domain. Note that the Name field of `state` will not be set.

func (DatastoreBacked) StatesForDomains

func (db DatastoreBacked) StatesForDomains(domains []string) (states []DomainState, err error)

StatesForDomains returns the domains states for the given domains

func (DatastoreBacked) StatesWithStatus

func (db DatastoreBacked) StatesWithStatus(status PreloadStatus) (domains []DomainState, err error)

StatesWithStatus returns the states of domains with the given status in the database.

type DomainState

type DomainState struct {
	// Name is the key in the datastore, so we don't include it as a field
	// in the stored value.
	Name string `datastore:"-" json:"name"`
	// e.g. StatusPending or StatusPreloaded
	Status PreloadStatus `json:"status"`
	// A custom message from the preload list maintainer explaining the
	// current status of the site (usually to explain a StatusRejected).
	Message string `datastore:",noindex" json:"message,omitempty"`
	// The Unix time this domain was last submitted.
	SubmissionDate time.Time `json:"-"`
	// If this domain is preloaded, this boolean determines whether its descendant
	// domains also are preloaded.
	IncludeSubDomains bool `json:"-"`
	// PolicyType represents the policy under which the domain is a part of the preload list
	Policy preloadlist.PolicyType `json:"-"`
}

DomainState represents the state stored for a domain in the hstspreload submission app database.

func EntryToDomainState

func EntryToDomainState(entry preloadlist.Entry, status PreloadStatus) DomainState

EntryToDomainState converts a preloadlist.Entry to a DomainState with no accompanying message.

func EntryToDomainStateWithMessage

func EntryToDomainStateWithMessage(entry preloadlist.Entry, status PreloadStatus, message string) DomainState

ToDomainStateWithMessage converts a preloadlist.Entry to a DomainState.

func (DomainState) Equal

func (s DomainState) Equal(s2 DomainState) bool

Equal checks if the fields of `s` are equal to the fields of `s2`, using == for all fields except for SubmissionDate, where Time.Equal is used instead. This is a more strict check than MatchesWanted and is intended for testing purposes.

func (DomainState) IsBulk

func (s DomainState) IsBulk() bool

func (DomainState) IsProtected

func (s DomainState) IsProtected() bool

Protected tells whether a domain is protected from automated removal

func (DomainState) MatchesWanted

func (s DomainState) MatchesWanted(wanted DomainState) bool

MatchesWanted checks if the fields of `s` match `wanted`.

- Name is always compared. - Status is always compared. - Message is compared when wanted.Message != nil - SubmissionDate is ignored.

func (DomainState) ToEntry

func (s DomainState) ToEntry() preloadlist.Entry

ToEntry converts a DomainState to a preloadlist.Entry.

Only the name, preload status, include subdomains boolean and policy is preserved during the conversion.

type IneligibleDomainState

type IneligibleDomainState struct {
	// Name is the key in the datastore, so we don't include it as a field
	// in the stored value.
	Name string `datastore:"-" json:"name"`
	// Scans is where information of the checks are stored
	Scans []Scan `json:"-"`
	//  The policy under which the domain is part of the
	//  preload list. “bulk-18-weeks” or “bulk-1-year”
	Policy string `json:"policy"`
}

IneligibleDomainState contains the state about a domain name that is potentially ineligible to remain on the list and is at risk for being removed from the list

type Mock

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

Mock is a very simple Mock for our database.

func (Mock) AllDomainStates

func (m Mock) AllDomainStates() (states []DomainState, err error)

AllDomainStates mock method

func (Mock) DeleteIneligibleDomainStates

func (m Mock) DeleteIneligibleDomainStates(domains []string) (err error)

func (Mock) GetAllIneligibleDomainStates

func (m Mock) GetAllIneligibleDomainStates() (states []IneligibleDomainState, err error)

func (Mock) GetIneligibleDomainStates

func (m Mock) GetIneligibleDomainStates(domains []string) (states []IneligibleDomainState, err error)

func (Mock) PutState

func (m Mock) PutState(update DomainState) error

PutState mock method

func (Mock) PutStates

func (m Mock) PutStates(updates []DomainState, logf func(format string, args ...interface{})) error

PutStates mock method

func (Mock) SetIneligibleDomainStates

func (m Mock) SetIneligibleDomainStates(updates []IneligibleDomainState, logf func(format string, args ...interface{})) error

func (Mock) StateForDomain

func (m Mock) StateForDomain(domain string) (state DomainState, err error)

StateForDomain mock method

func (Mock) StatesForDomains

func (m Mock) StatesForDomains(domains []string) (states []DomainState, err error)

StatesForDomain mock method

func (Mock) StatesWithStatus

func (m Mock) StatesWithStatus(status PreloadStatus) (domains []DomainState, err error)

StatesWithStatus mock method

type MockController

type MockController struct {
	FailCalls bool
}

MockController keeps track of mocking behaviour.

type PreloadStatus

type PreloadStatus string

PreloadStatus represents the current status of a domain, e.g. whether it is preloaded, pending, etc.

type Scan

type Scan struct {
	ScanTime time.Time
	Issues   hstspreload.Issues
}

Scan stores the Unix time this domain was scanned and the issues that arose

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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