From 27ac1d59d87f0f3cb26086f3fa19cf0e2d0ec24e Mon Sep 17 00:00:00 2001 From: Prem Kumar Kalle Date: Wed, 12 Jul 2023 10:59:23 -0700 Subject: [PATCH] Add CSPOrgID and EntitlementAccountNumber to telemetry options config API Signed-off-by: Prem Kumar Kalle --- config/cli_options_telemetry_test.go | 30 ++++++++++++++++++++++++---- config/types/clientconfig_types.go | 4 ++++ docs/config.md | 7 +++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/config/cli_options_telemetry_test.go b/config/cli_options_telemetry_test.go index 145c4ff1..d2d7bf69 100644 --- a/config/cli_options_telemetry_test.go +++ b/config/cli_options_telemetry_test.go @@ -20,13 +20,21 @@ func TestSetGetTelemetryOptions(t *testing.T) { }() telOptions := &configtypes.TelemetryOptions{ - Source: "/fake/path", + Source: "/fake/path", + CSPOrgID: "fake-csp-org-id", + EntitlementAccountNumber: "fake-entitlement-account-number", } telOptionsUpdate := &configtypes.TelemetryOptions{ Source: "/fake/path/updated", } + telOptionsUpdate2 := &configtypes.TelemetryOptions{ + Source: "/fake/path/updated-2", + CSPOrgID: "fake-csp-org-id-2", + EntitlementAccountNumber: "fake-entitlement-account-number-2", + } + // get telemetry options when the config file is empty gotTelemetryoptions, err := GetCLITelemetryOptions() assert.Equal(t, "telemetry not found", err.Error()) @@ -40,13 +48,25 @@ func TestSetGetTelemetryOptions(t *testing.T) { assert.Nil(t, err) assert.Equal(t, telOptions, gotTelemetryoptions) - // update telemetry options + // update telemetry options with one field in the input options err = SetCLITelemetryOptions(telOptionsUpdate) assert.NoError(t, err) gotTelemetryoptions, err = GetCLITelemetryOptions() assert.Nil(t, err) - assert.Equal(t, gotTelemetryoptions, telOptionsUpdate) + assert.Equal(t, gotTelemetryoptions, &configtypes.TelemetryOptions{ + Source: "/fake/path/updated", + CSPOrgID: "fake-csp-org-id", + EntitlementAccountNumber: "fake-entitlement-account-number", + }) + + // update telemetry options with all the fields in the input options + err = SetCLITelemetryOptions(telOptionsUpdate2) + assert.NoError(t, err) + + gotTelemetryoptions, err = GetCLITelemetryOptions() + assert.Nil(t, err) + assert.Equal(t, gotTelemetryoptions, telOptionsUpdate2) // test configuring with nil err = SetCLITelemetryOptions(nil) @@ -62,7 +82,9 @@ func TestDeleteTelemetryOptions(t *testing.T) { }() telOptions := &configtypes.TelemetryOptions{ - Source: "/fake/path", + Source: "/fake/path", + CSPOrgID: "fake-csp-org-id", + EntitlementAccountNumber: "fake-entitlement-account-number", } // delete telemetry options when the config file is empty should not return error diff --git a/config/types/clientconfig_types.go b/config/types/clientconfig_types.go index c25f0ab6..4335ad91 100644 --- a/config/types/clientconfig_types.go +++ b/config/types/clientconfig_types.go @@ -306,6 +306,10 @@ type CoreCliOptions struct { type TelemetryOptions struct { // Source is the path of the telemetry source database Source string `json:"source,omitempty" yaml:"source,omitempty"` + // CSPOrgID is the organization ID the user + CSPOrgID string `json:"cspOrgID,omitempty" yaml:"cspOrgID,omitempty"` + // EntitlementAccountNumber is the organization ID the user + EntitlementAccountNumber string `json:"entitlementAccountNumber,omitempty" yaml:"entitlementAccountNumber,omitempty"` } // Cert provides a certificate configuration for an endpoint diff --git a/docs/config.md b/docs/config.md index b03ded36..8185eef4 100644 --- a/docs/config.md +++ b/docs/config.md @@ -83,6 +83,13 @@ func GetEnvConfigurations() map[string]string func GetEdition() (string, error) func SetEdition(val string) (err error) +// Telemetry APIs +func GetCEIPOptIn() (string, error) +func SetCEIPOptIn(val string) (err error) +func GetCLITelemetryOptions() (*configtypes.TelemetryOptions, error) +func SetCLITelemetryOptions(c *configtypes.TelemetryOptions) error +func DeleteTelemetryOptions() errors + // Discovery Sources APIs func GetCLIDiscoverySources() ([]configtypes.PluginDiscovery, error) func GetCLIDiscoverySource(name string) (*configtypes.PluginDiscovery, error)