Skip to content

Commit

Permalink
add HTTPS_PROXY handle
Browse files Browse the repository at this point in the history
  • Loading branch information
computable-contracts-devops committed Jul 11, 2023
1 parent 59561aa commit 886f26d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"net/http"
netUrl "net/url"
"os"
"strings"

Expand All @@ -20,10 +21,27 @@ type roundTripper struct {

func (rt roundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
r.Header.Set("Authorization", fmt.Sprintf("token %s", rt.accessToken))
transport := http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: rt.insecure}}
transport := rt.getTransport()
return transport.RoundTrip(r)
}

func (rt roundTripper) getTransport() *http.Transport {
proxyURLStr := os.Getenv("HTTPS_PROXY")
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: rt.insecure},
}

if proxyURLStr != "" {
proxyURL, err := netUrl.Parse(proxyURLStr)
if err != nil {
log.Fatal("failed to parse HTTPS_PROXY:", err)
}
transport.Proxy = http.ProxyURL(proxyURL)
}

return transport
}

func isValidState(state string) bool {
validStates := [4]string{"error", "failure", "pending", "success"}
for _, s := range validStates {
Expand Down

0 comments on commit 886f26d

Please sign in to comment.