Skip to content

Commit

Permalink
CLI Unification: Warn if command is unavailable (#962)
Browse files Browse the repository at this point in the history
* show warnings for unavailable top level commands

* fix int tests

* show warnings for unavailable internal commands

* warnings for schema-registry commands

* warnings for kafka commands and fix tests

* fix typo

* remove todo

* fix iam

* fix cluster

* fix lint

* fix int tests

* fix prerun logic

* unit tests

* fix prerun logic

* code review

* fix tests

* fix windows test

* updated jenkinsfile git branch

* fix unit test

* disallow auto-login to opposite context

* fix windows tests

* change auto-login logic

* add cloud-signup suggestions

* fix windows tests

* use 7.0.x branch of muckrake

* Revert "use 7.0.x branch of muckrake"

This reverts commit ee4b874.
  • Loading branch information
brianstrauch committed Aug 27, 2021
1 parent 521e3ec commit 1bf9f61
Show file tree
Hide file tree
Showing 64 changed files with 957 additions and 739 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def job = {
export confluent_s3="https://s3-us-west-2.amazonaws.com"
git clone git@github.com:confluentinc/muckrake.git
cd muckrake
git checkout 6.2.x
git checkout 6.2.x-cli-unification
sed -i "s?\\(confluent-cli-\\(.*\\)=\\)\\(.*\\)?\\1${confluent_s3}/confluent.cloud/confluent-cli-system-test-builds/confluent_SNAPSHOT-${HASH}_linux_amd64\\.tar\\.gz\\"?" ducker/ducker
sed -i "s?get_cli .*?& ${confluent_s3}/confluent.cloud/confluent-cli-system-test-builds/confluent_SNAPSHOT-${HASH}_linux_amd64\\.tar\\.gz?g" vagrant/base-ubuntu.sh
sed -i "s?get_cli .*?& ${confluent_s3}/confluent.cloud/confluent-cli-system-test-builds/confluent_SNAPSHOT-${HASH}_linux_amd64\\.tar\\.gz?g" vagrant/base-redhat.sh
Expand All @@ -106,7 +106,7 @@ def job = {
["sonatype/confluent", "user", "SONATYPE_OSSRH_USER"],
["sonatype/confluent", "password", "SONATYPE_OSSRH_PASSWORD"]]) {
withEnv(["GIT_CREDENTIAL=${env.GIT_USER}:${env.GIT_TOKEN}",
"AWS_KEYPAIR_FILE=${pem_file}", "GIT_BRANCH=6.2.x"]) {
"AWS_KEYPAIR_FILE=${pem_file}", "GIT_BRANCH=6.2.x-cli-unification"]) {
withVaultFile([["maven/jenkins_maven_global_settings", "settings_xml",
"/home/jenkins/.m2/settings.xml", "MAVEN_GLOBAL_SETTINGS_FILE"],
["gradle/gradle_properties_maven", "gradle_properties_file",
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/admin/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
func New(prerunner pcmd.PreRunner, isTest bool) *cobra.Command {
c := pcmd.NewAnonymousCLICommand(
&cobra.Command{
Use: "admin",
Short: "Perform administrative tasks for the current organization.",
Args: cobra.NoArgs,
Use: "admin",
Short: "Perform administrative tasks for the current organization.",
Args: cobra.NoArgs,
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogin},
},
prerunner,
)
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/api-key/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ var (
func New(prerunner pcmd.PreRunner, keystore keystore.KeyStore, resolver pcmd.FlagResolver, analyticsClient analytics.Client) *command {
cliCmd := pcmd.NewAuthenticatedStateFlagCommand(
&cobra.Command{
Use: "api-key",
Short: "Manage the API keys.",
Use: "api-key",
Short: "Manage the API keys.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin},
}, prerunner, SubcommandFlags)
cmd := &command{
AuthenticatedStateFlagCommand: cliCmd,
Expand Down
38 changes: 18 additions & 20 deletions internal/cmd/audit-log/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/spf13/cobra"

pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
v3 "github.com/confluentinc/cli/internal/pkg/config/v3"
"github.com/confluentinc/cli/internal/pkg/errors"
)

Expand All @@ -19,29 +18,28 @@ type command struct {
}

// New returns the default command object for interacting with audit logs.
func New(cfg *v3.Config, prerunner pcmd.PreRunner) *cobra.Command {
cliCmd := pcmd.NewCLICommand(
&cobra.Command{
Use: "audit-log",
Short: "Manage audit log configuration.",
Long: "Manage which auditable events are logged, and where the event logs are sent.",
}, prerunner)
cmd := &command{
CLICommand: cliCmd,
func New(prerunner pcmd.PreRunner) *cobra.Command {
cmd := &cobra.Command{
Use: "audit-log",
Short: "Manage audit log configuration.",
Long: "Manage which auditable events are logged, and where the event logs are sent.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLoginOrOnPremLogin},
}

c := &command{
CLICommand: pcmd.NewAnonymousCLICommand(cmd, prerunner),
prerunner: prerunner,
}
cmd.init(cfg)
return cmd.Command
c.init()

return c.Command
}

func (c *command) init(cfg *v3.Config) {
if cfg.IsCloud() {
c.AddCommand(NewDescribeCommand(c.prerunner))
} else {
c.AddCommand(NewMigrateCommand(c.prerunner))
c.AddCommand(NewConfigCommand(c.prerunner))
c.AddCommand(NewRouteCommand(c.prerunner))
}
func (c *command) init() {
c.AddCommand(NewDescribeCommand(c.prerunner))
c.AddCommand(NewMigrateCommand(c.prerunner))
c.AddCommand(NewConfigCommand(c.prerunner))
c.AddCommand(NewRouteCommand(c.prerunner))
}

type errorMessage struct {
Expand Down
23 changes: 12 additions & 11 deletions internal/cmd/audit-log/command_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ import (
mds "github.com/confluentinc/mds-sdk-go/mdsv1"
"github.com/spf13/cobra"

"github.com/confluentinc/cli/internal/pkg/cmd"
pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
)

type configCommand struct {
*cmd.AuthenticatedStateFlagCommand
prerunner cmd.PreRunner
*pcmd.AuthenticatedStateFlagCommand
prerunner pcmd.PreRunner
}

// NewRouteCommand returns the sub-command object for interacting with audit log route rules.
func NewConfigCommand(prerunner cmd.PreRunner) *cobra.Command {
cliCmd := cmd.NewAuthenticatedWithMDSStateFlagCommand(
func NewConfigCommand(prerunner pcmd.PreRunner) *cobra.Command {
cliCmd := pcmd.NewAuthenticatedWithMDSStateFlagCommand(
&cobra.Command{
Use: "config",
Short: "Manage the audit log configuration specification.",
Long: "Manage the audit log defaults and routing rules that determine which auditable events are logged, and where.",
Use: "config",
Short: "Manage the audit log configuration specification.",
Long: "Manage the audit log defaults and routing rules that determine which auditable events are logged, and where.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireOnPremLogin},
}, prerunner, ConfigSubcommandFlags)
command := &configCommand{
AuthenticatedStateFlagCommand: cliCmd,
Expand All @@ -42,7 +43,7 @@ func (c *configCommand) init() {
Short: "Prints the audit log configuration spec object.",
Long: `Prints the audit log configuration spec object, where "spec" refers to the JSON blob that describes audit log routing rules.`,
Args: cobra.NoArgs,
RunE: cmd.NewCLIRunE(c.describe),
RunE: pcmd.NewCLIRunE(c.describe),
}
c.AddCommand(describeCmd)

Expand All @@ -51,7 +52,7 @@ func (c *configCommand) init() {
Short: "Submits audit-log config spec object to the API.",
Long: "Submits an audit-log configuration specification JSON object to the API.",
Args: cobra.NoArgs,
RunE: cmd.NewCLIRunE(c.update),
RunE: pcmd.NewCLIRunE(c.update),
}
updateCmd.Flags().String("file", "", "A local file path to the JSON configuration file, read as input. Otherwise the command will read from standard input.")
updateCmd.Flags().Bool("force", false, "Updates the configuration, overwriting any concurrent modifications.")
Expand All @@ -63,7 +64,7 @@ func (c *configCommand) init() {
Short: "Edit the audit-log config spec interactively.",
Long: "Edit the audit-log config spec object interactively, using the $EDITOR specified in your environment (for example, vim).",
Args: cobra.NoArgs,
RunE: cmd.NewCLIRunE(c.edit),
RunE: pcmd.NewCLIRunE(c.edit),
}
c.AddCommand(editCmd)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/audit-log/command_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func NewDescribeCommand(prerunner pcmd.PreRunner) *cobra.Command {
c := &describeCmd{
pcmd.NewAuthenticatedCLICommand(
&cobra.Command{
Use: "describe",
Short: "Describe the audit log configuration for this organization.",
Args: cobra.NoArgs,
Use: "describe",
Short: "Describe the audit log configuration for this organization.",
Args: cobra.NoArgs,
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogin},
},
prerunner,
),
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/audit-log/command_describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ func mockAuditLogCommand(configured bool) *cobra.Command {
}
}

return New(cfg, climock.NewPreRunnerMock(client, nil, nil, cfg))
return New(climock.NewPreRunnerMock(client, nil, nil, cfg))
}
15 changes: 8 additions & 7 deletions internal/cmd/audit-log/command_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import (

"github.com/spf13/cobra"

"github.com/confluentinc/cli/internal/pkg/cmd"
pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
"github.com/confluentinc/cli/internal/pkg/errors"
"github.com/confluentinc/cli/internal/pkg/examples"
"github.com/confluentinc/cli/internal/pkg/utils"
)

type migrateCmd struct {
*cmd.CLICommand
prerunner cmd.PreRunner
*pcmd.CLICommand
prerunner pcmd.PreRunner
}

func NewMigrateCommand(prerunner cmd.PreRunner) *cobra.Command {
cliCmd := cmd.NewCLICommand(
func NewMigrateCommand(prerunner pcmd.PreRunner) *cobra.Command {
cliCmd := pcmd.NewCLICommand(
&cobra.Command{
Use: "migrate",
Short: "Migrate legacy audit log configurations.",
Use: "migrate",
Short: "Migrate legacy audit log configurations.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireOnPremLogin},
}, prerunner)
command := &migrateCmd{
CLICommand: cliCmd,
Expand Down
21 changes: 11 additions & 10 deletions internal/cmd/audit-log/command_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import (
mds "github.com/confluentinc/mds-sdk-go/mdsv1"
"github.com/spf13/cobra"

"github.com/confluentinc/cli/internal/pkg/cmd"
pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
)

type routeCommand struct {
*cmd.AuthenticatedStateFlagCommand
prerunner cmd.PreRunner
*pcmd.AuthenticatedStateFlagCommand
prerunner pcmd.PreRunner
}

// NewRouteCommand returns the sub-command object for interacting with audit log route rules.
func NewRouteCommand(prerunner cmd.PreRunner) *cobra.Command {
cliCmd := cmd.NewAuthenticatedWithMDSStateFlagCommand(
func NewRouteCommand(prerunner pcmd.PreRunner) *cobra.Command {
cliCmd := pcmd.NewAuthenticatedWithMDSStateFlagCommand(
&cobra.Command{
Use: "route",
Short: "Return the audit log route rules.",
Long: "Return the routing rules that determine which auditable events are logged, and where.",
Use: "route",
Short: "Return the audit log route rules.",
Long: "Return the routing rules that determine which auditable events are logged, and where.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireOnPremLogin},
}, prerunner, RouteSubcommandFlags)
command := &routeCommand{
AuthenticatedStateFlagCommand: cliCmd,
Expand All @@ -38,7 +39,7 @@ func (c *routeCommand) init() {
Short: "List routes matching a resource & sub-resources.",
Long: "List the routes that match either the queried resource or its sub-resources.",
Args: cobra.NoArgs,
RunE: cmd.NewCLIRunE(c.list),
RunE: pcmd.NewCLIRunE(c.list),
}
listCmd.Flags().StringP("resource", "r", "", "The Confluent resource name (CRN) that is the subject of the query.")
check(listCmd.MarkFlagRequired("resource"))
Expand All @@ -50,7 +51,7 @@ func (c *routeCommand) init() {
Short: "Return the matching audit-log route rule.",
Long: "Return the single route that describes how audit log messages using this CRN would be routed, with all defaults populated.",
Args: cobra.ExactArgs(1),
RunE: cmd.NewCLIRunE(c.lookup),
RunE: pcmd.NewCLIRunE(c.lookup),
}
c.AddCommand(lookupCmd)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/audit-log/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (suite *AuditConfigTestSuite) newMockCmd(expect chan MockCall) *cobra.Comma
}
mdsClient := mds.NewAPIClient(mds.NewConfiguration())
mdsClient.AuditLogConfigurationApi = suite.mockApi
return New(suite.conf, cliMock.NewPreRunnerMock(nil, mdsClient, nil, suite.conf))
return New(cliMock.NewPreRunnerMock(nil, mdsClient, nil, suite.conf))
}

func TestAuditConfigTestSuite(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/cluster/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ type command struct {
func New(prerunner pcmd.PreRunner, metaClient Metadata) *cobra.Command {
cmd := &command{
StateFlagCommand: pcmd.NewAnonymousStateFlagCommand(&cobra.Command{
Use: "cluster",
Short: "Retrieve metadata about Confluent Platform clusters.",
Use: "cluster",
Short: "Retrieve metadata about Confluent Platform clusters.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireOnPremLogin},
}, prerunner, SubcommandFlags),
prerunner: prerunner,
metaClient: metaClient,
Expand Down
Loading

0 comments on commit 1bf9f61

Please sign in to comment.