forked from h2non/imaginary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpslurp_changes.diff
172 lines (154 loc) · 5.55 KB
/
pslurp_changes.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
diff --git a/Dockerfile b/Dockerfile
index a4e3f4a..aa0fde4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,7 +1,7 @@
ARG GOLANG="1.11.5"
FROM golang:${GOLANG} as builder
-ARG IMAGINARY_VERSION="dev"
+ARG IMAGINARY_VERSION="1.1.1"
ARG LIBVIPS_VERSION="8.7.4"
ARG GOLANG
@@ -60,7 +60,7 @@ FROM debian:stretch-slim
ARG IMAGINARY_VERSION
-LABEL maintainer="[email protected]" \
+LABEL maintainer="[email protected]" \
org.label-schema.description="Fast, simple, scalable HTTP microservice for high-level image processing with first-class Docker support" \
org.label-schema.schema-version="1.0" \
org.label-schema.url="https://github.com/h2non/imaginary" \
diff --git a/Makefile b/Makefile
index be99809..e79cf3b 100644
--- a/Makefile
+++ b/Makefile
@@ -16,11 +16,11 @@ benchmark: build
docker-build:
@echo "$(OK_COLOR)==> Building Docker image$(NO_COLOR)"
- docker build --no-cache=true -t h2non/imaginary:$(VERSION) .
+ docker build --no-cache=true -t pslurp/imaginary:$(VERSION) .
docker-push:
@echo "$(OK_COLOR)==> Pushing Docker image v$(VERSION) $(NO_COLOR)"
- docker push h2non/imaginary:$(VERSION)
+ docker push pslurp/imaginary:$(VERSION)
docker: docker-build docker-push
diff --git a/imaginary.go b/imaginary.go
index f38da13..0760a8f 100644
--- a/imaginary.go
+++ b/imaginary.go
@@ -48,6 +48,8 @@ var (
aBurst = flag.Int("burst", 100, "Throttle burst max cache size")
aMRelease = flag.Int("mrelease", 30, "OS memory release interval in seconds")
aCpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "Number of cpu cores to use")
+ aIgnoreCertErrors = flag.Bool("ignore-cert-errors", false, "Disables certificate checks for remote images")
+ aUserAgent = flag.String("user-agent", "imaginary/"+Version, "User-Agent to send to remote sources")
)
const usage = `imaginary %s
@@ -100,6 +102,8 @@ Options:
-mrelease <num> OS memory release interval in seconds [default: 30]
-cpus <num> Number of used cpu cores.
(default for current machine is %d cores)
+ -ignore-cert-errors Disables certificate checks for remote images
+ -user-agent User-Agent to send to remote sources
`
type URLSignature struct {
@@ -149,6 +153,8 @@ func main() {
ForwardHeaders: parseForwardHeaders(*aForwardHeaders),
AllowedOrigins: parseOrigins(*aAllowedOrigins),
MaxAllowedSize: *aMaxAllowedSize,
+ IgnoreCertErrors: *aIgnoreCertErrors,
+ UserAgent: *aUserAgent,
}
// Show warning if gzip flag is passed
diff --git a/server.go b/server.go
index 6e35ca9..729d3ad 100644
--- a/server.go
+++ b/server.go
@@ -37,6 +37,8 @@ type ServerOptions struct {
PlaceholderImage []byte
Endpoints Endpoints
AllowedOrigins []*url.URL
+ IgnoreCertErrors bool
+ UserAgent string
}
// Endpoints represents a list of endpoint names to disable.
diff --git a/source.go b/source.go
index 572e6aa..72b73e5 100644
--- a/source.go
+++ b/source.go
@@ -16,6 +16,8 @@ type SourceConfig struct {
ForwardHeaders []string
AllowedOrigins []*url.URL
MaxAllowedSize int
+ IgnoreCertErrors bool
+ UserAgent string
}
var imageSourceMap = make(map[ImageSourceType]ImageSource)
@@ -40,6 +42,8 @@ func LoadSources(o ServerOptions) {
AllowedOrigins: o.AllowedOrigins,
MaxAllowedSize: o.MaxAllowedSize,
ForwardHeaders: o.ForwardHeaders,
+ IgnoreCertErrors: o.IgnoreCertErrors,
+ UserAgent: o.UserAgent,
})
}
}
diff --git a/source_http.go b/source_http.go
index 6cdbbd5..409c132 100644
--- a/source_http.go
+++ b/source_http.go
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
+ "crypto/tls"
"strconv"
"strings"
)
@@ -39,7 +40,14 @@ func (s *HTTPImageSource) fetchImage(url *url.URL, ireq *http.Request) ([]byte,
// Check remote image size by fetching HTTP Headers
if s.Config.MaxAllowedSize > 0 {
req := newHTTPRequest(s, ireq, http.MethodHead, url)
- res, err := http.DefaultClient.Do(req)
+ client := *http.DefaultClient
+ if s.Config.IgnoreCertErrors {
+ tr := &http.Transport{
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+ }
+ client = http.Client{Transport: tr}
+ }
+ res, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("error fetching image http headers: %v", err)
}
@@ -56,7 +64,14 @@ func (s *HTTPImageSource) fetchImage(url *url.URL, ireq *http.Request) ([]byte,
// Perform the request using the default client
req := newHTTPRequest(s, ireq, http.MethodGet, url)
- res, err := http.DefaultClient.Do(req)
+ client := *http.DefaultClient
+ if s.Config.IgnoreCertErrors {
+ tr := &http.Transport{
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+ }
+ client = http.Client{Transport: tr}
+ }
+ res, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("error downloading image: %v", err)
}
@@ -101,7 +116,7 @@ func parseURL(request *http.Request) (*url.URL, error) {
func newHTTPRequest(s *HTTPImageSource, ireq *http.Request, method string, url *url.URL) *http.Request {
req, _ := http.NewRequest(method, url.String(), nil)
- req.Header.Set("User-Agent", "imaginary/"+Version)
+ req.Header.Set("User-Agent", s.Config.UserAgent)
req.URL = url
if len(s.Config.ForwardHeaders) != 0 {
diff --git a/version.go b/version.go
index 75eb4f7..5491fa2 100644
--- a/version.go
+++ b/version.go
@@ -1,7 +1,7 @@
package main
// Version stores the current package semantic version
-var Version = "dev"
+var Version = "1.1.1"
// Versions represents the used versions for several significant dependencies
type Versions struct {