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 2838a09
Show file tree
Hide file tree
Showing 8 changed files with 237 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) 2019 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) 2019 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)
}
83 changes: 83 additions & 0 deletions cmd/rosa-support/delete/tag/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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 --tag-value value`,

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 (required)",
)

Cmd.MarkFlagRequired("resource-id")

Check failure on line 67 in cmd/rosa-support/delete/tag/cmd.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `Cmd.MarkFlagRequired` is not checked (errcheck)
Cmd.MarkFlagRequired("region")

Check failure on line 68 in cmd/rosa-support/delete/tag/cmd.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `Cmd.MarkFlagRequired` is not checked (errcheck)
Cmd.MarkFlagRequired("tag-key")

Check failure on line 69 in cmd/rosa-support/delete/tag/cmd.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `Cmd.MarkFlagRequired` is not checked (errcheck)
Cmd.MarkFlagRequired("tag-value")
}
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)
}
}
65 changes: 65 additions & 0 deletions cmd/rosa-support/delete/vpc/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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",
)
Cmd.MarkFlagRequired("vpc-id")
Cmd.MarkFlagRequired("region")
}
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) 2019 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) 2019 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 2838a09

Please sign in to comment.