Documentation
¶
Index ¶
- Variables
- func DecryptAES128GCM(key []byte, base64EncryptedText string) (string, error)
- func DecryptURL(url string) (string, error)
- func DecryptURLKey(secretKey string, url string) (string, error)
- func EncryptAES128GCM(key []byte, plaintext string) (string, error)
- func EncryptURLKey(secretKey string, url string) (string, error)
- func ErrorImage(color string) (*vips.ImageRef, error)
- func HostAllowed(host string, allowed []string) bool
- func IsPublicAddress(ip net.IP) bool
- func LegacyKey(secretKey string) bool
- func NewJpegExportParams(options JpegCompression, stripMetadata bool) *vips.JpegExportParams
- func NewPngExportParams(options PngCompression, stripMetadata bool) *vips.PngExportParams
- func NewWebpExportParams(options WebpCompression, stripMetadata bool) *vips.WebpExportParams
- func ReadSource(body io.Reader, declared int64) ([]byte, error)
- func RecordStartupError(err error)
- func RegisterImageBackend(sourceBackend SourceBackend)
- func SignedMessage(commands string, imageUrl string, signedQuery string) string
- func StartVips(config *Config)
- func ValidateImageURL(u *url.URL, config Network) error
- type Config
- type EdgeControl
- type Error
- type FileSource
- type Image
- type ImageOutputOptions
- type JpegCompression
- type Limits
- type Network
- type Options
- type OriginCacheControl
- type OutputFormat
- type PngCompression
- type S3
- type Server
- type Signer
- type Signing
- type Source
- type SourceBackend
- type StatusError
- type Timeout
- type Vips
- type WebpCompression
Constants ¶
This section is empty.
Variables ¶
var ImageTypes = map[string]vips.ImageType{ "gif": vips.ImageTypeGIF, "jpeg": vips.ImageTypeJPEG, "jpg": vips.ImageTypeJPEG, "png": vips.ImageTypePNG, "tiff": vips.ImageTypeTIFF, "webp": vips.ImageTypeWEBP, "heif": vips.ImageTypeHEIF, "svg": vips.ImageTypeSVG, "psd": vips.ImageTypePSD, }
var Version = "v0.0.0"
Functions ¶
func DecryptAES128GCM ¶
DecryptAES128GCM takes a base64-encoded ciphertext and decrypts it using AES-128-GCM. The input must be encoded as: IV (12 bytes) | Ciphertext | Tag (16 bytes).
func DecryptURL ¶
func DecryptURLKey ¶ added in v0.7.2
DecryptURLKey decrypts the given eurl string using a derived AES-128-GCM key.
func EncryptAES128GCM ¶
EncryptAES128GCM encrypts the given plaintext using AES-128-GCM with the provided key. The result is base64-encoded and includes IV (12 bytes) | ciphertext | tag (16 bytes).
func EncryptURLKey ¶ added in v0.7.2
func HostAllowed ¶
HostAllowed reports whether host passes the configured allowlist. An empty allowlist permits every host.
func IsPublicAddress ¶
IsPublicAddress reports whether an address is routable on the public internet. An IPv4 address mapped into IPv6 is judged as IPv4, so ::ffff:169.254.169.254 is refused along with 169.254.169.254.
func LegacyKey ¶
LegacyKey reports whether the signing key uses the mod_dims sha1: prefix. That path derives the AES key from 16 hex characters, so it carries 64 bits of key material spread across 16 bytes.
func NewJpegExportParams ¶
func NewJpegExportParams(options JpegCompression, stripMetadata bool) *vips.JpegExportParams
func NewPngExportParams ¶
func NewPngExportParams(options PngCompression, stripMetadata bool) *vips.PngExportParams
func NewWebpExportParams ¶
func NewWebpExportParams(options WebpCompression, stripMetadata bool) *vips.WebpExportParams
func ReadSource ¶
ReadSource reads a source image and refuses one above DIMS_MAX_SOURCE_BYTES. The pixel caps do not cover this. They run once the whole body is already in memory, so only a byte limit bounds what a burst of downloads allocates.
declared is the size the origin announced. Pass a negative number when the origin announced none. A declared size above the limit is refused before the read, so an oversized body costs nothing.
func RecordStartupError ¶
func RecordStartupError(err error)
RecordStartupError stores a configuration failure for Validate to report. Only safe to call during package initialisation, which is single threaded.
func RegisterImageBackend ¶ added in v0.6.0
func RegisterImageBackend(sourceBackend SourceBackend)
func SignedMessage ¶
SignedMessage returns the string a signature covers. It holds one field per line: the command path, the image URL, then the canonical query.
A line break cannot appear inside a field. The query is percent-encoded, and a control character in the command path or the image URL is refused before the request is signed or validated. So one field can never stand in for two.
Types ¶
type Config ¶
type Config struct {
BindAddress string `env:"DIMS_BIND_ADDRESS" envDefault:":8080"`
DevelopmentMode bool `env:"DIMS_DEVELOPMENT_MODE" envDefault:"false"`
DebugMode bool `env:"DIMS_DEBUG_MODE" envDefault:"false"`
LogFormat string `env:"DIMS_LOG_FORMAT" envDefault:"text"`
Timeout
Limits
Vips
Server
Network
EdgeControl
Signing
Error
OriginCacheControl
OutputFormat
Options
ImageOutputOptions
}
func ReadConfig ¶
func ReadConfig() *Config
type EdgeControl ¶
type EdgeControl struct {
DownstreamTtl int `env:"DIMS_EDGE_CONTROL_DOWNSTREAM_TTL" envDefault:"0"`
}
type Error ¶
type Error struct {
Background string `env:"DIMS_ERROR_BACKGROUND" envDefault:"#5ADAFD"`
}
type FileSource ¶ added in v0.6.0
type FileSource struct {
BaseDir string `env:"DIMS_FILE_BASE_DIR" envDefault:"./resources"`
}
type Image ¶
type Image struct {
Bytes []byte // The downloaded image.
Format vips.ImageType // The original image format.
Status int // The HTTP status code of the downloaded image.
CacheControl string // The cache headers from the downloaded image.
EdgeControl string // The edge control headers from the downloaded image.
LastModified string // The last modified header from the downloaded image.
Etag string // The etag header from the downloaded image.
}
type ImageOutputOptions ¶
type ImageOutputOptions struct {
Jpeg JpegCompression
Png PngCompression
Webp WebpCompression
}
type JpegCompression ¶
type JpegCompression struct {
Quality int `env:"DIMS_JPEG_QUALITY" envDefault:"80"`
Interlace bool `env:"DIMS_JPEG_INTERLACE" envDefault:"false"`
OptimizeCoding bool `env:"DIMS_JPEG_OPTIMIZE_CODING" envDefault:"true"`
SubsampleMode bool `env:"DIMS_JPEG_SUBSAMPLE_MODE" envDefault:"true"`
TrellisQuant bool `env:"DIMS_JPEG_TRELLIS_QUANT" envDefault:"false"`
OvershootDeringing bool `env:"DIMS_JPEG_OVERSHOOT_DERINGING" envDefault:"false"`
OptimizeScans bool `env:"DIMS_JPEG_OPTIMIZE_SCANS" envDefault:"false"`
QuantTable int `env:"DIMS_JPEG_QUANT_TABLE" envDefault:"3"`
}
type Limits ¶
type Limits struct {
// Cost is linear in output pixels, measured at roughly 30 megapixels per
// second per thread. These caps bound the work one request can ask for.
// Zero disables a check.
MaxSourcePixels int `env:"DIMS_MAX_SOURCE_PIXELS" envDefault:"100000000"`
MaxOutputPixels int `env:"DIMS_MAX_OUTPUT_PIXELS" envDefault:"50000000"`
// MaxConcurrent caps how many images are processed at once. Zero derives
// a value from the CPU count. A negative value removes the limit.
MaxConcurrent int `env:"DIMS_MAX_CONCURRENT" envDefault:"0"`
// MaxConcurrentWait is how long a request queues for a slot before it is
// refused, in milliseconds.
MaxConcurrentWait int `env:"DIMS_MAX_CONCURRENT_WAIT" envDefault:"5000"`
// MaxSourceBytes caps the size of one source image, in bytes. The pixel
// caps do not bound memory, because the whole body is resident before any
// pixel check runs. Zero disables the check.
MaxSourceBytes int `env:"DIMS_MAX_SOURCE_BYTES" envDefault:"67108864"`
// MaxDownloadConcurrent caps how many source downloads run at once. Each
// download holds a whole source body, so this and MaxSourceBytes together
// bound the memory a burst can reach. Zero derives a value from the CPU
// count. A negative value removes the limit.
MaxDownloadConcurrent int `env:"DIMS_MAX_DOWNLOAD_CONCURRENT" envDefault:"0"`
}
type Network ¶
type Network struct {
// AllowedHosts limits which hosts an image may be fetched from. An entry
// starting with a dot matches any subdomain. An empty list allows any host
// that passes the address check.
AllowedHosts []string `env:"DIMS_ALLOWED_HOSTS"`
// AllowPrivateNetworks permits connections to loopback, link local,
// private, and other non-public addresses. Keep it false unless the origin
// sits inside the same network.
AllowPrivateNetworks bool `env:"DIMS_ALLOW_PRIVATE_NETWORKS" envDefault:"false"`
// MaxRedirects caps how many redirects one fetch will follow.
MaxRedirects int `env:"DIMS_MAX_REDIRECTS" envDefault:"3"`
}
type OriginCacheControl ¶
type OriginCacheControl struct {
UseOrigin bool `env:"DIMS_CACHE_CONTROL_USE_ORIGIN" envDefault:"false"`
Min int `env:"DIMS_CACHE_CONTROL_MIN" envDefault:"0"`
Max int `env:"DIMS_CACHE_CONTROL_MAX" envDefault:"0"`
Default int `env:"DIMS_CACHE_CONTROL_DEFAULT" envDefault:"31536000"`
Error int `env:"DIMS_CACHE_CONTROL_ERROR" envDefault:"60"`
}
type OutputFormat ¶
type PngCompression ¶
type Server ¶
type Server struct {
// All values are milliseconds. Zero disables the timeout, which is the
// standard library default and the reason a slow client could previously
// hold a connection open for as long as it liked.
ReadHeaderTimeout int `env:"DIMS_READ_HEADER_TIMEOUT" envDefault:"5000"`
ReadTimeout int `env:"DIMS_READ_TIMEOUT" envDefault:"15000"`
WriteTimeout int `env:"DIMS_WRITE_TIMEOUT" envDefault:"60000"`
IdleTimeout int `env:"DIMS_IDLE_TIMEOUT" envDefault:"120000"`
ShutdownTimeout int `env:"DIMS_SHUTDOWN_TIMEOUT" envDefault:"30000"`
MaxHeaderBytes int `env:"DIMS_MAX_HEADER_BYTES" envDefault:"65536"`
}
type SourceBackend ¶ added in v0.6.0
type StatusError ¶
func NewStatusError ¶
func NewStatusError(statusCode int, message string) *StatusError
func (*StatusError) Error ¶
func (e *StatusError) Error() string
type Vips ¶
type Vips struct {
// ConcurrencyLevel is how many threads libvips uses inside one operation.
// Raise it on a host with spare cores. A negative value keeps the libvips
// default.
ConcurrencyLevel int `env:"DIMS_VIPS_CONCURRENCY" envDefault:"1"`
// MaxCacheMem is the largest amount of memory the operation cache holds,
// in bytes.
MaxCacheMem int `env:"DIMS_VIPS_MAX_CACHE_MEM" envDefault:"52428800"`
// MaxCacheSize is how many operations the cache holds.
MaxCacheSize int `env:"DIMS_VIPS_MAX_CACHE_SIZE" envDefault:"100"`
// MaxCacheFiles is how many open files the cache holds.
MaxCacheFiles int `env:"DIMS_VIPS_MAX_CACHE_FILES" envDefault:"0"`
}