Skip to content

Commit

Permalink
OCM-7805 | feat: Add delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterkepley committed May 1, 2024
1 parent 8e2a339 commit c8820ac
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea
/rosa-support
rosa-support

16 changes: 16 additions & 0 deletions cmd/rosa-support/create/cmd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright (c) 2024 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package create

import (
Expand Down
35 changes: 35 additions & 0 deletions cmd/rosa-support/delete/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright (c) 2024 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package delete

import (
"github.com/openshift-online/rosa-support/cmd/rosa-support/delete/tag"
"github.com/openshift-online/rosa-support/cmd/rosa-support/delete/vpc"
"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "delete",
Aliases: []string{"del"},
Short: "Delete a resource from stdin",
Long: "Delete a resource from stdin",
}

func init() {
Cmd.AddCommand(vpc.Cmd)
Cmd.AddCommand(tag.Cmd)
}
91 changes: 91 additions & 0 deletions cmd/rosa-support/delete/tag/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package tag

import (
"os"

awsClient "github.com/openshift-online/ocm-common/pkg/aws/aws_client"
logger "github.com/openshift-online/ocm-common/pkg/log"
"github.com/spf13/cobra"
)

var args struct {
region string
resourceID string
tagKey string
tagValue string
profileName string
}
var Cmd = &cobra.Command{
Use: "tag",
Short: "Delete tag",
Long: "Delete tag.",
Example: ` # Delete a tag from the resource
rosa-support delete tag --resource-id <vpc id> --region us-east-2 --tag-key key`,

Run: run,
}

func init() {
flags := Cmd.Flags()
flags.SortFlags = false
flags.StringVarP(
&args.region,
"region",
"",
"",
"Region of the resource (required)",
)
flags.StringVarP(
&args.profileName,
"profile-name",
"",
"",
"profile name to pass into aws client",
)
flags.StringVarP(
&args.resourceID,
"resource-id",
"",
"",
"id of the resource (required)",
)
flags.StringVarP(
&args.tagKey,
"tag-key",
"",
"",
"tag key of the resource (required)",
)
flags.StringVarP(
&args.tagValue,
"tag-value",
"",
"",
"tag value of the resource",
)

err := Cmd.MarkFlagRequired("resource-id")
if err != nil {
panic(err)
}
err = Cmd.MarkFlagRequired("region")
if err != nil {
panic(err)
}
err = Cmd.MarkFlagRequired("tag-key")
if err != nil {
panic(err)
}
}
func run(_ *cobra.Command, _ []string) {
client, err := awsClient.CreateAWSClient(args.profileName, args.region)
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
_, err = client.RemoveResourceTag(args.resourceID, args.tagKey, args.tagValue)
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
}
71 changes: 71 additions & 0 deletions cmd/rosa-support/delete/vpc/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package vpc

import (
"os"

logger "github.com/openshift-online/ocm-common/pkg/log"
vpcClient "github.com/openshift-online/ocm-common/pkg/test/vpc_client"

"github.com/spf13/cobra"
)

var args struct {
region string
totalClean bool
vpcID string
}
var Cmd = &cobra.Command{
Use: "vpc",
Short: "Delete vpc",
Long: "Delete vpc.",
Example: ` # Delete a vpc with vpc ID
ocmqe delete vpc --vpc-id <vpc id> --region us-east-2`,

Run: run,
}

func init() {
flags := Cmd.Flags()
flags.SortFlags = false
flags.StringVarP(
&args.region,
"region",
"",
"",
"Region of the vpc (required)",
)
flags.StringVarP(
&args.vpcID,
"vpc-id",
"",
"",
"id of the vpc (required)",
)
flags.BoolVarP(
&args.totalClean,
"total-clean",
"",
false,
"find the vpc with same name",
)
err := Cmd.MarkFlagRequired("vpc-id")
if err != nil {
panic(err)
}
err = Cmd.MarkFlagRequired("region")
if err != nil {
panic(err)
}
}
func run(cmd *cobra.Command, _ []string) {
vpc, err := vpcClient.GenerateVPCByID(args.vpcID, args.region)
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
err = vpc.DeleteVPCChain(args.totalClean)
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
}
18 changes: 18 additions & 0 deletions cmd/rosa-support/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/*
Copyright (c) 2024 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rosa_support

import (
"os"

"github.com/openshift-online/rosa-support/cmd/rosa-support/create"
"github.com/openshift-online/rosa-support/cmd/rosa-support/delete"
"github.com/openshift-online/rosa-support/cmd/rosa-support/version"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -42,4 +59,5 @@ func init() {

rootCmd.AddCommand(version.NewVersionCmd())
rootCmd.AddCommand(create.Cmd)
rootCmd.AddCommand(delete.Cmd)
}
19 changes: 18 additions & 1 deletion cmd/rosa-support/version/cmd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
/*
Copyright (c) 2024 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"fmt"
"os"

"github.com/openshift-online/rosa-support/pkg/version"
"github.com/spf13/cobra"
"os"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"github.com/openshift-online/rosa-support/cmd/rosa-support"
cli "github.com/openshift-online/rosa-support/cmd/rosa-support"
)

func main() {
rosa_support.Execute()
cli.Execute()
}

0 comments on commit c8820ac

Please sign in to comment.