@@ -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,11 @@ 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+ },
112126}
113127
114128// GetServiceURL returns the URL for the given service
@@ -121,7 +135,7 @@ func GetServiceURL(service Service) *url.URL {
121135 serviceURL .Host = * host
122136 }
123137
124- if insecure := os . Getenv ( constants . APIInsecureEnvVarName ); insecure == "true" {
138+ if insecure := getProjectHostFromEnv ( ); insecure == "true" {
125139 if serviceURL .Scheme == "https" || serviceURL .Scheme == "wss" {
126140 serviceURL .Scheme = strings .TrimRight (serviceURL .Scheme , "s" )
127141 }
@@ -142,8 +156,9 @@ func GetServiceURL(service Service) *url.URL {
142156}
143157
144158func getProjectHost (service Service ) * string {
145- if apiHost := os .Getenv (constants .APIHostEnvVarName ); apiHost != "" {
146- return & apiHost
159+ if host := HostOverride (); host != "" {
160+ logging .Debug ("Using host override: %s" , host )
161+ return & host
147162 }
148163
149164 if condition .InUnitTest () {
@@ -164,11 +179,35 @@ func getProjectHost(service Service) *string {
164179 return & url .Host
165180}
166181
182+ func getProjectHostFromConfig () string {
183+ cfg , err := config .New ()
184+ if err != nil {
185+ return ""
186+ }
187+ return cfg .GetString (constants .APIHostConfig )
188+ }
189+
190+ func getProjectHostFromEnv () string {
191+ return os .Getenv (constants .APIHostEnvVarName )
192+ }
193+
194+ func HostOverride () string {
195+ if apiHost := getProjectHostFromEnv (); apiHost != "" {
196+ return apiHost
197+ }
198+
199+ if apiHost := getProjectHostFromConfig (); apiHost != "" {
200+ return apiHost
201+ }
202+
203+ return ""
204+ }
205+
167206// GetPlatformURL returns a generic Platform URL for the given path.
168207// This is for retrieving non-service URLs (e.g. signup URL).
169208func GetPlatformURL (path string ) * url.URL {
170209 host := constants .DefaultAPIHost
171- if hostOverride := os . Getenv ( constants . APIHostEnvVarName ); hostOverride != "" {
210+ if hostOverride := HostOverride ( ); hostOverride != "" {
172211 host = hostOverride
173212 }
174213 return & url.URL {
0 commit comments