Преглед изворни кода

Rename RawAPIKey -> APIKey in GUIConfiguration

Jakob Borg пре 9 година
родитељ
комит
e93c766c42
4 измењених фајлова са 8 додато и 8 уклоњено
  1. 1 1
      cmd/syncthing/main.go
  2. 2 2
      lib/config/config.go
  3. 1 1
      lib/config/config_test.go
  4. 4 4
      lib/config/guiconfiguration.go

+ 1 - 1
cmd/syncthing/main.go

@@ -480,7 +480,7 @@ func upgradeViaRest() error {
 	cfg, _ := loadConfig()
 	cfg, _ := loadConfig()
 	target := cfg.GUI().URL()
 	target := cfg.GUI().URL()
 	r, _ := http.NewRequest("POST", target+"/rest/system/upgrade", nil)
 	r, _ := http.NewRequest("POST", target+"/rest/system/upgrade", nil)
-	r.Header.Set("X-API-Key", cfg.GUI().RawAPIKey)
+	r.Header.Set("X-API-Key", cfg.GUI().APIKey)
 
 
 	tr := &http.Transport{
 	tr := &http.Transport{
 		Dial:            dialer.Dial,
 		Dial:            dialer.Dial,

+ 2 - 2
lib/config/config.go

@@ -229,8 +229,8 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
 		cfg.Options.ReconnectIntervalS = 5
 		cfg.Options.ReconnectIntervalS = 5
 	}
 	}
 
 
-	if cfg.GUI.RawAPIKey == "" {
-		cfg.GUI.RawAPIKey = randomString(32)
+	if cfg.GUI.APIKey == "" {
+		cfg.GUI.APIKey = randomString(32)
 	}
 	}
 }
 }
 
 

+ 1 - 1
lib/config/config_test.go

@@ -485,7 +485,7 @@ func TestCopy(t *testing.T) {
 	cfg.Devices[0].Addresses[0] = "wrong"
 	cfg.Devices[0].Addresses[0] = "wrong"
 	cfg.Folders[0].Devices[0].DeviceID = protocol.DeviceID{0, 1, 2, 3}
 	cfg.Folders[0].Devices[0].DeviceID = protocol.DeviceID{0, 1, 2, 3}
 	cfg.Options.ListenAddress[0] = "wrong"
 	cfg.Options.ListenAddress[0] = "wrong"
-	cfg.GUI.RawAPIKey = "wrong"
+	cfg.GUI.APIKey = "wrong"
 
 
 	bsChanged, err := json.MarshalIndent(cfg, "", "  ")
 	bsChanged, err := json.MarshalIndent(cfg, "", "  ")
 	if err != nil {
 	if err != nil {

+ 4 - 4
lib/config/guiconfiguration.go

@@ -18,7 +18,7 @@ type GUIConfiguration struct {
 	User                string `xml:"user,omitempty" json:"user"`
 	User                string `xml:"user,omitempty" json:"user"`
 	Password            string `xml:"password,omitempty" json:"password"`
 	Password            string `xml:"password,omitempty" json:"password"`
 	RawUseTLS           bool   `xml:"tls,attr" json:"useTLS"`
 	RawUseTLS           bool   `xml:"tls,attr" json:"useTLS"`
-	RawAPIKey           string `xml:"apikey,omitempty" json:"apiKey"`
+	APIKey              string `xml:"apikey,omitempty" json:"apiKey"`
 	InsecureAdminAccess bool   `xml:"insecureAdminAccess,omitempty" json:"insecureAdminAccess"`
 	InsecureAdminAccess bool   `xml:"insecureAdminAccess,omitempty" json:"insecureAdminAccess"`
 	Theme               string `xml:"theme" json:"theme" default:"default"`
 	Theme               string `xml:"theme" json:"theme" default:"default"`
 }
 }
@@ -76,14 +76,14 @@ func (c GUIConfiguration) URL() string {
 	return u.String()
 	return u.String()
 }
 }
 
 
-// Returns whether the given API key is valid, including both the value in config
-// and any overrides
+// IsValidAPIKey returns true when the given API key is valid, including both
+// the value in config and any overrides
 func (c GUIConfiguration) IsValidAPIKey(apiKey string) bool {
 func (c GUIConfiguration) IsValidAPIKey(apiKey string) bool {
 	switch apiKey {
 	switch apiKey {
 	case "":
 	case "":
 		return false
 		return false
 
 
-	case c.RawAPIKey, os.Getenv("STGUIAPIKEY"):
+	case c.APIKey, os.Getenv("STGUIAPIKEY"):
 		return true
 		return true
 
 
 	default:
 	default: