-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from jameszwang/ocm-11855
OCM-11855 | test: Support bastion proxy
- Loading branch information
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters