Skip to content

Commit 5702d5a

Browse files
committed
Merge branch 'amcintosh-post-to-terminate'
2 parents 675be30 + 0735035 commit 5702d5a

File tree

3 files changed

+69
-43
lines changed

3 files changed

+69
-43
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ https://github.com/diranged
2424
https://github.com/em0ney
2525
https://github.com/zqben402
2626
https://github.com/dlackty
27+
https://github.com/amcintosh
2728

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ For a full list of available options, use `-h`:
124124
```sh
125125
./aws-es-proxy -h
126126
Usage of ./aws-es-proxy:
127+
-auth
128+
Require HTTP Basic Auth
129+
-debug
130+
Print debug messages
127131
-endpoint string
128132
Amazon ElasticSearch Endpoint (e.g: https://dummy-host.eu-west-1.es.amazonaws.com)
129133
-listen string
@@ -132,10 +136,22 @@ Usage of ./aws-es-proxy:
132136
Log user requests and ElasticSearch responses to files
133137
-no-sign-reqs
134138
Disable AWS Signature v4
139+
-password string
140+
HTTP Basic Auth Password
135141
-pretty
136142
Prettify verbose and file output
143+
-realm string
144+
Authentication Required
145+
-remote-terminate
146+
Allow HTTP remote termination
147+
-timeout int
148+
Set a request timeout to ES. Specify in seconds, defaults to 15 (default 15)
149+
-username string
150+
HTTP Basic Auth Username
137151
-verbose
138152
Print user requests
153+
-version
154+
Print aws-es-proxy version
139155
```
140156

141157

aws-es-proxy.go

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,24 @@ type responseStruct struct {
6969
}
7070

7171
type proxy struct {
72-
scheme string
73-
host string
74-
region string
75-
service string
76-
endpoint string
77-
verbose bool
78-
prettify bool
79-
logtofile bool
80-
nosignreq bool
81-
fileRequest *os.File
82-
fileResponse *os.File
83-
credentials *credentials.Credentials
84-
httpClient *http.Client
85-
auth bool
86-
username string
87-
password string
88-
realm string
72+
scheme string
73+
host string
74+
region string
75+
service string
76+
endpoint string
77+
verbose bool
78+
prettify bool
79+
logtofile bool
80+
nosignreq bool
81+
fileRequest *os.File
82+
fileResponse *os.File
83+
credentials *credentials.Credentials
84+
httpClient *http.Client
85+
auth bool
86+
username string
87+
password string
88+
realm string
89+
remoteTerminate bool
8990
}
9091

9192
func newProxy(args ...interface{}) *proxy {
@@ -100,16 +101,17 @@ func newProxy(args ...interface{}) *proxy {
100101
}
101102

102103
return &proxy{
103-
endpoint: args[0].(string),
104-
verbose: args[1].(bool),
105-
prettify: args[2].(bool),
106-
logtofile: args[3].(bool),
107-
nosignreq: args[4].(bool),
108-
httpClient: &client,
109-
auth: args[6].(bool),
110-
username: args[7].(string),
111-
password: args[8].(string),
112-
realm: args[9].(string),
104+
endpoint: args[0].(string),
105+
verbose: args[1].(bool),
106+
prettify: args[2].(bool),
107+
logtofile: args[3].(bool),
108+
nosignreq: args[4].(bool),
109+
httpClient: &client,
110+
auth: args[6].(bool),
111+
username: args[7].(string),
112+
password: args[8].(string),
113+
realm: args[9].(string),
114+
remoteTerminate: args[10].(bool),
113115
}
114116
}
115117

@@ -210,6 +212,10 @@ func (p *proxy) getSigner() *v4.Signer {
210212
}
211213

212214
func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
215+
if p.remoteTerminate && r.URL.Path == "/terminate-proxy" && r.Method == http.MethodPost {
216+
logrus.Infoln("Terminate Signal")
217+
os.Exit(0)
218+
}
213219

214220
if p.auth {
215221
user, pass, ok := r.BasicAuth()
@@ -420,22 +426,23 @@ func copyHeaders(dst, src http.Header) {
420426
func main() {
421427

422428
var (
423-
debug bool
424-
auth bool
425-
username string
426-
password string
427-
realm string
428-
verbose bool
429-
prettify bool
430-
logtofile bool
431-
nosignreq bool
432-
ver bool
433-
endpoint string
434-
listenAddress string
435-
fileRequest *os.File
436-
fileResponse *os.File
437-
err error
438-
timeout int
429+
debug bool
430+
auth bool
431+
username string
432+
password string
433+
realm string
434+
verbose bool
435+
prettify bool
436+
logtofile bool
437+
nosignreq bool
438+
ver bool
439+
endpoint string
440+
listenAddress string
441+
fileRequest *os.File
442+
fileResponse *os.File
443+
err error
444+
timeout int
445+
remoteTerminate bool
439446
)
440447

441448
flag.StringVar(&endpoint, "endpoint", "", "Amazon ElasticSearch Endpoint (e.g: https://dummy-host.eu-west-1.es.amazonaws.com)")
@@ -451,6 +458,7 @@ func main() {
451458
flag.StringVar(&username, "username", "", "HTTP Basic Auth Username")
452459
flag.StringVar(&password, "password", "", "HTTP Basic Auth Password")
453460
flag.StringVar(&realm, "realm", "", "Authentication Required")
461+
flag.BoolVar(&remoteTerminate, "remote-terminate", false, "Allow HTTP remote termination")
454462
flag.Parse()
455463

456464
if endpoint == "" {
@@ -496,6 +504,7 @@ func main() {
496504
username,
497505
password,
498506
realm,
507+
remoteTerminate,
499508
)
500509

501510
if err = p.parseEndpoint(); err != nil {

0 commit comments

Comments
 (0)