Skip to content

Commit

Permalink
chore: Added events for policy
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFaucherre committed Aug 1, 2023
1 parent 2761dc6 commit 051386b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
18 changes: 15 additions & 3 deletions cmd/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,29 @@ import (

"github.com/CircleCI-Public/circleci-cli/api/policy"
"github.com/CircleCI-Public/circleci-cli/api/rest"
"github.com/CircleCI-Public/circleci-cli/cmd/create_telemetry"
"github.com/CircleCI-Public/circleci-cli/cmd/validator"
"github.com/CircleCI-Public/circleci-cli/config"
"github.com/CircleCI-Public/circleci-cli/telemetry"

"github.com/CircleCI-Public/circleci-cli/settings"
)

// NewCommand creates the root policy command with all policy subcommands attached.
func NewCommand(globalConfig *settings.Config, preRunE validator.Validator) *cobra.Command {
cmd := &cobra.Command{
Use: "policy",
PersistentPreRunE: preRunE,
Short: "Manage security policies",
Use: "policy",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
telemetryClient := create_telemetry.CreateTelemetry(globalConfig)
defer telemetryClient.Close()
telemetryClient.Track(telemetry.CreatePolicyEvent(create_telemetry.GetCommandInformation(cmd, true)))

if preRunE != nil {
return preRunE(cmd, args)
}
return nil
},
Short: "Manage security policies",
Long: `Policies ensures security of build configs via security policy management framework.
This group of commands allows the management of polices to be verified against build configs.`,
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestPushPolicyWithPrompt(t *testing.T) {
}))
defer svr.Close()

config := &settings.Config{Token: "testtoken", HTTPClient: http.DefaultClient}
config := &settings.Config{Token: "testtoken", HTTPClient: http.DefaultClient, IsTelemetryDisabled: true}
cmd := NewCommand(config, nil)

buffer := makeSafeBuffer()
Expand Down Expand Up @@ -1382,10 +1382,11 @@ func TestTestRunner(t *testing.T) {

func makeCMD(circleHost string, token string) (*cobra.Command, *bytes.Buffer, *bytes.Buffer) {
config := &settings.Config{
Host: circleHost,
Token: token,
RestEndpoint: "/api/v2",
HTTPClient: http.DefaultClient,
Host: circleHost,
Token: token,
RestEndpoint: "/api/v2",
HTTPClient: http.DefaultClient,
IsTelemetryDisabled: true,
}

cmd := NewCommand(config, nil)
Expand Down
4 changes: 4 additions & 0 deletions telemetry/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ func CreateNamespaceEvent(cmdInfo CommandInfo) Event {
func CreateOrbEvent(cmdInfo CommandInfo) Event {
return createEventFromCommandInfo("orb", cmdInfo)
}

func CreatePolicyEvent(cmdInfo CommandInfo) Event {
return createEventFromCommandInfo("policy", cmdInfo)
}

0 comments on commit 051386b

Please sign in to comment.