Skip to content

Commit 1dab88d

Browse files
committed
Proxy configuration is now part of Configuration struct
1 parent 7f6e96f commit 1dab88d

File tree

5 files changed

+29
-47
lines changed

5 files changed

+29
-47
lines changed

Diff for: configs/configuration.go

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ type Configuration struct {
4646

4747
// BoardManagerAdditionalUrls contains the additional URL for 3rd party packages
4848
BoardManagerAdditionalUrls []*url.URL
49+
50+
// ProxyType is the type of proxy configured
51+
ProxyType string
52+
53+
// ProxyHostname is the proxy hostname
54+
ProxyHostname string
55+
56+
// ProxyUsername is the proxy user
57+
ProxyUsername string
58+
59+
// ProxyPassword is the proxy password
60+
ProxyPassword string
4961
}
5062

5163
var defaultPackageIndexURL, _ = url.Parse("https://downloads.arduino.cc/packages/package_index.json")
@@ -66,6 +78,7 @@ func NewConfiguration() (*Configuration, error) {
6678
DataDir: dataDir,
6779
SketchbookDir: sketchbookDir,
6880
BoardManagerAdditionalUrls: []*url.URL{defaultPackageIndexURL},
81+
ProxyType: "auto",
6982
}, nil
7083
}
7184

Diff for: configs/env_vars_serializer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
// LoadFromEnv read configurations from the environment variables
2727
func (config *Configuration) LoadFromEnv() {
2828
if p, has := os.LookupEnv("PROXY_TYPE"); has {
29-
ProxyType = p
29+
config.ProxyType = p
3030
}
3131
if dir, has := os.LookupEnv("ARDUINO_SKETCHBOOK_DIR"); has {
3232
config.SketchbookDir = paths.New(dir)

Diff for: configs/preferences_txt_serializer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (config *Configuration) LoadFromDesktopIDEPreferences() error {
7676
logrus.WithError(err).Warn("Error during unserialize from IDE preferences")
7777
return err
7878
}
79-
err = proxyConfigsFromIDEPrefs(props)
79+
err = config.proxyConfigsFromIDEPrefs(props)
8080
if err != nil {
8181
logrus.WithError(err).Warn("Error during unserialize from IDE preferences")
8282
return err
@@ -94,7 +94,7 @@ func (config *Configuration) LoadFromDesktopIDEPreferences() error {
9494
return nil
9595
}
9696

97-
func proxyConfigsFromIDEPrefs(props *properties.Map) error {
97+
func (config *Configuration) proxyConfigsFromIDEPrefs(props *properties.Map) error {
9898
proxy := props.SubTree("proxy")
9999
switch proxy.Get("type") {
100100
case "auto":
@@ -110,10 +110,10 @@ func proxyConfigsFromIDEPrefs(props *properties.Map) error {
110110
username := manualConfig.Get("username")
111111
password := manualConfig.Get("password")
112112

113-
ProxyType = "manual"
114-
ProxyHostname = hostname
115-
ProxyUsername = username
116-
ProxyPassword = password
113+
config.ProxyType = "manual"
114+
config.ProxyHostname = hostname
115+
config.ProxyUsername = username
116+
config.ProxyPassword = password
117117
break
118118
case "none":
119119
// No proxy

Diff for: configs/proxy.go

-31
This file was deleted.

Diff for: configs/yaml_serializer.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func (config *Configuration) LoadFromYAML(path *paths.Path) error {
6767
config.SketchbookDir = paths.New(ret.SketchbookPath)
6868
}
6969
if ret.ProxyType != "" {
70-
ProxyType = ret.ProxyType
70+
config.ProxyType = ret.ProxyType
7171
if ret.ProxyManualConfig != nil {
72-
ProxyHostname = ret.ProxyManualConfig.Hostname
73-
ProxyUsername = ret.ProxyManualConfig.Username
74-
ProxyPassword = ret.ProxyManualConfig.Password
72+
config.ProxyHostname = ret.ProxyManualConfig.Hostname
73+
config.ProxyUsername = ret.ProxyManualConfig.Username
74+
config.ProxyPassword = ret.ProxyManualConfig.Password
7575
}
7676
}
7777
if ret.BoardsManager != nil {
@@ -96,12 +96,12 @@ func (config *Configuration) SerializeToYAML() ([]byte, error) {
9696
if config.DataDir != nil {
9797
c.ArduinoDataDir = config.DataDir.String()
9898
}
99-
c.ProxyType = ProxyType
100-
if ProxyType == "manual" {
99+
c.ProxyType = config.ProxyType
100+
if config.ProxyType == "manual" {
101101
c.ProxyManualConfig = &yamlProxyConfig{
102-
Hostname: ProxyHostname,
103-
Username: ProxyUsername,
104-
Password: ProxyPassword,
102+
Hostname: config.ProxyHostname,
103+
Username: config.ProxyUsername,
104+
Password: config.ProxyPassword,
105105
}
106106
}
107107
if len(config.BoardManagerAdditionalUrls) > 1 {

0 commit comments

Comments
 (0)