Skip to content
Draft
Changes from all commits
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
20 changes: 16 additions & 4 deletions cmd/localstack/custom_interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ const (
Error LocalStackStatus = "error"
)

// transport with disabled proxy, to avoid issues with customers having proxies configured in their environment
// should be used for all communication with the LocalStack instance
var transport http.RoundTripper = &http.Transport{
Proxy: nil,
}

func (l *LocalStackAdapter) SendStatus(status LocalStackStatus, payload []byte) error {
client := &http.Client{
Transport: transport,
}
Comment on lines +51 to +53
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: perhaps this could be extracted into a helper function or type so every client creation can go through the same code path? We use this struct initialization twice in this change

statusUrl := fmt.Sprintf("%s/status/%s/%s", l.UpstreamEndpoint, l.RuntimeId, status)
_, err := http.Post(statusUrl, "application/json", bytes.NewReader(payload))
_, err := client.Post(statusUrl, "application/json", bytes.NewReader(payload))
if err != nil {
return err
}
Expand Down Expand Up @@ -76,6 +85,9 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate interop.Server, logCollecto
RuntimeId: lsOpts.RuntimeId,
},
}
client := &http.Client{
Transport: transport,
}

// TODO: extract this
go func() {
Expand Down Expand Up @@ -159,7 +171,7 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate interop.Server, logCollecto

serializedLogs, err2 := json.Marshal(logCollector.getLogs())
if err2 == nil {
_, err2 = http.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/logs", "application/json", bytes.NewReader(serializedLogs))
_, err2 = client.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/logs", "application/json", bytes.NewReader(serializedLogs))
// TODO: handle err
}

Expand All @@ -172,13 +184,13 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate interop.Server, logCollecto

if isErr {
log.Infoln("Sending to /error")
_, err = http.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/error", "application/json", bytes.NewReader(invokeResp.Body))
_, err = client.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/error", "application/json", bytes.NewReader(invokeResp.Body))
if err != nil {
log.Error(err)
}
} else {
log.Infoln("Sending to /response")
_, err = http.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/response", "application/json", bytes.NewReader(invokeResp.Body))
_, err = client.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/response", "application/json", bytes.NewReader(invokeResp.Body))
if err != nil {
log.Error(err)
}
Expand Down