Skip to content

Commit

Permalink
Merge pull request #23 from jameszwang/ocm-11855
Browse files Browse the repository at this point in the history
OCM-11855 | test: Support bastion proxy
  • Loading branch information
xueli181114 authored Nov 18, 2024
2 parents ccdac81 + e76af40 commit 9f19993
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
95 changes: 95 additions & 0 deletions cmd/rosa-support/create/bastion/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package bastion

import (
"fmt"
logger "github.com/openshift-online/ocm-common/pkg/log"
vpcClient "github.com/openshift-online/ocm-common/pkg/test/vpc_client"
"github.com/spf13/cobra"
"os"
)

var args struct {
region string
vpcID string
availabilityZone string
cidr string
}

var Cmd = &cobra.Command{
Use: "bastion",
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>`,

Run: run,
}

func init() {
flags := Cmd.Flags()
flags.SortFlags = false
flags.StringVarP(
&args.region,
"region",
"",
"",
"Vpc region (required)",
)
err := Cmd.MarkFlagRequired("region")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
flags.StringVarP(
&args.vpcID,
"vpc-id",
"",
"",
"ID of vpc to be used to create bastion proxy (required)",
)
err = Cmd.MarkFlagRequired("vpc-id")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
flags.StringVarP(
&args.availabilityZone,
"availability-zone",
"",
"",
"Availability zone to create public subnet of specified vpc (required)",
)
err = Cmd.MarkFlagRequired("availability-zone")
if err != nil {
logger.LogError(err.Error())
os.Exit(1)
}
flags.StringVarP(
&args.cidr,
"cidr-block",
"",
"",
"Only IP address within CIDR block can access other resources through bastion "+
"proxy(not required, default is 0.0.0.0/0)",
)
}

func run(cmd *cobra.Command, _ []string) {
vpc, err := vpcClient.GenerateVPCByID(args.vpcID, args.region)
if err != nil {
panic(err)
}
instance, err := vpc.PrepareBastionProxy(args.availabilityZone, args.cidr)
if err != nil {
panic(err)
}

inst := *instance
publicIp := *inst.PublicIpAddress
httpProxy := fmt.Sprintf("http://%s:3128", publicIp)
httpsProxy := fmt.Sprintf("https://%s:3128", publicIp)
logger.LogInfo("Bastion instance ID: %s", *inst.InstanceId)
logger.LogInfo("Bastion HTTP PROXY: %s", httpProxy)
logger.LogInfo("Bastion HTTPs PROXY: %s", httpsProxy)

}
2 changes: 2 additions & 0 deletions cmd/rosa-support/create/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package create

import (
"github.com/openshift-online/rosa-support/cmd/rosa-support/create/bastion"
"github.com/openshift-online/rosa-support/cmd/rosa-support/create/proxy"
"github.com/openshift-online/rosa-support/cmd/rosa-support/create/sg"
subnets "github.com/openshift-online/rosa-support/cmd/rosa-support/create/subnets"
Expand All @@ -36,4 +37,5 @@ func init() {
Cmd.AddCommand(sg.Cmd)
Cmd.AddCommand(subnets.Cmd)
Cmd.AddCommand(proxy.Cmd)
Cmd.AddCommand(bastion.Cmd)
}
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.12
github.com/openshift-online/ocm-common v0.0.13
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.12 h1:2oGZCXd8O/nZVlM0pvTtm3hDGbW/ncTtvSLLB+nuQf0=
github.com/openshift-online/ocm-common v0.0.12/go.mod h1:6MWje2NFNJ3IWpGs7BYj6DWagWXHyp8EnmYY7XFTtI4=
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/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

0 comments on commit 9f19993

Please sign in to comment.