Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/flink/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func addCmfFlagSet(cmd *cobra.Command) {
cmd.Flags().String("certificate-authority-path", "", `Path to a PEM-encoded Certificate Authority to verify the Confluent Manager for Apache Flink connection. Environment variable "CONFLUENT_CMF_CERTIFICATE_AUTHORITY_PATH" may be set in place of this flag.`)
}

func addPageSizeFlag(cmd *cobra.Command) {
cmd.Flags().Int32("page-size", 100, "Number of results to fetch per API request while paginating; does not cap the total results returned.")
}

func getPageSize(cmd *cobra.Command) (int32, error) {
return cmd.Flags().GetInt32("page-size")
}
Comment on lines +132 to +134

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we want to avoid client side validation for things that aren't recorded in the spec, so I think we should remove these checks and treat this like a regular flag read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in the latest commit.


func (c *command) createContext() context.Context {
if !c.Config.IsOnPremLogin() {
return context.Background()
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_application_event_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (c *command) newApplicationEventListCommand() *cobra.Command {

cmd.Flags().String("environment", "", "Name of the Flink environment.")
cmd.Flags().String("application", "", "Name of the Flink application.")
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

Expand All @@ -37,12 +38,17 @@ func (c *command) applicationEventList(cmd *cobra.Command, _ []string) error {
return err
}

pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

events, err := client.ListApplicationEvents(c.createContext(), environment, application)
events, err := client.ListApplicationEvents(c.createContext(), environment, application, pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_application_instance_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

cmd.Flags().String("environment", "", "Name of the Flink environment.")
cmd.Flags().String("application", "", "Name of the Flink application.")
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

Expand All @@ -26,7 +27,7 @@
return cmd
}

func (c *command) applicationInstanceList(cmd *cobra.Command, _ []string) error {

Check failure on line 30 in internal/flink/command_application_instance_list.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 24 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3424&issues=cbd254fd-4449-41c6-87ff-31236d12978a&open=cbd254fd-4449-41c6-87ff-31236d12978a
environment, err := cmd.Flags().GetString("environment")
if err != nil {
return err
Expand All @@ -37,12 +38,17 @@
return err
}

pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

instances, err := client.ListApplicationInstances(c.createContext(), environment, application)
instances, err := client.ListApplicationInstances(c.createContext(), environment, application, pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_application_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}

cmd.Flags().String("environment", "", "Name of the Flink environment.")
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

Expand All @@ -26,18 +27,23 @@
return cmd
}

func (c *command) applicationList(cmd *cobra.Command, _ []string) error {

Check failure on line 30 in internal/flink/command_application_list.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3424&issues=d1a3a975-811e-48c7-88ca-65461859389d&open=d1a3a975-811e-48c7-88ca-65461859389d
environment, err := cmd.Flags().GetString("environment")
if err != nil {
return err
}

pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

applications, err := client.ListApplications(c.createContext(), environment)
applications, err := client.ListApplications(c.createContext(), environment, pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_catalog_database_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (c *command) newCatalogDatabaseListCommand() *cobra.Command {

cmd.Flags().String("catalog", "", "Name of the catalog.")
cobra.CheckErr(cmd.MarkFlagRequired("catalog"))
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

Expand All @@ -29,12 +30,17 @@ func (c *command) catalogDatabaseList(cmd *cobra.Command, _ []string) error {
return err
}

pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

sdkDatabases, err := client.ListDatabases(c.createContext(), catalogName)
sdkDatabases, err := client.ListDatabases(c.createContext(), catalogName, pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_catalog_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@ func (c *command) newCatalogListCommand() *cobra.Command {
RunE: c.catalogList,
}

addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

return cmd
}

func (c *command) catalogList(cmd *cobra.Command, _ []string) error {
pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

sdkCatalogs, err := client.ListCatalog(c.createContext())
sdkCatalogs, err := client.ListCatalog(c.createContext(), pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_compute_pool_list_onprem.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (c *command) newComputePoolListCommandOnPrem() *cobra.Command {
}

cmd.Flags().String("environment", "", "Name of the Flink environment.")
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)
cobra.CheckErr(cmd.MarkFlagRequired("environment"))
Expand All @@ -30,12 +31,17 @@ func (c *command) computePoolListOnPrem(cmd *cobra.Command, _ []string) error {
return err
}

pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

sdkComputePools, err := client.ListComputePools(c.createContext(), environment)
sdkComputePools, err := client.ListComputePools(c.createContext(), environment, pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_detached_savepoint_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (c *command) newDetachedSavepointListCommand() *cobra.Command {
}

cmd.Flags().String("filter", "", "A filter expression to filter by detached savepoint name prefix.")
addPageSizeFlag(cmd)

pcmd.AddOutputFlag(cmd)
addCmfFlagSet(cmd)
Expand All @@ -41,7 +42,12 @@ func (c *command) detachedSavepointList(cmd *cobra.Command, args []string) error
return err
}

detachedSavepoints, err := client.ListDetachedSavepoint(c.createContext(), filter)
pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

detachedSavepoints, err := client.ListDetachedSavepoint(c.createContext(), filter, pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_environment_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (c *command) newEnvironmentListCommand() *cobra.Command {
RunE: c.environmentList,
}

addPageSizeFlag(cmd)
addCmfFlagSet(cmd)

pcmd.AddOutputFlag(cmd)
Expand All @@ -23,12 +24,17 @@ func (c *command) newEnvironmentListCommand() *cobra.Command {
}

func (c *command) environmentList(cmd *cobra.Command, _ []string) error {
pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

sdkEnvironments, err := client.ListEnvironments(c.createContext())
sdkEnvironments, err := client.ListEnvironments(c.createContext(), pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_savepoint_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (c *command) newSavepointListCommand() *cobra.Command {
cmd.Flags().String("environment", "", "Name of the Flink environment.")
cmd.Flags().String("application", "", "The name of the Flink application to list the savepoints.")
cmd.Flags().String("statement", "", "The name of the Flink statement to list the savepoints.")
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

Expand All @@ -45,12 +46,17 @@ func (c *command) savepointList(cmd *cobra.Command, _ []string) error {
return err
}

pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

sdkSavepoints, err := client.ListSavepoint(c.createContext(), environment, statement, application, statement != "")
sdkSavepoints, err := client.ListSavepoint(c.createContext(), environment, statement, application, statement != "", pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_secret_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@ func (c *command) newSecretListCommand() *cobra.Command {
RunE: c.secretList,
}

addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

return cmd
}

func (c *command) secretList(cmd *cobra.Command, _ []string) error {
pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

sdkSecrets, err := client.ListSecrets(c.createContext())
sdkSecrets, err := client.ListSecrets(c.createContext(), pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_secret_mapping_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,30 @@

cmd.Flags().String("environment", "", "Name of the Flink environment.")
cobra.CheckErr(cmd.MarkFlagRequired("environment"))
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

return cmd
}

func (c *command) secretMappingList(cmd *cobra.Command, _ []string) error {

Check failure on line 28 in internal/flink/command_secret_mapping_list.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3424&issues=5d7b3a74-cdfc-476d-8ad0-87bb5474993d&open=5d7b3a74-cdfc-476d-8ad0-87bb5474993d
environment, err := cmd.Flags().GetString("environment")
if err != nil {
return err
}

pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

client, err := c.GetCmfClient(cmd)
if err != nil {
return err
}

sdkMappings, err := client.ListSecretMappings(c.createContext(), environment)
sdkMappings, err := client.ListSecretMappings(c.createContext(), environment, pageSize)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/flink/command_statement_list_onprem.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (c *command) newStatementListCommandOnPrem() *cobra.Command {
cmd.Flags().String("environment", "", "Name of the Flink environment.")
cmd.Flags().String("compute-pool", "", "Optional flag to filter the Flink statements by compute pool ID.")
cmd.Flags().String("status", "", "Optional flag to filter the Flink statements by statement status.")
addPageSizeFlag(cmd)
addCmfFlagSet(cmd)
pcmd.AddOutputFlag(cmd)

Expand Down Expand Up @@ -57,7 +58,12 @@ func (c *command) statementListOnPrem(cmd *cobra.Command, _ []string) error {
return err
}

sdkStatements, err := client.ListStatements(c.createContext(), environment, computePool, status)
pageSize, err := getPageSize(cmd)
if err != nil {
return err
}

sdkStatements, err := client.ListStatements(c.createContext(), environment, computePool, status, pageSize)
if err != nil {
return err
}
Expand Down
Loading