Skip to content

Commit

Permalink
adapt for concentration rules and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
achever1 committed Jul 17, 2024
1 parent 4232d30 commit 32667ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions client/gatway_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (client *GatewayClient) Get(kind *schema.Kind, parentPathValue []string) ([
return result, err
}

func (client *GatewayClient) GetAliasTopics(kind *schema.Kind, param map[string]string) ([]resource.Resource, error) {
func (client *GatewayClient) ListKindWithFilters(kind *schema.Kind, param map[string]string) ([]resource.Resource, error) {
var result []resource.Resource
url := client.baseUrl + kind.ListPath(nil)
req := client.client.R()
Expand Down Expand Up @@ -130,7 +130,7 @@ func (client *GatewayClient) Delete(kind *schema.Kind, parentPathValue []string,
return err
}

func (client *GatewayClient) DeleteAliasTopics(kind *schema.Kind, param map[string]string) error {
func (client *GatewayClient) DeleteKindByNameAndVCluster(kind *schema.Kind, param map[string]string) error {
url := client.baseUrl + kind.ListPath(nil)
req := client.client.R()
req.SetBody(
Expand Down
14 changes: 7 additions & 7 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func initDelete(kinds schema.KindCatalog) {
deleteCmd.MarkFlagRequired("file")

for name, kind := range kinds {
if name == "AliasTopics" {
aliasTopicDeleteCmd := buildDeleteAliasTopicCmd(name, kind)
if name == "AliasTopics" || name == "ConcentrationRules" {
aliasTopicDeleteCmd := buildDeleteByVClusterAndNameCmd(name, kind)
deleteCmd.AddCommand(aliasTopicDeleteCmd)
} else {
flags := kind.GetFlag()
Expand Down Expand Up @@ -78,14 +78,14 @@ func initDelete(kinds schema.KindCatalog) {
}
}

func buildDeleteAliasTopicCmd(name string, kind schema.Kind) *cobra.Command {
func buildDeleteByVClusterAndNameCmd(name string, kind schema.Kind) *cobra.Command {
const nameFlag = "name"
const vClusterFlag = "vcluster"
var nameValue string
var vClusterValue string
var aliasTopicDeleteCmd = &cobra.Command{
Use: fmt.Sprintf("%s [name]", name),
Short: "Delete an Alias Topic",
Short: "Delete resource of kind " + kind.GetName(),
Args: cobra.ExactArgs(0),
Aliases: []string{strings.ToLower(name), strings.ToLower(name) + "s", name + "s"},
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -100,16 +100,16 @@ func buildDeleteAliasTopicCmd(name string, kind schema.Kind) *cobra.Command {
queryParams[vClusterFlag] = "passthrough"
}

err = gatewayApiClient().DeleteAliasTopics(&kind, queryParams)
err = gatewayApiClient().DeleteKindByNameAndVCluster(&kind, queryParams)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
},
}

aliasTopicDeleteCmd.Flags().StringVar(&nameValue, nameFlag, "", "name of the alias topic")
aliasTopicDeleteCmd.Flags().StringVar(&vClusterValue, "vCluster", "", "vCluster of the alias topic")
aliasTopicDeleteCmd.Flags().StringVar(&nameValue, nameFlag, "", "name of the "+kind.GetName())
aliasTopicDeleteCmd.Flags().StringVar(&vClusterValue, vClusterFlag, "", "vCluster of the "+kind.GetName())

aliasTopicDeleteCmd.MarkFlagRequired(nameFlag)
aliasTopicDeleteCmd.MarkFlagRequired(vClusterFlag)
Expand Down
14 changes: 7 additions & 7 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func initGet(kinds schema.KindCatalog) {
rootCmd.AddCommand(getCmd)

for name, kind := range kinds {
if name == "AliasTopics" {
aliasTopicGetCmd := buildGetAliasTopicCmd(name, kind)
if name == "AliasTopics" || name == "ConcentrationRules" {
aliasTopicGetCmd := buildListFilteredByVClusterOrNameCmd(name, kind)
getCmd.AddCommand(aliasTopicGetCmd)
} else {
flags := kind.GetFlag()
Expand Down Expand Up @@ -74,7 +74,7 @@ func initGet(kinds schema.KindCatalog) {
}
}

func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command {
func buildListFilteredByVClusterOrNameCmd(name string, kind schema.Kind) *cobra.Command {
const nameFlag = "name"
const vClusterFlag = "vcluster"
const showDefaultsFlag = "showDefaults"
Expand All @@ -83,7 +83,7 @@ func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command {
var showDefaultsValue string
var aliasTopicGetCmd = &cobra.Command{
Use: fmt.Sprintf("%s [name]", name),
Short: "List Alias Topics",
Short: "Get resource of kind " + kind.GetName(),
Args: cobra.ExactArgs(0),
Aliases: []string{strings.ToLower(name), strings.ToLower(name) + "s", name + "s"},
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -100,7 +100,7 @@ func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command {
queryParams[showDefaultsFlag] = showDefaultsValue
}

result, err = gatewayApiClient().GetAliasTopics(&kind, queryParams)
result, err = gatewayApiClient().ListKindWithFilters(&kind, queryParams)
for _, r := range result {
r.PrintPreservingOriginalFieldOrder()
fmt.Println("---")
Expand All @@ -112,8 +112,8 @@ func buildGetAliasTopicCmd(name string, kind schema.Kind) *cobra.Command {
},
}

aliasTopicGetCmd.Flags().StringVar(&nameValue, nameFlag, "", "filter the alias topic result list by name")
aliasTopicGetCmd.Flags().StringVar(&vClusterValue, "vCluster", "", "filter the alias topic result list by vcluster")
aliasTopicGetCmd.Flags().StringVar(&nameValue, nameFlag, "", "filter the "+kind.GetName()+" result list by name")
aliasTopicGetCmd.Flags().StringVar(&vClusterValue, vClusterFlag, "", "filter the "+kind.GetName()+" result list by vcluster")
aliasTopicGetCmd.Flags().StringVar(&showDefaultsValue, "showDefaults", "", "Toggle show defaults values (true|false, default false)")

return aliasTopicGetCmd
Expand Down

0 comments on commit 32667ea

Please sign in to comment.