Do not send telemetry for aliases
This commit is contained in:
parent
73f390073c
commit
6709e315df
2 changed files with 35 additions and 10 deletions
18
acceptance/testdata/telemetry/no-telemetry-for-alias.txtar
vendored
Normal file
18
acceptance/testdata/telemetry/no-telemetry-for-alias.txtar
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Aliases should not leak their user-defined names via telemetry, but the
|
||||||
|
# resolved inner command should still record normally — its path is a core
|
||||||
|
# gh command and conveys no user-authored identifier.
|
||||||
|
|
||||||
|
env GH_PRIVATE_ENABLE_TELEMETRY=1
|
||||||
|
env GH_TELEMETRY=log
|
||||||
|
env GH_TELEMETRY_SAMPLE_RATE=100
|
||||||
|
|
||||||
|
# Create a regular (non-shell) alias that resolves to an existing command.
|
||||||
|
exec gh alias set secret-project-alias version
|
||||||
|
|
||||||
|
# Invoking the alias must not produce any event carrying the alias name.
|
||||||
|
exec gh secret-project-alias
|
||||||
|
! stderr 'secret-project-alias'
|
||||||
|
|
||||||
|
# The resolved inner command still records telemetry as normal.
|
||||||
|
stderr 'Telemetry payload:'
|
||||||
|
stderr '"command": "gh version"'
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/cli/cli/v2/internal/run"
|
"github.com/cli/cli/v2/internal/run"
|
||||||
"github.com/cli/cli/v2/internal/text"
|
"github.com/cli/cli/v2/internal/text"
|
||||||
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/findsh"
|
"github.com/cli/cli/v2/pkg/findsh"
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
|
|
@ -17,7 +18,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
|
func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
|
||||||
return &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: aliasName,
|
Use: aliasName,
|
||||||
Short: fmt.Sprintf("Shell alias for %q", text.Truncate(80, aliasValue)),
|
Short: fmt.Sprintf("Shell alias for %q", text.Truncate(80, aliasValue)),
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
|
|
@ -39,16 +40,19 @@ func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *co
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
GroupID: "alias",
|
GroupID: "alias",
|
||||||
Annotations: map[string]string{
|
|
||||||
"skipAuthCheck": "true",
|
|
||||||
},
|
|
||||||
DisableFlagParsing: true,
|
DisableFlagParsing: true,
|
||||||
}
|
}
|
||||||
|
cmdutil.DisableAuthCheck(cmd)
|
||||||
|
// Aliases are user-defined names and must not be reported as telemetry
|
||||||
|
// dimensions, since the name itself may be sensitive (e.g. project or
|
||||||
|
// organization names).
|
||||||
|
cmdutil.DisableTelemetry(cmd)
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
|
func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
|
||||||
return &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: aliasName,
|
Use: aliasName,
|
||||||
Short: fmt.Sprintf("Alias for %q", text.Truncate(80, aliasValue)),
|
Short: fmt.Sprintf("Alias for %q", text.Truncate(80, aliasValue)),
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
|
|
@ -60,12 +64,15 @@ func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.C
|
||||||
root.SetArgs(expandedArgs)
|
root.SetArgs(expandedArgs)
|
||||||
return root.Execute()
|
return root.Execute()
|
||||||
},
|
},
|
||||||
GroupID: "alias",
|
GroupID: "alias",
|
||||||
Annotations: map[string]string{
|
|
||||||
"skipAuthCheck": "true",
|
|
||||||
},
|
|
||||||
DisableFlagParsing: true,
|
DisableFlagParsing: true,
|
||||||
}
|
}
|
||||||
|
cmdutil.DisableAuthCheck(cmd)
|
||||||
|
// Aliases are user-defined names and must not be reported as telemetry
|
||||||
|
// dimensions, since the name itself may be sensitive (e.g. project or
|
||||||
|
// organization names).
|
||||||
|
cmdutil.DisableTelemetry(cmd)
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.
|
// ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue