Skip to content
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

Code cleanup #2

Merged
merged 4 commits into from
Oct 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleaning up code, moving insecure logic to main function (TODO: still…
… need to test)
DustinKLo committed Oct 17, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 88a70862dd53143ba415900d505830bbcf243d9e
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -2,4 +2,5 @@
vendor
glide.lock
dist
.idea
.idea
aws-es-proxy
27 changes: 7 additions & 20 deletions aws-es-proxy.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,6 @@ import (
)

func logger(debug bool) {

formatFilePath := func(path string) string {
arr := strings.Split(path, "/")
return arr[len(arr)-1]
@@ -87,7 +86,6 @@ type proxy struct {
password string
realm string
remoteTerminate bool
insecure bool
}

func newProxy(args ...interface{}) *proxy {
@@ -101,12 +99,6 @@ func newProxy(args ...interface{}) *proxy {
CheckRedirect: noRedirect,
}

if args[12].(bool) == true {
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}

return &proxy{
endpoint: args[0].(string),
verbose: args[1].(bool),
@@ -120,7 +112,7 @@ func newProxy(args ...interface{}) *proxy {
realm: args[9].(string),
remoteTerminate: args[10].(bool),
region: args[11].(string),
insecure: args[12].(bool),
service: "es",
}
}

@@ -156,14 +148,9 @@ func (p *proxy) parseEndpoint() error {
p.scheme = link.Scheme
p.host = link.Host

p.service = "es"
logrus.Debugln("AWS Region", p.region)

// AWS SignV4 enabled, extract required parts for signing process
if !p.nosignreq {

split := strings.SplitAfterN(link.Hostname(), ".", 2)

if len(split) < 2 {
logrus.Debugln("Endpoint split is less than 2")
}
@@ -175,7 +162,6 @@ func (p *proxy) parseEndpoint() error {
func (p *proxy) getSigner() *v4.Signer {
// Refresh credentials after expiration. Required for STS
if p.credentials == nil {

sess, err := session.NewSession(
&aws.Config{
Region: aws.String(p.region),
@@ -342,7 +328,6 @@ func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

if p.logtofile {

requestID := primitive.NewObjectID().Hex()

reqStruct := &requestStruct{
@@ -408,7 +393,6 @@ func copyHeaders(dst, src http.Header) {
dst.Add(k, v)
}
}

}
}

@@ -499,16 +483,20 @@ func main() {
realm,
remoteTerminate,
region,
insecure,
)

if insecure == true {
p.httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}

if err = p.parseEndpoint(); err != nil {
logrus.Fatalln(err)
os.Exit(1)
}

if p.logtofile {

requestFname := fmt.Sprintf("request-%s.log", primitive.NewObjectID().Hex())
if fileRequest, err = os.Create(requestFname); err != nil {
log.Fatalln(err.Error())
@@ -523,7 +511,6 @@ func main() {

p.fileRequest = fileRequest
p.fileResponse = fileResponse

}

logrus.Infof("Listening on %s...\n", listenAddress)