-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle termination HTTP signal #78
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,23 +69,24 @@ type responseStruct struct { | |
} | ||
|
||
type proxy struct { | ||
scheme string | ||
host string | ||
region string | ||
service string | ||
endpoint string | ||
verbose bool | ||
prettify bool | ||
logtofile bool | ||
nosignreq bool | ||
fileRequest *os.File | ||
fileResponse *os.File | ||
credentials *credentials.Credentials | ||
httpClient *http.Client | ||
auth bool | ||
username string | ||
password string | ||
realm string | ||
scheme string | ||
host string | ||
region string | ||
service string | ||
endpoint string | ||
verbose bool | ||
prettify bool | ||
logtofile bool | ||
nosignreq bool | ||
fileRequest *os.File | ||
fileResponse *os.File | ||
credentials *credentials.Credentials | ||
httpClient *http.Client | ||
auth bool | ||
username string | ||
password string | ||
realm string | ||
remoteTerminate bool | ||
} | ||
|
||
func newProxy(args ...interface{}) *proxy { | ||
|
@@ -100,16 +101,17 @@ func newProxy(args ...interface{}) *proxy { | |
} | ||
|
||
return &proxy{ | ||
endpoint: args[0].(string), | ||
verbose: args[1].(bool), | ||
prettify: args[2].(bool), | ||
logtofile: args[3].(bool), | ||
nosignreq: args[4].(bool), | ||
httpClient: &client, | ||
auth: args[6].(bool), | ||
username: args[7].(string), | ||
password: args[8].(string), | ||
realm: args[9].(string), | ||
endpoint: args[0].(string), | ||
verbose: args[1].(bool), | ||
prettify: args[2].(bool), | ||
logtofile: args[3].(bool), | ||
nosignreq: args[4].(bool), | ||
httpClient: &client, | ||
auth: args[6].(bool), | ||
username: args[7].(string), | ||
password: args[8].(string), | ||
realm: args[9].(string), | ||
remoteTerminate: args[10].(bool), | ||
} | ||
} | ||
|
||
|
@@ -210,6 +212,10 @@ func (p *proxy) getSigner() *v4.Signer { | |
} | ||
|
||
func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
if p.remoteTerminate && r.URL.Path == "/terminate-proxy" && r.Method == http.MethodPost { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did you land on using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to terminate on a GET and while I considered DELETE, this isn't exactly restful, so I figured POST to be the most intuitive. |
||
logrus.Infoln("Terminate Signal") | ||
os.Exit(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Amazing! ❤️ |
||
} | ||
|
||
if p.auth { | ||
user, pass, ok := r.BasicAuth() | ||
|
@@ -420,22 +426,23 @@ func copyHeaders(dst, src http.Header) { | |
func main() { | ||
|
||
var ( | ||
debug bool | ||
auth bool | ||
username string | ||
password string | ||
realm string | ||
verbose bool | ||
prettify bool | ||
logtofile bool | ||
nosignreq bool | ||
ver bool | ||
endpoint string | ||
listenAddress string | ||
fileRequest *os.File | ||
fileResponse *os.File | ||
err error | ||
timeout int | ||
debug bool | ||
auth bool | ||
username string | ||
password string | ||
realm string | ||
verbose bool | ||
prettify bool | ||
logtofile bool | ||
nosignreq bool | ||
ver bool | ||
endpoint string | ||
listenAddress string | ||
fileRequest *os.File | ||
fileResponse *os.File | ||
err error | ||
timeout int | ||
remoteTerminate bool | ||
) | ||
|
||
flag.StringVar(&endpoint, "endpoint", "", "Amazon ElasticSearch Endpoint (e.g: https://dummy-host.eu-west-1.es.amazonaws.com)") | ||
|
@@ -451,6 +458,7 @@ func main() { | |
flag.StringVar(&username, "username", "", "HTTP Basic Auth Username") | ||
flag.StringVar(&password, "password", "", "HTTP Basic Auth Password") | ||
flag.StringVar(&realm, "realm", "", "Authentication Required") | ||
flag.BoolVar(&remoteTerminate, "remote-terminate", false, "Allow HTTP remote termination") | ||
flag.Parse() | ||
|
||
if endpoint == "" { | ||
|
@@ -496,6 +504,7 @@ func main() { | |
username, | ||
password, | ||
realm, | ||
remoteTerminate, | ||
) | ||
|
||
if err = p.parseEndpoint(); err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😻