Skip to content

Commit 2ad9338

Browse files
committed
Merge remote-tracking branch 'origin/master' into CP-1084
2 parents 6c7214a + 7483c85 commit 2ad9338

File tree

30 files changed

+657
-135
lines changed

30 files changed

+657
-135
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,4 +544,4 @@ jobs:
544544
session-build-macos-13
545545
session-build-macos-latest
546546
session-build-windows-2025
547-
session-build-ubuntu-24.04-arm
547+
session-build-ubuntu-24.04-arm

cmd/state-svc/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/ActiveState/cli/internal/rollbar"
3030
"github.com/ActiveState/cli/internal/runbits/panics"
3131
"github.com/ActiveState/cli/internal/svcctl"
32+
"github.com/ActiveState/cli/pkg/platform/api"
3233
"github.com/ActiveState/cli/pkg/platform/authentication"
3334
"github.com/inconshreveable/mousetrap"
3435
)
@@ -70,6 +71,8 @@ func main() {
7071
rollbar.SetupRollbar(constants.StateServiceRollbarToken)
7172
rollbar.SetConfig(cfg)
7273

74+
api.SetConfig(cfg)
75+
7376
if os.Getenv("VERBOSE") == "true" {
7477
logging.CurrentHandler().SetVerbose(true)
7578
}

cmd/state/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/ActiveState/cli/internal/runbits/panics"
3838
"github.com/ActiveState/cli/internal/subshell"
3939
"github.com/ActiveState/cli/internal/svcctl"
40+
"github.com/ActiveState/cli/pkg/platform/api"
4041
secretsapi "github.com/ActiveState/cli/pkg/platform/api/secrets"
4142
"github.com/ActiveState/cli/pkg/platform/authentication"
4243
"github.com/ActiveState/cli/pkg/platform/model"
@@ -91,6 +92,7 @@ func main() {
9192
return
9293
}
9394
rollbar.SetConfig(cfg)
95+
api.SetConfig(cfg)
9496

9597
// Configuration options
9698
// This should only be used if the config option is not exclusive to one package.

internal/analytics/analytics.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
configMediator "github.com/ActiveState/cli/internal/mediators/config"
77
)
88

9+
func init() {
10+
configMediator.RegisterOption(constants.AnalyticsPixelOverrideConfig, configMediator.String, "")
11+
}
12+
913
// Dispatcher describes a struct that can send analytics event in the background
1014
type Dispatcher interface {
1115
Event(category, action string, dim ...*dimensions.Values)

internal/analytics/client/sync/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ func New(source string, cfg *config.Instance, auth *authentication.Auth, out out
123123
// Register reporters
124124
if condition.InTest() {
125125
logging.Debug("Using test reporter")
126-
a.NewReporter(reporters.NewTestReporter(reporters.TestReportFilepath()))
126+
a.NewReporter(reporters.NewTestReporter(reporters.TestReportFilepath(), a.cfg))
127127
logging.Debug("Using test reporter as instructed by env")
128128
} else if v := os.Getenv(constants.AnalyticsLogEnvVarName); v != "" {
129-
a.NewReporter(reporters.NewTestReporter(v))
129+
a.NewReporter(reporters.NewTestReporter(v, a.cfg))
130130
} else {
131-
a.NewReporter(reporters.NewPixelReporter())
131+
a.NewReporter(reporters.NewPixelReporter(a.cfg))
132132
}
133133

134134
return a

internal/analytics/client/sync/reporters/pixel.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@ import (
77
"os"
88

99
"github.com/ActiveState/cli/internal/analytics/dimensions"
10+
"github.com/ActiveState/cli/internal/config"
1011
"github.com/ActiveState/cli/internal/constants"
1112
"github.com/ActiveState/cli/internal/errs"
13+
14+
configMediator "github.com/ActiveState/cli/internal/mediators/config"
1215
)
1316

1417
type PixelReporter struct {
1518
url string
1619
}
1720

18-
func NewPixelReporter() *PixelReporter {
19-
var pixelUrl string
20-
21-
// Attempt to get the value for the pixel URL from the environment. Fall back to default if that fails
22-
if pixelUrl = os.Getenv(constants.AnalyticsPixelOverrideEnv); pixelUrl == "" {
23-
pixelUrl = constants.DefaultAnalyticsPixel
21+
func NewPixelReporter(cfg *config.Instance) *PixelReporter {
22+
reporter := &PixelReporter{
23+
url: sourcePixelURL(cfg),
2424
}
25-
return &PixelReporter{pixelUrl}
25+
26+
configMediator.AddListener(constants.AnalyticsPixelOverrideConfig, func() {
27+
reporter.url = sourcePixelURL(cfg)
28+
})
29+
return reporter
2630
}
2731

2832
func (r *PixelReporter) ID() string {
@@ -55,3 +59,23 @@ func (r *PixelReporter) Event(category, action, source, label string, d *dimensi
5559

5660
return nil
5761
}
62+
63+
func sourcePixelURL(cfg *config.Instance) string {
64+
var (
65+
pixelUrl string
66+
67+
envUrl = os.Getenv(constants.AnalyticsPixelOverrideEnv)
68+
cfgUrl = cfg.GetString(constants.AnalyticsPixelOverrideConfig)
69+
)
70+
71+
switch {
72+
case envUrl != "":
73+
pixelUrl = envUrl
74+
case cfgUrl != "":
75+
pixelUrl = cfgUrl
76+
default:
77+
pixelUrl = constants.DefaultAnalyticsPixel
78+
}
79+
80+
return pixelUrl
81+
}

internal/analytics/client/sync/reporters/test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import (
55
"path/filepath"
66

77
"github.com/ActiveState/cli/internal/analytics/dimensions"
8+
"github.com/ActiveState/cli/internal/config"
9+
"github.com/ActiveState/cli/internal/constants"
810
"github.com/ActiveState/cli/internal/errs"
911
"github.com/ActiveState/cli/internal/fileutils"
1012
"github.com/ActiveState/cli/internal/installation/storage"
1113
"github.com/ActiveState/cli/internal/logging"
14+
configMediator "github.com/ActiveState/cli/internal/mediators/config"
1215
)
1316

1417
type TestReporter struct {
1518
path string
19+
cfg *config.Instance
1620
}
1721

1822
const TestReportFilename = "analytics.log"
@@ -23,8 +27,12 @@ func TestReportFilepath() string {
2327
return filepath.Join(appdata, TestReportFilename)
2428
}
2529

26-
func NewTestReporter(path string) *TestReporter {
27-
return &TestReporter{path}
30+
func NewTestReporter(path string, cfg *config.Instance) *TestReporter {
31+
reporter := &TestReporter{path, cfg}
32+
configMediator.AddListener(constants.AnalyticsPixelOverrideConfig, func() {
33+
reporter.cfg = cfg
34+
})
35+
return reporter
2836
}
2937

3038
func (r *TestReporter) ID() string {
@@ -36,11 +44,13 @@ type TestLogEntry struct {
3644
Action string
3745
Source string
3846
Label string
47+
URL string
3948
Dimensions *dimensions.Values
4049
}
4150

4251
func (r *TestReporter) Event(category, action, source, label string, d *dimensions.Values) error {
43-
b, err := json.Marshal(TestLogEntry{category, action, source, label, d})
52+
url := r.cfg.GetString(constants.AnalyticsPixelOverrideConfig)
53+
b, err := json.Marshal(TestLogEntry{category, action, source, label, url, d})
4454
if err != nil {
4555
return errs.Wrap(err, "Could not marshal test log entry")
4656
}

internal/captain/values.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ func (p *PackageValue) Set(s string) error {
155155
}
156156
switch {
157157
case strings.Contains(s, ":"):
158-
v := strings.Split(s, ":")
159-
p.Namespace = strings.TrimSpace(strings.Join(v[0:len(v)-1], ":"))
160-
p.Name = strings.TrimSpace(v[len(v)-1])
158+
namespace, name, _ := strings.Cut(s, ":")
159+
p.Namespace = strings.TrimSpace(namespace)
160+
p.Name = strings.TrimSpace(name)
161161
case strings.Contains(s, "/"):
162162
v := strings.Split(s, "/")
163163
p.Namespace = strings.TrimSpace(strings.Join(v[0:len(v)-1], "/"))

internal/constants/constants.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ const VulnerabilitiesAPIPath = "/v13s/v1/graphql"
261261
// HasuraInventoryAPIPath is the path used for the hasura inventory api
262262
const HasuraInventoryAPIPath = "/sv/hasura-inventory/v1/graphql"
263263

264+
// UpdateInfoAPIPath is the path used for the update info api
265+
const UpdateInfoAPIPath = "/sv/state-update/api/v1"
266+
264267
// NotificationsInfoURL is the URL we check against to see what versions are deprecated
265268
const NotificationsInfoURL = "https://state-tool.s3.amazonaws.com/messages.json"
266269

@@ -409,6 +412,15 @@ const SecurityPromptConfig = "security.prompt.enabled"
409412
// SecurityPromptLevelConfig is the config key used to determine the level of security prompts
410413
const SecurityPromptLevelConfig = "security.prompt.level"
411414

415+
// AnalyticsPixelOverrideConfig is the config key used to override the analytics pixel url
416+
const AnalyticsPixelOverrideConfig = "report.analytics.endpoint"
417+
418+
// UpdateEndpointConfig is the config key used to determine the update endpoint to use
419+
const UpdateEndpointConfig = "update.endpoint"
420+
421+
// APIHostConfig is the config key used to determine the api host
422+
const APIHostConfig = "api.host"
423+
412424
// SvcAppName is the name we give our state-svc application
413425
const SvcAppName = "State Service"
414426

internal/runbits/checkout/checkout.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/ActiveState/cli/internal/runbits/buildscript"
1515
"github.com/ActiveState/cli/internal/runbits/git"
1616
"github.com/ActiveState/cli/pkg/localcommit"
17+
"github.com/ActiveState/cli/pkg/platform/api"
1718
"github.com/ActiveState/cli/pkg/platform/api/mono/mono_models"
1819
"github.com/ActiveState/cli/pkg/platform/authentication"
1920
"github.com/ActiveState/cli/pkg/platform/model"
@@ -193,6 +194,7 @@ func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID,
193194
Language: language,
194195
Cache: cachePath,
195196
Portable: portable,
197+
Host: api.HostOverride(),
196198
})
197199
if err != nil {
198200
if osutils.IsAccessDeniedError(err) {

0 commit comments

Comments
 (0)