mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-04-26 21:36:24 +02:00
add support for multiple signature keys (#209)
This commit is contained in:
parent
3bdd0fe8ed
commit
ef09c1ba31
3 changed files with 44 additions and 21 deletions
|
|
@ -48,7 +48,7 @@ var denyHosts = flag.String("denyHosts", "", "comma separated list of denied rem
|
|||
var referrers = flag.String("referrers", "", "comma separated list of allowed referring hosts")
|
||||
var baseURL = flag.String("baseURL", "", "default base URL for relative remote URLs")
|
||||
var cache tieredCache
|
||||
var signatureKey = flag.String("signatureKey", "", "HMAC key used in calculating request signatures")
|
||||
var signatureKeyList SignatureKeyList
|
||||
var scaleUp = flag.Bool("scaleUp", false, "allow images to scale beyond their original dimensions")
|
||||
var timeout = flag.Duration("timeout", 0, "time limit for requests served by this proxy")
|
||||
var verbose = flag.Bool("verbose", false, "print verbose logging messages")
|
||||
|
|
@ -58,6 +58,7 @@ var userAgent = flag.String("userAgent", "willnorris/imageproxy", "specify the u
|
|||
|
||||
func init() {
|
||||
flag.Var(&cache, "cache", "location to cache images (see https://github.com/willnorris/imageproxy#cache)")
|
||||
flag.Var(&signatureKeyList, "signatureKey", "HMAC key used in calculating request signatures")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
@ -77,18 +78,7 @@ func main() {
|
|||
if *contentTypes != "" {
|
||||
p.ContentTypes = strings.Split(*contentTypes, ",")
|
||||
}
|
||||
if *signatureKey != "" {
|
||||
key := []byte(*signatureKey)
|
||||
if strings.HasPrefix(*signatureKey, "@") {
|
||||
file := strings.TrimPrefix(*signatureKey, "@")
|
||||
var err error
|
||||
key, err = ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
log.Fatalf("error reading signature file: %v", err)
|
||||
}
|
||||
}
|
||||
p.SignatureKey = key
|
||||
}
|
||||
p.SignatureKeys = signatureKeyList
|
||||
if *baseURL != "" {
|
||||
var err error
|
||||
p.DefaultBaseURL, err = url.Parse(*baseURL)
|
||||
|
|
@ -112,6 +102,27 @@ func main() {
|
|||
log.Fatal(http.ListenAndServe(*addr, nil))
|
||||
}
|
||||
|
||||
type SignatureKeyList [][]byte
|
||||
|
||||
func (skl *SignatureKeyList) String() string {
|
||||
return fmt.Sprint(*skl)
|
||||
}
|
||||
|
||||
func (skl *SignatureKeyList) Set(value string) error {
|
||||
key := []byte(value)
|
||||
if strings.HasPrefix(value, "@") {
|
||||
file := strings.TrimPrefix(value, "@")
|
||||
var err error
|
||||
key, err = ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
log.Fatalf("error reading signature file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
*skl = append(*skl, key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// tieredCache allows specifying multiple caches via flags, which will create
|
||||
// tiered caches using the twotier package.
|
||||
type tieredCache struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue