From 70a206b04ec74f4d95d5d0550014c98f146fc5be Mon Sep 17 00:00:00 2001 From: John Dietz Date: Sat, 21 Oct 2023 13:21:36 -0400 Subject: [PATCH] fix: moving subdomain out of runtime --- pkg/telemetryShim/telemetry.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/telemetryShim/telemetry.go b/pkg/telemetryShim/telemetry.go index e1eae1a4..5c5ba6e0 100644 --- a/pkg/telemetryShim/telemetry.go +++ b/pkg/telemetryShim/telemetry.go @@ -8,12 +8,12 @@ package telemetryShim import ( "os" + "strings" "time" "github.com/denisbrodbeck/machineid" "github.com/kubefirst/kubefirst-api/pkg/segment" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" - "github.com/kubefirst/runtime/pkg" "github.com/segmentio/analytics-go" log "github.com/sirupsen/logrus" ) @@ -40,7 +40,7 @@ func SetupTelemetry(cl pkgtypes.Cluster) (*segment.SegmentClient, error) { kubefirstVersion = "development" } - strippedDomainName, err := pkg.RemoveSubdomainV2(cl.DomainName) + strippedDomainName, err := RemoveSubdomainV2(cl.DomainName) if err != nil { return &segment.SegmentClient{}, nil } @@ -71,3 +71,17 @@ func Transmit(segmentClient *segment.SegmentClient, metricName string, errorMess log.Info(segmentMsg) } } + +func RemoveSubdomainV2(domainName string) (string, error) { + + domainName = strings.TrimRight(domainName, ".") + domainSlice := strings.Split(domainName, ".") + + if len(domainSlice) < 2 { + return "", nil + } + + domainName = strings.Join([]string{domainSlice[len(domainSlice)-2], domainSlice[len(domainSlice)-1]}, ".") + + return domainName, nil +}