From 06d3929dcb0137bd9d8663f787fda7dda79a6cf6 Mon Sep 17 00:00:00 2001 From: Dmitriy Dyomin Date: Tue, 3 Dec 2024 22:05:22 +0300 Subject: [PATCH] socks5 support socks5 support via environment variable, e.g. SOCKS5_PROXY=localhost:1080 yay ... --- go.mod | 1 + go.sum | 1 + pkg/runtime/runtime.go | 12 ++++++++++++ 3 files changed, 14 insertions(+) diff --git a/go.mod b/go.mod index f049c99d3..1a5760acb 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 github.com/leonelquinteros/gotext v1.5.2 github.com/stretchr/testify v1.9.0 + golang.org/x/net v0.0.0-20220722155237-a158d28d115b golang.org/x/sys v0.18.0 golang.org/x/term v0.18.0 gopkg.in/h2non/gock.v1 v1.1.2 diff --git a/go.sum b/go.sum index a4cdd86a2..362e8252b 100644 --- a/go.sum +++ b/go.sum @@ -59,6 +59,7 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 499ee4f08..f1a8278c4 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -21,6 +21,8 @@ import ( "github.com/Jguer/aur/rpc" "github.com/Jguer/votar/pkg/vote" "github.com/Morganamilo/go-pacmanconf" + + "golang.org/x/net/proxy" ) type Runtime struct { @@ -39,10 +41,20 @@ func NewRuntime(cfg *settings.Configuration, cmdArgs *parser.Arguments, version logger := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, cfg.Debug, "runtime") runner := exe.NewOSRunner(logger.Child("runner")) + var transport = &http.Transport{} + if socks5_proxy := os.Getenv("SOCKS5_PROXY"); socks5_proxy != "" { + dialer, err := proxy.SOCKS5("tcp", socks5_proxy, nil, proxy.Direct) + if err != nil { + return nil, err + } + transport = &http.Transport{Dial: dialer.Dial} + } + httpClient := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, + Transport: transport, } userAgent := fmt.Sprintf("Yay/%s", version)