Skip to content

Commit 2aeb782

Browse files
committed
Added dynamic configuration for search results fields
1 parent ad7bf6b commit 2aeb782

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
Shell into any server in your aws account.
44

5-
#Search
5+
Search
6+
====
67
calling the search command will look up all ec2 instances then filter the results by the term entered. if only a single result the app will ssh directly. If multiple results returned the app will display a numbered list and prompt for which to connect.
78

9+
810
```
911
aws-ssh search {{search term}}
1012
```
1113

12-
#Connect
14+
Connect
15+
=====
1316
connect allows you to connect directly to a known server. (team member running windows asked for this.)
1417

15-
#Configuration
18+
Configuration
19+
======
1620

1721
you will need to specify aws credentials. see [AWS Credentials](http://blogs.aws.amazon.com/security/post/Tx3D6U6WSFGOK2H/A-New-and-Standardized-Way-to-Manage-Credentials-in-the-AWS-SDKs) for details.
1822

@@ -24,5 +28,18 @@ aws_access_key_id = ACCESS_KEY
2428
aws_secret_access_key = SECRET_KEY
2529
```
2630

31+
#### Config File
32+
by setting a `~/.aws-ssh.yml` file you can set additional fields to the search
33+
results.
34+
35+
example `.aws-ssh.yml` file:
36+
```markdown
37+
tags:
38+
- env
39+
- name
40+
- role
41+
```
42+
43+
2744
##PEM keys
2845
if setting a key add the name only expected to be at ~/.ssh/{{KEY_NAME}}.pem

cmd/versionCmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13-
const Version = "0.0.10"
13+
const Version = "0.0.11"
1414

1515
// versionCmd represents the version command
1616
var versionCmd = &cobra.Command{

modules/instanceCollection.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/aws/aws-sdk-go/aws/session"
1111
"github.com/aws/aws-sdk-go/service/ec2"
1212
"github.com/olekukonko/tablewriter"
13+
"github.com/spf13/viper"
1314
)
1415

1516
//Instances Instance Collection type
@@ -106,17 +107,24 @@ func (instances Instances) FilterByName(name string) Instances {
106107
//CreateTable creates a formated table of instances
107108
func (instances Instances) CreateTable(writer io.Writer) {
108109
table := tablewriter.NewWriter(writer)
109-
table.SetHeader([]string{"Num", "Id", "State", "Public", "Private", "env", "role"})
110+
tags := viper.GetStringSlice("tags")
111+
fmt.Println(tags)
112+
headers := []string{"Num", "Id", "State", "Public", "Private"}
113+
headers = append(headers, tags...)
114+
table.SetHeader(headers)
110115

111116
for pos, inst := range instances {
112-
table.Append([]string{strconv.Itoa(pos),
117+
row := []string{strconv.Itoa(pos),
113118
inst.Id,
114119
inst.State,
115120
inst.Host,
116121
inst.PrivateIp,
117-
inst.GetKey("env"),
118-
inst.GetKey("role"),
119-
})
122+
}
123+
for _, tag := range tags {
124+
row = append(row, inst.GetKey(tag))
125+
}
126+
// row = append(row, tags...)
127+
table.Append(row)
120128
// fmt.Println(pos, " ", inst.Name, " ", inst.State, " ", inst.Host)
121129
}
122130
table.Render()

0 commit comments

Comments
 (0)