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 }