@@ -69,23 +69,24 @@ type responseStruct struct {
6969}
7070
7171type 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
9192func 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
212214func (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) {
420426func 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