Skip to content

Commit

Permalink
feat: Allow endpoint url to be passed through to aws clients
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeforkin committed Sep 16, 2024
1 parent 5012383 commit 68e578d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ By default, the tool will prompt you to interactively select which cluster, serv
| `--profile` | `-p` | Specify the profile to load the credentials | `default` |
| `--region` | `-r` | Specify the AWS region to run in | N/A |
| `--quiet` | `-q` | Disable output detailing the Cluster/Service/Task information | `false` |
| `--aws-endpoint-url` | `-e` | Specify the AWS endpoint used for all service requests | N/A |

The tool also supports AWS Config/Environment Variables for configuration. If you aren't familiar with working on AWS via the CLI, you can read more about how to configure your environment [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html).

Expand Down
6 changes: 6 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main
import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -94,6 +95,10 @@ func init() {
rootCmd.PersistentFlags().BoolP("forward", "f", false, "Port Forward")
rootCmd.PersistentFlags().StringP("local-port", "l", "", "Local port for use with port forwarding")
rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Do not print cluster and container information")
rootCmd.PersistentFlags().StringP("aws-endpoint-url", "e", "", "AWS Endpoint Url")

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()

viper.BindPFlag("cmd", rootCmd.PersistentFlags().Lookup("cmd"))
viper.BindPFlag("profile", rootCmd.PersistentFlags().Lookup("profile"))
Expand All @@ -105,4 +110,5 @@ func init() {
viper.BindPFlag("forward", rootCmd.PersistentFlags().Lookup("forward"))
viper.BindPFlag("local-port", rootCmd.PersistentFlags().Lookup("local-port"))
viper.BindPFlag("quiet", rootCmd.PersistentFlags().Lookup("quiet"))
viper.BindPFlag("aws-endpoint-url", rootCmd.PersistentFlags().Lookup("aws-endpoint-url"))
}
9 changes: 6 additions & 3 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func createOpts(opts []string) []string {

func createEcsClient() *ecs.ECS {
region := viper.GetString("region")
endpointUrl := viper.GetString("aws-endpoint-url")
sess := session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{Region: aws.String(region)},
Config: aws.Config{Region: aws.String(region), Endpoint: aws.String(endpointUrl)},
Profile: viper.GetString("profile"),
SharedConfigState: session.SharedConfigEnable,
}))
Expand All @@ -52,8 +53,9 @@ func createEcsClient() *ecs.ECS {

func createEc2Client() *ec2.EC2 {
region := viper.GetString("region")
endpointUrl := viper.GetString("aws-endpoint-url")
sess := session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{Region: aws.String(region)},
Config: aws.Config{Region: aws.String(region), Endpoint: aws.String(endpointUrl)},
Profile: viper.GetString("profile"),
SharedConfigState: session.SharedConfigEnable,
}))
Expand All @@ -64,8 +66,9 @@ func createEc2Client() *ec2.EC2 {

func createSSMClient() *ssm.SSM {
region := viper.GetString("region")
endpointUrl := viper.GetString("aws-endpoint-url")
sess := session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{Region: aws.String(region)},
Config: aws.Config{Region: aws.String(region), Endpoint: aws.String(endpointUrl)},
Profile: viper.GetString("profile"),
SharedConfigState: session.SharedConfigEnable,
}))
Expand Down

0 comments on commit 68e578d

Please sign in to comment.