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

feat: Allow endpoint url to be passed through to aws clients #48

Merged
merged 2 commits into from
Oct 9, 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: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ 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 |
| `--enable-env` | `-v` | Enable ENV population of cli args | `false` |



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
11 changes: 11 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 @@ -67,6 +68,12 @@ Requires pre-existing installation of the session-manager-plugin
fmt.Printf(fmt.Sprintf("%s\n", app.Yellow("The service argument will be ignored when task is specified")))
viper.Set("service", "")
}

if viper.GetBool("enable-env") {
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
}

return nil
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -94,6 +101,8 @@ 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")
rootCmd.PersistentFlags().BoolP("enable-env", "v", false, "Enable ENV population of cli args")

viper.BindPFlag("cmd", rootCmd.PersistentFlags().Lookup("cmd"))
viper.BindPFlag("profile", rootCmd.PersistentFlags().Lookup("profile"))
Expand All @@ -105,4 +114,6 @@ 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"))
viper.BindPFlag("enable-env", rootCmd.PersistentFlags().Lookup("enable-env"))
}
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)},
tedsmitt marked this conversation as resolved.
Show resolved Hide resolved
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
Loading