Skip to content

Commit

Permalink
Added public ip support
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciferInLove committed Sep 26, 2021
1 parent 22c445b commit ec49be4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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

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.*.*
Expand All @@ -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

Expand Down
11 changes: 9 additions & 2 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type instance struct {
}

var (
version = "v0.0.4"
version = "v0.0.5"
appAuthor *cli.Author = &cli.Author{
Name: "LuciferInLove",
Email: "[email protected]",
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit ec49be4

Please sign in to comment.