From 06d3929dcb0137bd9d8663f787fda7dda79a6cf6 Mon Sep 17 00:00:00 2001 From: Dmitriy Dyomin Date: Tue, 3 Dec 2024 22:05:22 +0300 Subject: [PATCH 1/2] 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) From ddf623321041046697e2dc67f867aa28121192d9 Mon Sep 17 00:00:00 2001 From: Jo Garnier Date: Fri, 20 Dec 2024 16:39:57 +0000 Subject: [PATCH 2/2] use default transport and update tests to work on arm --- pkg/runtime/pacman_test.go | 9 ++++++++- pkg/runtime/runtime.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/runtime/pacman_test.go b/pkg/runtime/pacman_test.go index 23f7fbc0b..d494f5d35 100644 --- a/pkg/runtime/pacman_test.go +++ b/pkg/runtime/pacman_test.go @@ -5,6 +5,7 @@ package runtime import ( "path/filepath" + "runtime" "testing" "github.com/Morganamilo/go-pacmanconf" @@ -21,13 +22,19 @@ func TestPacmanConf(t *testing.T) { absPath, err := filepath.Abs(path) require.NoError(t, err) + // detect the architecture of the system + expectedArch := []string{"x86_64"} + if runtime.GOARCH == "arm64" { + expectedArch = []string{"aarch64"} + } + expectedPacmanConf := &pacmanconf.Config{ RootDir: "/", DBPath: "/var/lib/pacman/", CacheDir: []string{"/var/cache/pacman/pkg/"}, HookDir: []string{"/etc/pacman.d/hooks/"}, GPGDir: "/etc/pacman.d/gnupg/", LogFile: "/var/log/pacman.log", HoldPkg: []string{"pacman", "glibc"}, IgnorePkg: []string{"xorm"}, - IgnoreGroup: []string{"yorm"}, Architecture: []string{"x86_64"}, + IgnoreGroup: []string{"yorm"}, Architecture: expectedArch, XferCommand: "/usr/bin/wget --passive-ftp -c -O %o %u", NoUpgrade: []string(nil), NoExtract: []string(nil), CleanMethod: []string{"KeepInstalled"}, SigLevel: []string{"PackageRequired", "PackageTrustedOnly", "DatabaseOptional", "DatabaseTrustedOnly"}, diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index f1a8278c4..e0f5abb23 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -41,7 +41,7 @@ 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{} + transport := http.DefaultTransport.(*http.Transport).Clone() if socks5_proxy := os.Getenv("SOCKS5_PROXY"); socks5_proxy != "" { dialer, err := proxy.SOCKS5("tcp", socks5_proxy, nil, proxy.Direct) if err != nil {