Skip to content

Commit

Permalink
Add CSPOrgID and EntitlementAccountNumber to telemetry options config…
Browse files Browse the repository at this point in the history
… API

Signed-off-by: Prem Kumar Kalle <[email protected]>
  • Loading branch information
prkalle committed Jul 12, 2023
1 parent 6b662c0 commit 27ac1d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
30 changes: 26 additions & 4 deletions config/cli_options_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/types/clientconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 27ac1d5

Please sign in to comment.