@@ -18,6 +18,8 @@ import (
1818 "github.com/ActiveState/cli/internal/logging"
1919 "github.com/ActiveState/cli/internal/retryhttp"
2020 "github.com/ActiveState/cli/internal/rtutils/ptr"
21+
22+ configMediator "github.com/ActiveState/cli/internal/mediators/config"
2123)
2224
2325type Configurable interface {
@@ -32,30 +34,28 @@ var (
3234 InvocationSourceUpdate InvocationSource = "update"
3335)
3436
37+ func init () {
38+ configMediator .RegisterOption (constants .UpdateEndpointConfig , configMediator .String , "" )
39+ }
40+
3541type Checker struct {
36- cfg Configurable
37- an analytics.Dispatcher
38- apiInfoURL string
39- retryhttp * retryhttp.Client
40- cache * AvailableUpdate
41- done chan struct {}
42+ cfg Configurable
43+ an analytics.Dispatcher
44+ retryhttp * retryhttp.Client
45+ cache * AvailableUpdate
46+ done chan struct {}
4247
4348 InvocationSource InvocationSource
4449}
4550
4651func NewDefaultChecker (cfg Configurable , an analytics.Dispatcher ) * Checker {
47- infoURL := constants .APIUpdateInfoURL
48- if url , ok := os .LookupEnv ("_TEST_UPDATE_INFO_URL" ); ok {
49- infoURL = url
50- }
51- return NewChecker (cfg , an , infoURL , retryhttp .DefaultClient )
52+ return NewChecker (cfg , an , retryhttp .DefaultClient )
5253}
5354
54- func NewChecker (cfg Configurable , an analytics.Dispatcher , infoURL string , httpget * retryhttp.Client ) * Checker {
55+ func NewChecker (cfg Configurable , an analytics.Dispatcher , httpget * retryhttp.Client ) * Checker {
5556 return & Checker {
5657 cfg ,
5758 an ,
58- infoURL ,
5959 httpget ,
6060 nil ,
6161 make (chan struct {}),
@@ -83,11 +83,26 @@ func (u *Checker) infoURL(tag, desiredVersion, branchName, platform, arch string
8383 v .Set ("target-version" , desiredVersion )
8484 }
8585
86+ var (
87+ infoURL string
88+
89+ envUrl = os .Getenv ("_TEST_UPDATE_INFO_URL" )
90+ cfgUrl = u .cfg .GetString (constants .UpdateEndpointConfig )
91+ )
92+ switch {
93+ case envUrl != "" :
94+ infoURL = envUrl
95+ case cfgUrl != "" :
96+ infoURL = cfgUrl
97+ default :
98+ infoURL = constants .APIUpdateInfoURL
99+ }
100+
86101 if tag != "" {
87102 v .Set ("tag" , tag )
88103 }
89104
90- return u . apiInfoURL + "/info?" + v .Encode ()
105+ return infoURL + "/info?" + v .Encode ()
91106}
92107
93108func (u * Checker ) getUpdateInfo (desiredChannel , desiredVersion string ) (* AvailableUpdate , error ) {
@@ -118,13 +133,15 @@ func (u *Checker) getUpdateInfo(desiredChannel, desiredVersion string) (*Availab
118133 logging .Debug ("Update info 404s: %v" , errs .JoinMessage (err ))
119134 label = anaConst .UpdateLabelUnavailable
120135 msg = anaConst .UpdateErrorNotFound
136+ info = & AvailableUpdate {}
121137
122138 // The request could not be satisfied or service is unavailable. This happens when Cloudflare
123139 // blocks access, or the service is unavailable in a particular geographic location.
124140 case resp .StatusCode == 403 || resp .StatusCode == 503 :
125141 logging .Warning ("Update info request blocked or service unavailable: %v" , err )
126142 label = anaConst .UpdateLabelUnavailable
127143 msg = anaConst .UpdateErrorBlocked
144+ info = & AvailableUpdate {}
128145
129146 // If all went well.
130147 default :
0 commit comments