Skip to main content

internal/notify/destination.go

internal/notify · 151 lines · 7 declarations · source

This file carries the package documentation, rendered on the package page.

Declarations

var ErrNotPermitted

var ErrNotPermitted = errors.New("this deployment does not send notifications to that destination")

ErrNotPermitted is a destination this deployment will not send to. One error for every reason, because a caller registering an endpoint should learn that it is not allowed and not learn which private addresses exist behind the refusal.

source

type Destinations

type Destinations struct {
// hosts are exact hostnames or a leading-dot suffix ("example.com", ".example.com"). A suffix
// permits subdomains and nothing else; an empty list permits nothing.
hosts []string
// permitPrivate lets a destination resolve to a private or loopback address. Off unless an
// operator says otherwise, and the only reason to say otherwise is a deployment whose receiver
// genuinely is on the same private network — which is a thing to state, not to discover.
permitPrivate bool
}

Destinations is what an operator permitted. The zero value permits nothing, which is the point: a deployment that has not been configured for notifications does not make outbound requests.

source

func Permit

func Permit(list string, permitPrivate bool) Destinations

Permit builds the operator's list. An empty list is not an error: it is a deployment with notifications off, and the sender refuses every destination.

source

method Destinations.Enabled

func (d Destinations) Enabled() bool

Enabled reports whether any destination could be permitted at all.

source

method Destinations.Allow

func (d Destinations) Allow(raw string, resolve func(string) ([]net.IP, error)) error

Allow checks a URL against what the operator permitted: the scheme, the host and, unless the operator said otherwise, that it does not resolve into somewhere this deployment can reach and the internet cannot.

The resolution is deliberately at send time as well as at registration. A destination is a name, and a name's answer is somebody else's to change.

source

method Destinations.listed

func (d Destinations) listed(host string) bool

source

func routable

func routable(ip net.IP) bool

routable reports whether an address is one the public internet could have given us. Everything else — loopback, link-local, private, multicast, unspecified, and the IPv4 address embedded in an IPv6 form of it — is somewhere only this deployment can reach.

source