...

Source file src/github.com/redhat-developer/odo/pkg/segment/integrations.go

Documentation: github.com/redhat-developer/odo/pkg/segment

     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  // getTelemetryForDevfileRegistry returns a populated TelemetryData object that contains some odo telemetry (with client consent), such as the anonymous ID and
    17  // locale in addition to the generic client name "odo"
    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  	// if there is an error, tag will be undetermined
    39  	tag, _ := locale.Detect()
    40  	td.Locale = tag.String()
    41  
    42  	user, err := GetUserIdentity(GetTelemetryFilePath())
    43  	if err != nil {
    44  		// default to the generic user ID if the anonymous ID cannot be found
    45  		td.User = td.Client
    46  		return td, err
    47  	}
    48  
    49  	td.User = user
    50  	return td, nil
    51  
    52  }
    53  
    54  // GetRegistryOptions returns a populated RegistryOptions object containing all the properties needed to make a devfile registry library call
    55  func GetRegistryOptions(ctx context.Context) registryLibrary.RegistryOptions {
    56  	td, err := getTelemetryForDevfileRegistry(ctx)
    57  	if err != nil {
    58  		// this error should not prevent basic telemetry from being sent
    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