Allow configuration of releases URL

This commit is contained in:
Jakob Borg 2015-09-10 14:16:44 +02:00
parent 46364a38c6
commit 9dae87c80c
6 changed files with 12 additions and 8 deletions

View File

@ -773,7 +773,7 @@ func (s *apiSvc) getSystemUpgrade(w http.ResponseWriter, r *http.Request) {
http.Error(w, upgrade.ErrUpgradeUnsupported.Error(), 500)
return
}
rel, err := upgrade.LatestRelease(Version)
rel, err := upgrade.LatestRelease(cfg.Options().ReleasesURL, Version)
if err != nil {
http.Error(w, err.Error(), 500)
return
@ -816,7 +816,7 @@ func (s *apiSvc) getLang(w http.ResponseWriter, r *http.Request) {
}
func (s *apiSvc) postSystemUpgrade(w http.ResponseWriter, r *http.Request) {
rel, err := upgrade.LatestRelease(Version)
rel, err := upgrade.LatestRelease(cfg.Options().ReleasesURL, Version)
if err != nil {
l.Warnln("getting latest release:", err)
http.Error(w, err.Error(), 500)

View File

@ -347,7 +347,7 @@ func main() {
}
if doUpgrade || doUpgradeCheck {
rel, err := upgrade.LatestRelease(Version)
rel, err := upgrade.LatestRelease(cfg.Options().ReleasesURL, Version)
if err != nil {
l.Fatalln("Upgrade:", err) // exits 1
}
@ -1060,7 +1060,7 @@ func autoUpgrade() {
case <-timer.C:
}
rel, err := upgrade.LatestRelease(Version)
rel, err := upgrade.LatestRelease(cfg.Options().ReleasesURL, Version)
if err == upgrade.ErrUpgradeUnsupported {
events.Default.Unsubscribe(sub)
return

View File

@ -248,6 +248,7 @@ type OptionsConfiguration struct {
PingTimeoutS int `xml:"pingTimeoutS" json:"pingTimeoutS" default:"30"`
PingIdleTimeS int `xml:"pingIdleTimeS" json:"pingIdleTimeS" default:"60"`
MinHomeDiskFreePct float64 `xml:"minHomeDiskFreePct" json:"minHomeDiskFreePct" default:"1"`
ReleasesURL string `xml:"releasesURL" json:"releasesURL" default:"https://api.github.com/repos/syncthing/syncthing/releases?per_page=30"`
}
func (orig OptionsConfiguration) Copy() OptionsConfiguration {

View File

@ -63,6 +63,7 @@ func TestDefaultValues(t *testing.T) {
URURL: "https://data.syncthing.net/newdata",
URInitialDelayS: 1800,
URPostInsecurely: false,
ReleasesURL: "https://api.github.com/repos/syncthing/syncthing/releases?per_page=30",
}
cfg := New(device1)
@ -181,6 +182,7 @@ func TestOverriddenValues(t *testing.T) {
URURL: "https://localhost/newdata",
URInitialDelayS: 800,
URPostInsecurely: true,
ReleasesURL: "https://localhost/releases",
}
cfg, err := Load("testdata/overridenvalues.xml", device1)

View File

@ -35,5 +35,6 @@
<urURL>https://localhost/newdata</urURL>
<urInitialDelayS>800</urInitialDelayS>
<urPostInsecurely>true</urPostInsecurely>
<releasesURL>https://localhost/releases</releasesURL>
</options>
</configuration>

View File

@ -46,8 +46,8 @@ var insecureHTTP = &http.Client{
// LatestGithubReleases returns the latest releases, including prereleases or
// not depending on the argument
func LatestGithubReleases(version string) ([]Release, error) {
resp, err := insecureHTTP.Get("https://api.github.com/repos/syncthing/syncthing/releases?per_page=30")
func LatestGithubReleases(releasesURL, version string) ([]Release, error) {
resp, err := insecureHTTP.Get(releasesURL)
if err != nil {
return nil, err
}
@ -74,8 +74,8 @@ func (s SortByRelease) Less(i, j int) bool {
return CompareVersions(s[i].Tag, s[j].Tag) > 0
}
func LatestRelease(version string) (Release, error) {
rels, _ := LatestGithubReleases(version)
func LatestRelease(releasesURL, version string) (Release, error) {
rels, _ := LatestGithubReleases(releasesURL, version)
return SelectLatestRelease(version, rels)
}