...
1 package segment
2
3 import (
4 "context"
5
6 "github.com/Xuanwo/go-locale"
7
8 registryLibrary "github.com/devfile/registry-support/registry-library/library"
9
10 envcontext "github.com/redhat-developer/odo/pkg/config/context"
11 scontext "github.com/redhat-developer/odo/pkg/segment/context"
12
13 "k8s.io/klog"
14 )
15
16
17
18 func getTelemetryForDevfileRegistry(ctx context.Context) (registryLibrary.TelemetryData, error) {
19
20 td := registryLibrary.TelemetryData{
21 Client: TelemetryClient,
22 }
23
24 envConfig := envcontext.GetEnvConfig(ctx)
25
26 if envConfig.TelemetryCaller != "" {
27 td.Client += "-" + envConfig.TelemetryCaller
28 }
29
30 if envConfig.OdoDebugTelemetryFile != nil {
31 return td, nil
32 }
33
34 if !scontext.GetTelemetryStatus(ctx) {
35 return td, nil
36 }
37
38
39 tag, _ := locale.Detect()
40 td.Locale = tag.String()
41
42 user, err := GetUserIdentity(GetTelemetryFilePath())
43 if err != nil {
44
45 td.User = td.Client
46 return td, err
47 }
48
49 td.User = user
50 return td, nil
51
52 }
53
54
55 func GetRegistryOptions(ctx context.Context) registryLibrary.RegistryOptions {
56 td, err := getTelemetryForDevfileRegistry(ctx)
57 if err != nil {
58
59 klog.Errorf("An error prevented additional telemetry to be set %v", err)
60 }
61
62 registryOptions := registryLibrary.RegistryOptions{
63 SkipTLSVerify: false,
64 Telemetry: td,
65 Filter: registryLibrary.RegistryFilter{},
66 }
67
68 return registryOptions
69 }
70
View as plain text