Documentation
¶
Overview ¶
Package resourcedownload is the short-lived download link to a managed resource (#2847): manage_resource action=download_link, or Copy link in the portal, hands back a URL on the platform's public address that anybody holding it can GET the file from, with no session or key, until it expires. It is for handing a file to a connection that needs it now (an API that takes a PDF by URL), and comes in two kinds: a single download, which ends after the first full download or an hour, and one that works for six hours. A HEAD request or a byte-range read is not the download, since a fetcher may make one before it (a PDF reader reads by range).
The link is the asset content URL's token (internal/portal/contenturl, #1848) under a key of its own, so a token minted for one is never valid as the other, every replica verifies what any replica minted, and nothing is stored.
Index ¶
Constants ¶
const ( // SingleDownload ends after its first full download, or after // SingleTTL. SingleDownload = "single_download" // SixHours works for anyone holding it for SixHoursTTL. SixHours = "6h" SingleTTL = time.Hour SixHoursTTL = 6 * time.Hour )
The two kinds of link (a link's expires), and how long each lives.
const KeyLabel = "resource-download-link"
KeyLabel derives this package's key from the browser-session signing key.
const Route = "GET " + RoutePrefix + "{token}/{filename}"
Route is the pattern a link is served on.
const RoutePrefix = "/api/v1/resources/downloads/"
RoutePrefix is where a link is served: the token, then the file's name, so a reader that judges a file by its URL sees what it is.
Variables ¶
var ( ErrUnavailable = errors.New("this deployment cannot give out download links: it needs auth.browser_session.signing_key " + "to sign them and portal.public_base_url to name them") // ErrBadExpiry is a kind of link there is none of. ErrBadExpiry = fmt.Errorf("expires is %q (ended by the first full download, or an hour) or %q (six hours)", SingleDownload, SixHours) )
Errors a caller tells apart.
Functions ¶
This section is empty.
Types ¶
type Link ¶
type Link struct {
URL string `json:"url" example:"https://data.example.com/api/v1/resources/downloads/eyJ...Q/report.pdf"`
Expires string `json:"expires" example:"single_download"`
ExpiresAt time.Time `json:"expires_at"`
}
Link is a minted link.
type Options ¶
type Options struct {
// Master is the browser-session signing key the link key is derived from.
Master []byte
// Base is the platform's public address (portal.public_base_url).
Base string
Store Store
Objects resource.S3Client
Bucket string
// Uses records single downloads (NewUses).
Uses Uses
}
Options is what a Service is made from.
type Service ¶
type Service struct {
// Now is the clock; nil is time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
Service mints links and serves the files they name.
func New ¶
New is the service o describes, nil when it has no signing key, public address, store or record of single downloads: a deployment that cannot sign, name or count a link hands out none.