From 5ab84b66556797d48383522c8621c9d4a97335c0 Mon Sep 17 00:00:00 2001 From: 1fexd Date: Thu, 23 Apr 2026 07:32:08 +0200 Subject: [PATCH] Add option to use proxy --- internal/state/config/options.go | 9 +++++++++ internal/state/state.go | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/internal/state/config/options.go b/internal/state/config/options.go index 7f9c21d69..071d04cc9 100644 --- a/internal/state/config/options.go +++ b/internal/state/config/options.go @@ -169,6 +169,15 @@ var ( nil, ) + OptionProxy = newOpt( + "proxy", + "A proxy url to use", + "", + DefaultPreferenceFlags, + nil, + nil, + ) + OptionQuiet = newOpt( "quiet", "If true, only print error messages", diff --git a/internal/state/state.go b/internal/state/state.go index 4e883c93d..c79fcb50e 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "net/url" "os" "strings" "time" @@ -135,6 +136,18 @@ func (c *state) newClient() (hcapi2.Client, error) { })) } + proxyUrlStr, err := config.OptionProxy.Get(c.config) + if err != nil { + return nil, err + } + if len(proxyUrlStr) > 0 { + proxyUrl, err := url.Parse(proxyUrlStr) + if err != nil { + return nil, err + } + opts = append(opts, hcloud.WithProxy(proxyUrl)) + } + return hcapi2.NewClient(opts...), nil }