Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support record ssh private key and update README.md #24

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/check-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23.2'
cache: false
- name: Ensure dependencies are downloaded
run: go mod download
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.54
version: v1.62.0
skip-cache: true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ fmt:

.PHONY: lint
lint:
golangci-lint run --timeout 5m0s
golangci-lint run --timeout 10m0s
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,18 @@ git push origin v0.0.1

`$ rosa-support delete vpc --vpc-id <vpc id> --region <region>`

* Prepare bastion
* *--region* is required where created the vpc-id
* *--availability-zone* is required on which zone to launch the bastion instance
* *--vpc-id* is required which should be VPC id used to launch cluster
* *--keypair-name* is required to generate temporary used to launch the proxy instance
* *--private-key-path* is required to record the generated private ssh key
* *--cidr-block* is NOT required, only IP address within CIDR block can access other resources through bastion proxy(default is 0.0.0.0/0)

`$ rosa-support create bastion --region us-east-2 --availability-zone us-east-2a --vpc-id <vpc id> --keypair-name <name> --private-key-path <path>`

* Destroy bastion,the bastion and related resources with VPC will be destroyed when clean VPC

`$ rosa-support delete vpc --vpc-id <vpc id> --region <region>`

Note that a repository administrator may need to push the tag to the repository due to access restrictions.
36 changes: 31 additions & 5 deletions cmd/rosa-support/create/bastion/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var args struct {
region string
vpcID string
availabilityZone string
privateKeyPath string
keyPairName string
cidr string
}

Expand All @@ -20,7 +22,7 @@ var Cmd = &cobra.Command{
Short: "Create bastion proxy",
Long: "Create bastion proxy.",
Example: ` # Create a bastion proxy in region 'us-east-2'
rosa-support create bastion --region us-east-2 --availability-zone us-east-2a --vpc-id <vpc id>`,
rosa-support create bastion --region us-east-2 --availability-zone us-east-2a --vpc-id <vpc id> --keypair-name <name> --private-key-path <path>`,

Run: run,
}
Expand All @@ -37,7 +39,7 @@ func init() {
)
err := Cmd.MarkFlagRequired("region")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
flags.StringVarP(
Expand All @@ -49,7 +51,7 @@ func init() {
)
err = Cmd.MarkFlagRequired("vpc-id")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
flags.StringVarP(
Expand All @@ -61,7 +63,31 @@ func init() {
)
err = Cmd.MarkFlagRequired("availability-zone")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
flags.StringVarP(
&args.keyPairName,
"keypair-name",
"",
"",
"key pair will be created with the name (required)",
)
err = Cmd.MarkFlagRequired("keypair-name")
if err != nil {
logger.LogError("%s", err.Error())
os.Exit(1)
}
flags.StringVarP(
&args.privateKeyPath,
"private-key-path",
"",
"",
"record generated private ssh key in the given path (required)",
)
err = Cmd.MarkFlagRequired("private-key-path")
if err != nil {
logger.LogError("%s", err.Error())
os.Exit(1)
}
flags.StringVarP(
Expand All @@ -79,7 +105,7 @@ func run(cmd *cobra.Command, _ []string) {
if err != nil {
panic(err)
}
instance, err := vpc.PrepareBastionProxy(args.availabilityZone, args.cidr)
instance, err := vpc.PrepareBastionProxy(args.availabilityZone, args.cidr, args.keyPairName, args.privateKeyPath)
if err != nil {
panic(err)
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/rosa-support/create/proxy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,33 @@ func init() {

err := Cmd.MarkFlagRequired("vpc-id")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
err = Cmd.MarkFlagRequired("region")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
err = Cmd.MarkFlagRequired("availability-zone")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
err = Cmd.MarkFlagRequired("ca-file")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
err = Cmd.MarkFlagRequired("keypair-name")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}

err = Cmd.MarkFlagRequired("private-key-path")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/rosa-support/create/sg/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func init() {
)
err := Cmd.MarkFlagRequired("vpc-id")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
err = Cmd.MarkFlagRequired("region")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/rosa-support/create/subnets/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
)
err := Cmd.MarkFlagRequired("region")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
flags.StringVarP(
Expand All @@ -51,7 +51,7 @@ func init() {
)
err = Cmd.MarkFlagRequired("availability-zones")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
flags.StringVarP(
Expand All @@ -63,7 +63,7 @@ func init() {
)
err = Cmd.MarkFlagRequired("vpc-id")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/rosa-support/create/vpc/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func init() {
func run(cmd *cobra.Command, _ []string) {
vpc, err := vpcClient.PrepareVPC(args.name, args.region, args.cidr, args.findExisting, "")
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}

Expand All @@ -92,7 +92,7 @@ func run(cmd *cobra.Command, _ []string) {
}
_, err = vpc.AWSClient.TagResource(vpc.VpcID, tagMap)
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/rosa-support/delete/tag/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func init() {
func run(_ *cobra.Command, _ []string) {
client, err := awsClient.CreateAWSClient(args.profileName, args.region)
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
_, err = client.RemoveResourceTag(args.resourceID, args.tagKey, args.tagValue)
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
}
4 changes: 2 additions & 2 deletions cmd/rosa-support/delete/vpc/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func init() {
func run(cmd *cobra.Command, _ []string) {
vpc, err := vpcClient.GenerateVPCByID(args.vpcID, args.region)
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
err = vpc.DeleteVPCChain(args.totalClean)
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion cmd/rosa-support/tag/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func init() {
for _, requiredFlag := range requiredFlags {
err := Cmd.MarkFlagRequired(requiredFlag)
if err != nil {
logger.LogError(err.Error())
logger.LogError("%s", err.Error())
os.Exit(1)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/openshift-online/rosa-support
go 1.21

require (
github.com/openshift-online/ocm-common v0.0.13
github.com/openshift-online/ocm-common v0.0.14-0.20241121072829-c1150dfc4289
github.com/spf13/cobra v1.8.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/openshift-online/ocm-common v0.0.13 h1:FUn4PwuxOLsGbyJIC+izQQxYP3hA6dW5z/ep4HbTE4Q=
github.com/openshift-online/ocm-common v0.0.13/go.mod h1:6MWje2NFNJ3IWpGs7BYj6DWagWXHyp8EnmYY7XFTtI4=
github.com/openshift-online/ocm-common v0.0.14-0.20241121072829-c1150dfc4289 h1:CYX7p1cLo4+BwjHlJXHDP/zPiNit32b6YO6R0lGW+ZQ=
github.com/openshift-online/ocm-common v0.0.14-0.20241121072829-c1150dfc4289/go.mod h1:6MWje2NFNJ3IWpGs7BYj6DWagWXHyp8EnmYY7XFTtI4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
Loading