diff --git a/.gitignore b/.gitignore index 8e7f8de..79b814a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .idea /rosa-support -rosa-support diff --git a/cmd/rosa-support/create/cmd.go b/cmd/rosa-support/create/cmd.go index 61047b9..be19ed9 100644 --- a/cmd/rosa-support/create/cmd.go +++ b/cmd/rosa-support/create/cmd.go @@ -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 ( diff --git a/cmd/rosa-support/delete/cmd.go b/cmd/rosa-support/delete/cmd.go new file mode 100644 index 0000000..8ed16c5 --- /dev/null +++ b/cmd/rosa-support/delete/cmd.go @@ -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) +} diff --git a/cmd/rosa-support/delete/tag/cmd.go b/cmd/rosa-support/delete/tag/cmd.go new file mode 100644 index 0000000..3a82daa --- /dev/null +++ b/cmd/rosa-support/delete/tag/cmd.go @@ -0,0 +1,95 @@ +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 --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)", + ) + + 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) + } + err = Cmd.MarkFlagRequired("tag-value") + 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) + } +} diff --git a/cmd/rosa-support/delete/vpc/cmd.go b/cmd/rosa-support/delete/vpc/cmd.go new file mode 100644 index 0000000..26fac55 --- /dev/null +++ b/cmd/rosa-support/delete/vpc/cmd.go @@ -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 --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) + } +} diff --git a/cmd/rosa-support/root.go b/cmd/rosa-support/root.go index 1d37f0d..7363b38 100644 --- a/cmd/rosa-support/root.go +++ b/cmd/rosa-support/root.go @@ -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" @@ -42,4 +59,5 @@ func init() { rootCmd.AddCommand(version.NewVersionCmd()) rootCmd.AddCommand(create.Cmd) + rootCmd.AddCommand(delete.Cmd) } diff --git a/cmd/rosa-support/version/cmd.go b/cmd/rosa-support/version/cmd.go index bc7c115..e081fac 100644 --- a/cmd/rosa-support/version/cmd.go +++ b/cmd/rosa-support/version/cmd.go @@ -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 ( diff --git a/main.go b/main.go index 6e19076..37159f2 100644 --- a/main.go +++ b/main.go @@ -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() }