Skip to content

Commit

Permalink
refactor: dedicated commands moved to kafka (#1839)
Browse files Browse the repository at this point in the history
* refactor: dedicated commands moved to kafka

* refactor: move source of dedicated to kafka pkg

---------

Co-authored-by: Dimitri Saridakis <dimitri.saridakis@gmail.com>
  • Loading branch information
jackdelahunt and dimakis authored Mar 24, 2023
1 parent b96e3fa commit 44539ab
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 132 deletions.
28 changes: 0 additions & 28 deletions pkg/cmd/dedicated/dedicated.go

This file was deleted.

10 changes: 5 additions & 5 deletions pkg/cmd/kafka/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/redhat-developer/app-services-cli/internal/build"
"github.com/redhat-developer/app-services-cli/pkg/cmd/dedicated/dedicatedcmdutil"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/openshift-cluster/openshiftclustercmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/auth/token"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection/api/clustermgmt"
"github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
Expand Down Expand Up @@ -167,8 +167,8 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command {
flags.StringVar(&opts.billingModel, FlagBillingModel, "", f.Localizer.MustLocalize("kafka.common.flag.billingModel.description"))
flags.AddBypassTermsCheck(&opts.bypassChecks)
flags.StringVar(&opts.clusterId, "cluster-id", "", f.Localizer.MustLocalize("kafka.create.flag.clusterId.description"))
flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("dedicated.registerCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("dedicated.registercluster.flag.accessToken.description"))
flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("kafka.openshiftCluster.registerCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("kafka.openshiftCluster.registercluster.flag.accessToken.description"))

_ = cmd.RegisterFlagCompletionFunc(FlagProvider, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return GetCloudProviderCompletionValues(f)
Expand All @@ -194,7 +194,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command {
return GetBillingModelCompletionValues(f)
})

dedicatedcmdutil.HideClusterMgmtFlags(flags)
openshiftclustercmdutil.HideClusterMgmtFlags(flags)

return cmd
}
Expand Down Expand Up @@ -977,7 +977,7 @@ func getClusterNameMap(opts *options, clusterList *kafkamgmtclient.EnterpriseClu
}

func selectClusterPrompt(opts *options) (int, error) {
promptOptions := dedicatedcmdutil.CreatePromptOptionsFromClusters(opts.kfmClusterList, opts.clusterMap)
promptOptions := openshiftclustercmdutil.CreatePromptOptionsFromClusters(opts.kfmClusterList, opts.clusterMap)
promptForCluster := &survey.Select{
Message: opts.f.Localizer.MustLocalize("kafka.create.input.cluster.selectClusterMessage"),
Options: *promptOptions,
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/delete"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/describe"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/list"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/openshift-cluster"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/promote"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/providers"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/topic"
Expand Down Expand Up @@ -44,6 +45,7 @@ func NewKafkaCommand(f *factory.Factory) *cobra.Command {
billing.NewBillingCommand(f),
providers.NewProviderCommand(f),
promote.NewPromoteCommand(f),
openshift_cluster.NewDedicatedCmd(f),
)

return cmd
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/kafka/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
flags.IntVar(&opts.page, "page", int(cmdutil.ConvertPageValueToInt32(build.DefaultPageNumber)), opts.f.Localizer.MustLocalize("kafka.list.flag.page"))
flags.IntVar(&opts.limit, "limit", int(cmdutil.ConvertPageValueToInt32(build.DefaultPageSize)), opts.f.Localizer.MustLocalize("kafka.list.flag.limit"))
flags.StringVar(&opts.search, "search", "", opts.f.Localizer.MustLocalize("kafka.list.flag.search"))
flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("dedicated.registerCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("dedicated.registercluster.flag.accessToken.description"))
flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("kafka.openshiftCluster.registerCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("kafka.openshiftCluster.registercluster.flag.accessToken.description"))

_ = flags.MarkHidden("cluster-mgmt-api-url")
_ = flags.MarkHidden("access-token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/AlecAivazis/survey/v2"
clustersmgmtv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/redhat-developer/app-services-cli/internal/build"
"github.com/redhat-developer/app-services-cli/pkg/cmd/dedicated/dedicatedcmdutil"
kafkaFlagutil "github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/openshift-cluster/openshiftclustercmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection/api/clustermgmt"
Expand Down Expand Up @@ -43,21 +43,21 @@ func NewDeRegisterClusterCommand(f *factory.Factory) *cobra.Command {

cmd := &cobra.Command{
Use: "deregister-cluster",
Short: f.Localizer.MustLocalize("dedicated.deregisterCluster.cmd.shortDescription"),
Long: f.Localizer.MustLocalize("dedicated.deregisterCluster.cmd.longDescription"),
Example: f.Localizer.MustLocalize("dedicated.deregisterCluster.cmd.example"),
Short: f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.cmd.shortDescription"),
Long: f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.cmd.longDescription"),
Example: f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.cmd.example"),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runDeRegisterClusterCmd(opts)
},
}

flags := kafkaFlagutil.NewFlagSet(cmd, f.Localizer)
flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("dedicated.deregisterCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("dedicated.deregistercluster.flag.accessToken.description"))
flags.StringVar(&opts.selectedClusterId, "cluster-id", "", f.Localizer.MustLocalize("dedicated.deregisterCluster.flag.clusterId.description"))
flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("kafka.openshiftCluster.deregistercluster.flag.accessToken.description"))
flags.StringVar(&opts.selectedClusterId, "cluster-id", "", f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.flag.clusterId.description"))

dedicatedcmdutil.HideClusterMgmtFlags(flags)
openshiftclustercmdutil.HideClusterMgmtFlags(flags)

return cmd
}
Expand All @@ -69,7 +69,7 @@ func runDeRegisterClusterCmd(opts *options) error {
}

if len(clusterList) == 0 {
return opts.f.Localizer.MustLocalizeError("dedicated.deregisterCluster.run.noClusterFound")
return opts.f.Localizer.MustLocalizeError("kafka.openshiftCluster.deregisterCluster.run.noClusterFound")
}

if opts.selectedClusterId == "" {
Expand All @@ -86,7 +86,7 @@ func runDeRegisterClusterCmd(opts *options) error {
}

if opts.selectedCluster == nil {
return opts.f.Localizer.MustLocalizeError("dedicated.deregisterCluster.noClusterFoundFromIdFlag", localize.NewEntry("ID", opts.selectedClusterId))
return opts.f.Localizer.MustLocalizeError("kafka.openshiftCluster.deregisterCluster.noClusterFoundFromIdFlag", localize.NewEntry("ID", opts.selectedClusterId))
}
}

Expand All @@ -95,7 +95,7 @@ func runDeRegisterClusterCmd(opts *options) error {
return err
}

opts.f.Logger.Info(opts.f.Localizer.MustLocalize("dedicated.deregisterCluster.kafka.delete.warning"))
opts.f.Logger.Info(opts.f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.kafka.delete.warning"))

err = deleteKafkasPrompt(opts, &kafkas)
if err != nil {
Expand All @@ -122,7 +122,7 @@ func getListOfClusters(opts *options) ([]*clustersmgmtv1.Cluster, error) {
if err != nil {
if response != nil {
if response.StatusCode == 403 {
return nil, opts.f.Localizer.MustLocalizeError("dedicated.deregisterCluster.error.403")
return nil, opts.f.Localizer.MustLocalizeError("kafka.openshiftCluster.deregisterCluster.error.403")
}
return nil, fmt.Errorf("%v: %w", response.Status, err)
}
Expand Down Expand Up @@ -233,16 +233,16 @@ func deleteKafkasPrompt(opts *options, kafkas *[]kafkamgmtclient.KafkaRequest) e
checkIfDeletedIdList = append(checkIfDeletedIdList[:i], checkIfDeletedIdList[i+1:]...)
break
} else {
return fmt.Errorf(fmt.Sprintf("%v, %v", opts.f.Localizer.MustLocalize("dedicated.deregisterCluster.kafka.delete.failed"), response.Status))
return fmt.Errorf(fmt.Sprintf("%v, %v", opts.f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.kafka.delete.failed"), response.Status))
}
}
}

opts.f.Logger.Info(opts.f.Localizer.MustLocalize("dedicated.deregisterCluster.deletingKafka.message"))
opts.f.Logger.Info(opts.f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.deletingKafka.message"))
time.Sleep(5 * time.Second)
}

opts.f.Logger.Info(opts.f.Localizer.MustLocalize("dedicated.deregisterCluster.deletingKafka.success"))
opts.f.Logger.Info(opts.f.Localizer.MustLocalize("kafka.openshiftCluster.deregisterCluster.deletingKafka.success"))
return nil
}

Expand All @@ -254,7 +254,7 @@ func runClusterSelectionInteractivePrompt(opts *options, clusterList *[]*cluster
}

prompt := &survey.Select{
Message: opts.f.Localizer.MustLocalize("dedicated.registerCluster.prompt.selectCluster.message"),
Message: opts.f.Localizer.MustLocalize("kafka.openshiftCluster.registerCluster.prompt.selectCluster.message"),
Options: clusterStringList,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
clustersmgmtv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/redhat-developer/app-services-cli/internal/build"
"github.com/redhat-developer/app-services-cli/pkg/cmd/dedicated/dedicatedcmdutil"
kafkaFlagutil "github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/openshift-cluster/openshiftclustercmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection/api/clustermgmt"
Expand Down Expand Up @@ -40,9 +40,9 @@ func NewListClusterCommand(f *factory.Factory) *cobra.Command {

cmd := &cobra.Command{
Use: "list",
Short: f.Localizer.MustLocalize("dedicated.list.cmd.shortDescription"),
Long: f.Localizer.MustLocalize("dedicated.list.cmd.longDescription"),
Example: f.Localizer.MustLocalize("dedicated.list.cmd.example"),
Short: f.Localizer.MustLocalize("kafka.openshiftCluster.list.cmd.shortDescription"),
Long: f.Localizer.MustLocalize("kafka.openshiftCluster.list.cmd.longDescription"),
Example: f.Localizer.MustLocalize("kafka.openshiftCluster.list.cmd.example"),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runListClusters(opts, f)
Expand All @@ -51,10 +51,10 @@ func NewListClusterCommand(f *factory.Factory) *cobra.Command {

flags := kafkaFlagutil.NewFlagSet(cmd, f.Localizer)

flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("dedicated.registerCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("dedicated.registercluster.flag.accessToken.description"))
flags.StringVar(&opts.clusterManagementApiUrl, "cluster-mgmt-api-url", "", f.Localizer.MustLocalize("kafka.openshiftCluster.registerCluster.flag.clusterMgmtApiUrl.description"))
flags.StringVar(&opts.accessToken, "access-token", "", f.Localizer.MustLocalize("kafka.openshiftCluster.registercluster.flag.accessToken.description"))

dedicatedcmdutil.HideClusterMgmtFlags(flags)
openshiftclustercmdutil.HideClusterMgmtFlags(flags)

return cmd

Expand All @@ -66,7 +66,7 @@ func runListClusters(opts *options, f *factory.Factory) error {

if response != nil {
if response.StatusCode == 403 {
return opts.f.Localizer.MustLocalizeError("dedicated.list.error.permissionDenied")
return opts.f.Localizer.MustLocalizeError("kafka.openshiftCluster.list.error.permissionDenied")
}

return fmt.Errorf("%v, %w", response.Status, err)
Expand All @@ -82,7 +82,7 @@ func runListClusters(opts *options, f *factory.Factory) error {
return err
}
if clist == nil {
return opts.f.Localizer.MustLocalizeError("dedicated.list.error.noRegisteredClustersFound")
return opts.f.Localizer.MustLocalizeError("kafka.openshiftCluster.list.error.noRegisteredClustersFound")
}
opts.clustermgmtClusterList = clist
opts.registeredClusters = kfmListToClusterRowList(opts)
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions pkg/cmd/kafka/openshift-cluster/openshift-cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package openshift_cluster

import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/openshift-cluster/deregister"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/openshift-cluster/list"
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/openshift-cluster/register"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/spf13/cobra"
)

func NewDedicatedCmd(f *factory.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "openshift-cluster",
Short: f.Localizer.MustLocalize("kafka.openshiftCluster.cmd.shortDescription"),
Long: f.Localizer.MustLocalize("kafka.openshiftCluster.cmd.longDescription"),
Example: f.Localizer.MustLocalize("kafka.openshiftCluster.cmd.example"),
}

cmd.Aliases = append(cmd.Aliases, "oc")

cmd.AddCommand(
register.NewRegisterClusterCommand(f),
list.NewListClusterCommand(f),
deregister.NewDeRegisterClusterCommand(f),
)

cmd.Hidden = true

return cmd
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dedicatedcmdutil
package openshiftclustercmdutil

import (
"fmt"
Expand Down
Loading

0 comments on commit 44539ab

Please sign in to comment.