@@ -5,13 +5,19 @@ import (
55 "os"
66 "strings"
77
8+ configMediator "github.com/ActiveState/cli/internal/mediators/config"
89 "github.com/ActiveState/cli/pkg/projectfile"
910
1011 "github.com/ActiveState/cli/internal/condition"
12+ "github.com/ActiveState/cli/internal/config"
1113 "github.com/ActiveState/cli/internal/constants"
1214 "github.com/ActiveState/cli/internal/logging"
1315)
1416
17+ func init () {
18+ configMediator .RegisterOption (constants .APIHostConfig , configMediator .String , "" )
19+ }
20+
1521// Service records available api services
1622type Service string
1723
@@ -49,6 +55,9 @@ const (
4955 // ServiceHasuraInventory is the Hasura service for inventory information.
5056 ServiceHasuraInventory = "hasura-inventory"
5157
58+ // ServiceUpdateInfo is the service for update info
59+ ServiceUpdateInfo = "update-info"
60+
5261 // TestingPlatform is the API host used by tests so-as not to affect production.
5362 TestingPlatform = ".testing.tld"
5463)
@@ -109,6 +118,24 @@ var urlsByService = map[Service]*url.URL{
109118 Host : constants .DefaultAPIHost ,
110119 Path : constants .HasuraInventoryAPIPath ,
111120 },
121+ ServiceUpdateInfo : {
122+ Scheme : "https" ,
123+ Host : constants .DefaultAPIHost ,
124+ Path : constants .UpdateInfoAPIPath ,
125+ },
126+ }
127+
128+ var configuredAPIHost string
129+
130+ func registerConfigListener (cfg * config.Instance ) {
131+ configMediator .AddListener (constants .APIHostConfig , func () {
132+ configuredAPIHost = cfg .GetString (constants .APIHostConfig )
133+ })
134+ }
135+
136+ func SetConfig (cfg * config.Instance ) {
137+ configuredAPIHost = cfg .GetString (constants .APIHostConfig )
138+ registerConfigListener (cfg )
112139}
113140
114141// GetServiceURL returns the URL for the given service
@@ -121,7 +148,7 @@ func GetServiceURL(service Service) *url.URL {
121148 serviceURL .Host = * host
122149 }
123150
124- if insecure := os .Getenv (constants .APIInsecureEnvVarName ); insecure == "true" {
151+ if insecure := os .Getenv (constants .APIHostEnvVarName ); insecure == "true" {
125152 if serviceURL .Scheme == "https" || serviceURL .Scheme == "wss" {
126153 serviceURL .Scheme = strings .TrimRight (serviceURL .Scheme , "s" )
127154 }
@@ -142,8 +169,9 @@ func GetServiceURL(service Service) *url.URL {
142169}
143170
144171func getProjectHost (service Service ) * string {
145- if apiHost := os .Getenv (constants .APIHostEnvVarName ); apiHost != "" {
146- return & apiHost
172+ if host := HostOverride (); host != "" {
173+ logging .Debug ("Using host override: %s" , host )
174+ return & host
147175 }
148176
149177 if condition .InUnitTest () {
@@ -164,11 +192,30 @@ func getProjectHost(service Service) *string {
164192 return & url .Host
165193}
166194
195+ func getProjectHostFromConfig () string {
196+ if configuredAPIHost != "" {
197+ return configuredAPIHost
198+ }
199+ return ""
200+ }
201+
202+ func HostOverride () string {
203+ if apiHost := os .Getenv (constants .APIHostEnvVarName ); apiHost != "" {
204+ return apiHost
205+ }
206+
207+ if apiHost := getProjectHostFromConfig (); apiHost != "" {
208+ return apiHost
209+ }
210+
211+ return ""
212+ }
213+
167214// GetPlatformURL returns a generic Platform URL for the given path.
168215// This is for retrieving non-service URLs (e.g. signup URL).
169216func GetPlatformURL (path string ) * url.URL {
170217 host := constants .DefaultAPIHost
171- if hostOverride := os . Getenv ( constants . APIHostEnvVarName ); hostOverride != "" {
218+ if hostOverride := HostOverride ( ); hostOverride != "" {
172219 host = hostOverride
173220 }
174221 return & url.URL {
0 commit comments