From ec49be4309e3c29cfe05fb42097bc5f36fbdc30d Mon Sep 17 00:00:00 2001 From: LuciferInLove Date: Sun, 26 Sep 2021 12:11:48 +0300 Subject: [PATCH] Added public ip support --- CHANGELOG.md | 8 +++++++- README.md | 5 +++-- instances.go | 11 +++++++++-- main.go | 10 ++++++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbdd6bb..12dbd6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.5] - 2021-09-26 + +### Changed +- Added public ip support + ## [0.0.4] - 2021-09-26 ### Changed @@ -32,7 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial release -[unreleased]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.4...HEAD +[unreleased]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.5...HEAD +[0.0.5]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.4...v0.0.5 [0.0.4]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.3...v0.0.4 [0.0.3]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.2...v0.0.3 [0.0.2]: https://github.com/LuciferInLove/dynamic-sshmenu-aws/compare/v0.0.1...v0.0.2 diff --git a/README.md b/README.md index 82a1caa..9d2d4f0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Dynamically creates a menu containing a list of AWS EC2 instances selected using ## Overview -**dynamic-sshmenu-aws** generates sshmenu-style lists to connect to aws instances. It searches instances by aws instances tags that you can define as arguments. **dynamic-sshmenu-aws** executes `ssh __ip_address__` after choosing a menu item. Only private ip addresses are supported. +**dynamic-sshmenu-aws** generates sshmenu-style lists to connect to aws instances. It searches instances by aws instances tags that you can define as arguments. **dynamic-sshmenu-aws** executes `ssh __ip_address__` after choosing a menu item. ## Preparations for using @@ -16,7 +16,7 @@ First of all, you should setup credentials to interact with AWS services: * [via awscli](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) * [manually](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials) -Then you should setup ssh client to connect to aws instances via private addresses. If you are using bastion server, you can set it as proxy in ssh config as follows: +If you are using bastion server, you can set it as proxy in ssh config as follows: ``` Host 172.31.*.* @@ -38,6 +38,7 @@ You can see the **dynamic-sshmenu-aws** help by running it without arguments or --tags value, -t value instance tags in "key1:value1,value2;key2:value1" format. If undefined, full list will be shown --display-name value, -d value key of instance tag to display its values in results (default: "Name") + --public-ip, -p use public ip instead of private (default: false) --help, -h show help --version, -v print the version diff --git a/instances.go b/instances.go index b5a4a81..381859a 100644 --- a/instances.go +++ b/instances.go @@ -9,7 +9,7 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" ) -func getSliceOfInstances(tags string, displayName string) ([]instance, error) { +func getSliceOfInstances(tags string, displayName string, publicIP bool) ([]instance, error) { var ( i int = 1 sliceOfInstances []instance @@ -69,9 +69,16 @@ func getSliceOfInstances(tags string, displayName string) ([]instance, error) { instanceName = *tag.Value } } + + var instanceIP string + if publicIP { + instanceIP = *inst.PublicIpAddress + } else { + instanceIP = *inst.PrivateIpAddress + } currentInstance := instance{ Number: i, - IP: *inst.PrivateIpAddress, + IP: instanceIP, Name: instanceName, Zone: *inst.Placement.AvailabilityZone, } diff --git a/main.go b/main.go index b653352..e438681 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ type instance struct { } var ( - version = "v0.0.4" + version = "v0.0.5" appAuthor *cli.Author = &cli.Author{ Name: "LuciferInLove", Email: "lucifer.in.love@protonmail.com", @@ -59,6 +59,12 @@ func main() { Usage: "key of instance tag to display its values in results", Value: "Name", }, + &cli.BoolFlag{ + Name: "public-ip", + Aliases: []string{"p"}, + Usage: "use public ip instead of private", + Value: false, + }, } app.RunAndExitOnError() @@ -163,7 +169,7 @@ func parseResult(result string) (instance, error) { } func action(c *cli.Context) error { - instances, err := getSliceOfInstances(c.String("tags"), c.String("display-name")) + instances, err := getSliceOfInstances(c.String("tags"), c.String("display-name"), c.Bool("public-ip")) if err != nil { if err.Error() == "WrongTagDefinition" {