socks5 support (#2543)

* socks5 support

socks5 support via environment variable, e.g. SOCKS5_PROXY=localhost:1080 yay ...

* use default transport and update tests to work on arm
This commit is contained in:
dmitrodem
2024-12-20 19:49:05 +03:00
committed by GitHub
parent da53d3855f
commit 3f2f6eae31
4 changed files with 22 additions and 1 deletions

View File

@@ -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"},

View File

@@ -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"))
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 {
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)