├── .gitignore ├── README.md ├── gif └── pic.gif ├── go.mod ├── go.sum ├── main.go ├── pkg ├── aws │ └── ec2.go ├── cmd │ ├── cmd.go │ └── root.go └── config │ └── envparser.go └── test └── aws_sdk_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | setting.code-workspace 2 | .idea 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SSH Auto Connector for EC2 Instance 2 | 3 | Simple commands which connects to AWS EC2 Instances! 4 | 5 | You don't need to check your changed EC2 instance IP anymore. Just use **'ec2-connect'** 6 | 7 |

8 | 9 | [ec2-ssh-autoconnect](https://github.com/alicek106/ec2-ssh-autoconnect) 의 속도를 개선한 Go 구현 버전입니다. 10 | 11 | # 1. Features 12 | 13 | Features that this script provide is.. 14 | 15 | - Start and stop a EC2 instance 16 | - Start and stop multiple EC2 instances as a group 17 | - **Connect SSH to a EC2 instance automatically** 18 | - List all EC2 instances 19 | 20 | # 2. Install 21 | 22 | ## 2.1 Install binary 23 | 24 | Download release binary. Currently, MacOS is only supported. 25 | 26 | ``` 27 | $ wget https://github.com/alicek106/go-ec2-ssh-autoconnect/releases/download/v0.7/ec2-connect-darwin && \ 28 | chmod +x ec2-connect-darwin && \ 29 | mv ec2-connect-darwin /usr/local/bin/ec2-connect 30 | ``` 31 | 32 | ## 2.2 Create configuration file 33 | 34 | Create configuration file as **/etc/ec2_connect_config.yaml** like below. 35 | 36 | ```yaml 37 | version: v1 38 | spec: 39 | region: "ap-northeast-2" 40 | 41 | # .spec.credentials is Optional. Instead you can define keys in ~/.aws/credentials 42 | credentials: 43 | accessKey: "... :D" 44 | secretKey: "... :D" 45 | 46 | privateKeys: 47 | - name: "default" # You should define default key 48 | path: "/Users/alicek106/dev/keys/DockerEngineTestInstance.pem" 49 | - name: "customKey1" # Optional. you can use this key as alternative 50 | path: "/Users/alicek106/dev/keys/VaultAdminKey.pem" 51 | 52 | instanceGroups: 53 | - name: "kubeadm_part" 54 | instances: ["kubeadm_master", "kubeadm_worker0"] 55 | - name: "kubeadm" 56 | instances: ["kubeadm_master", "kubeadm_worker0", "kubeadm_worker1", "kubeadm_worker2"] 57 | - name: "consul" 58 | instances: ["consul-1", "consul-2", "consul-3"] 59 | - name: "vault" 60 | instances: ["vault-1-active", "vault-2-standby"] 61 | ``` 62 | 63 | Configuration file consists of four part. 64 | 65 | - **region** : AWS region to use. Instances of only selected region are shown and managed in ec2-connect. 66 | - **spec.credentails.accessKey and secretKey** : Optional. AWS credentials to use. You can define in ~/.aws/credential as a static credential. Or you can also use assume role from ~/.aws/config (by source_profile and role_arn) to ~/.aws/credentials by shared config. 67 | - **spec.privateKeys** : Default SSH private key when using **ec2-connect connect** for a EC2 instance. By default, privateKey named "default" will be used, but you can define another SSH private key to connect SSH. It is used by **--key** parameter in command 68 | - **spec.instanceGroups** : It defines group for starting and stoping multiple EC2 instances. Above example defined 'kubeadm_part' group, so if you use command **ec2-connect group start kubeadm_part**, it will start two instances (kubeadm-worker, kubeadm-worker0). 69 | 70 | 71 | ## 2.3 Setting AWS credential 72 | 73 | AWS credentials priority is like below. 74 | 75 | 1. Define credentials in bash environment values: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY (High Priority) 76 | 2. Define credentials in /etc/ec2_connect_config.yaml (Medium Priority) 77 | 3. Define credentials in ~/.aws/credentials (Low Priority) 78 | 79 | FYI, I'm using third way (~/.aws/credentials) :D 80 | 81 | # 3. How to use (Easy!) 82 | 83 | 1. Check EC2 instance list using **ec2-connect list** 84 | 85 | ``` 86 | $ ec2-connect list 87 | 2019/08/11 22:26:08 Cannot found credential in environment variable. 88 | 2019/08/11 22:26:08 Found credential in configuration file. 89 | 2019/08/11 22:26:09 Succeed to validate AWS credential. 90 | Instance ID Instance Name IP Address Status 91 | i-04f9e3da95a25e939 kubeadm-master Unknown stopped 92 | i-0c35c716a6442a72e kubeadm-worker0 Unknown stopped 93 | i-0ef65f12957a67559 kubeadm-worker2 Unknown stopped 94 | i-0c4bb55ba07c9edbf kubeadm-worker1 Unknown stopped 95 | i-0994dac6654fd59e1 Test 13.209.67.72 running 96 | ``` 97 | 98 | 2. Start EC2 instance using **ec2-connect start** 99 | ``` 100 | $ ec2-connect start Test 101 | 2019/08/11 22:26:22 Cannot found credential in environment variable. 102 | 2019/08/11 22:26:22 Found credential in configuration file. 103 | 2019/08/11 22:26:22 Succeed to validate AWS credential. 104 | 2019/08/11 22:26:23 Starting EC2 instance : Test (instance ID: i-0994dac6654fd59e1) 105 | 2019/08/11 22:26:23 Succeed to start EC2 instances. 106 | ``` 107 | 3. Connect to EC2 instance by **ec2-connect connect [EC2 instance name]**. This command uses private key defined in /etc/ec2_connect_config.yaml (spec.privateKeys) 108 | 109 | ``` 110 | $ ec2-connect connect Test 111 | 2019/08/11 22:26:54 Cannot found credential in environment variable. 112 | 2019/08/11 22:26:54 Found credential in configuration file. 113 | 2019/08/11 22:26:54 Succeed to validate AWS credential. 114 | 2019/08/11 22:26:55 Instance in active. 115 | Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-1088-aws x86_64) 116 | 117 | ... 118 | 119 | New release '18.04.2 LTS' available. 120 | Run 'do-release-upgrade' to upgrade to it. 121 | 122 | 123 | Last login: Sun Aug 11 13:15:12 2019 from 1.222.77.99 124 | ubuntu@testbed:~$ 125 | ``` 126 | 127 | > **Tip** : If a instance is in STOP state, 'connect' command automatically start the instance and connect SSH. So you don't need to command 'start' actually. Just use **connect**! 128 | 129 | Or, you can use user-defined key in ec2_connect_config.yaml by specifying --key. By default, this script uses "default" key in config file. 130 | 131 | ``` 132 | $ ec2-connect connect Test --key=MY_CUSTOM_KEY_PATH 133 | ``` 134 | 135 | 136 | 4. Stop EC2 instance by **ec2-connect stop [EC2 instance name]** 137 | 138 | ``` 139 | $ ec2-connect stop Test 140 | 2019/08/11 22:28:12 Cannot found credential in environment variable. 141 | 2019/08/11 22:28:12 Found credential in configuration file. 142 | 2019/08/11 22:28:12 Succeed to validate AWS credential. 143 | 2019/08/11 22:28:12 Stoping EC2 instance : Test (instance ID: i-0994dac6654fd59e1) 144 | 2019/08/11 22:28:13 Succeed to stop EC2 instances. 145 | ``` 146 | 147 | 5. If you defined **custom group** in /etc/ec2_connect_config.yaml, you can use 'group start' or 'group stop' 148 | 149 | ``` 150 | $ ec2-connect group start kubeadm_part 151 | 2019/08/11 22:29:07 Cannot found credential in environment variable. 152 | 2019/08/11 22:29:07 Found credential in configuration file. 153 | 2019/08/11 22:29:08 Succeed to validate AWS credential. 154 | 2019/08/11 22:29:08 Starting EC2 instance : kubeadm-master (instance ID: i-04f9e3d...) 155 | 2019/08/11 22:29:08 Starting EC2 instance : kubeadm-worker0 (instance ID: i-0c35c71...) 156 | 2019/08/11 22:29:08 Succeed to start EC2 instances. 157 | ... 158 | ``` 159 | 160 | -------------------------------------------------------------------------------- /gif/pic.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alicek106/go-ec2-ssh-autoconnect/257200e7e1ea7ab97241444e817113f9e86e905b/gif/pic.gif -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/alicek106/go-ec2-ssh-autoconnect 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/aws/aws-sdk-go v1.38.36 7 | github.com/spf13/cobra v1.1.3 // indirect 8 | github.com/stretchr/testify v1.3.0 // indirect 9 | gopkg.in/ini.v1 v1.51.0 10 | gopkg.in/yaml.v2 v2.4.0 11 | ) 12 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 6 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 7 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 8 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 9 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 10 | cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= 11 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 12 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 13 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 14 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 15 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 16 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 17 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 18 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 19 | github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= 20 | github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= 21 | github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= 22 | github.com/aws/aws-sdk-go v1.15.77 h1:qlut2MDI5mRKllPC6grO5n9M8UhPQg1TIA9cYAkC/gc= 23 | github.com/aws/aws-sdk-go v1.15.77/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM= 24 | github.com/aws/aws-sdk-go v1.20.16 h1:Dq68fBH39XnSjjb2hX/iW6mui8JtXcVAuhRYGSRiisY= 25 | github.com/aws/aws-sdk-go v1.20.16/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= 26 | github.com/aws/aws-sdk-go v1.38.36 h1:MiqzQY/IOFTX/jmGse7ThafD0eyOC4TrCLv2KY1v+bI= 27 | github.com/aws/aws-sdk-go v1.38.36/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= 28 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 29 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 30 | github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= 31 | github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= 32 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 33 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 34 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 35 | github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 36 | github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 37 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 38 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 39 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 40 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 41 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 42 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 43 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 44 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 45 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 46 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 47 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 48 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 49 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 50 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 51 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 52 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 53 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 54 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 55 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 56 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 57 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 58 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 59 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 60 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 61 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 62 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 63 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 64 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 65 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 66 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 67 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 68 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 69 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 70 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 71 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 72 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 73 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 74 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 75 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 76 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 77 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 78 | github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= 79 | github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= 80 | github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= 81 | github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 82 | github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= 83 | github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= 84 | github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 85 | github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= 86 | github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= 87 | github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= 88 | github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 89 | github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 90 | github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= 91 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 92 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 93 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 94 | github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= 95 | github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= 96 | github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= 97 | github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= 98 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= 99 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 100 | github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= 101 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= 102 | github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= 103 | github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= 104 | github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= 105 | github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= 106 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 107 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 108 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 109 | github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= 110 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 111 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 112 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 113 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 114 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 115 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 116 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 117 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 118 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 119 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 120 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 121 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 122 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 123 | github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= 124 | github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= 125 | github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 126 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 127 | github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 128 | github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= 129 | github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= 130 | github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 131 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 132 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 133 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 134 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 135 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 136 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= 137 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 138 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 139 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 140 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 141 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 142 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 143 | github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= 144 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 145 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 146 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 147 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 148 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 149 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 150 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 151 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 152 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 153 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 154 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 155 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 156 | github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= 157 | github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= 158 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 159 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 160 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= 161 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= 162 | github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 h1:N8Bg45zpk/UcpNGnfJt2y/3lRWASHNTUET8owPYCgYI= 163 | github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 164 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 165 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 166 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 167 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 168 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 169 | github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= 170 | github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= 171 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 172 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 173 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 174 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 175 | github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= 176 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 177 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 178 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 179 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 180 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 181 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= 182 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 183 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 184 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 185 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 186 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 187 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 188 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 189 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 190 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 191 | golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 192 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 193 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 194 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 195 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 196 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 197 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 198 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 199 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 200 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 201 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 202 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 203 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 204 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 205 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 206 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 207 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 208 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 209 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 210 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 211 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 212 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 213 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 214 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 215 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 216 | golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 217 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 218 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 219 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 220 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 221 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 222 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 223 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 224 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 225 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 226 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 227 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 228 | golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 229 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 230 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 231 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 232 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 233 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 234 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 235 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 236 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 237 | golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 238 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 239 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 240 | golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 241 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 242 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 243 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 244 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 245 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 246 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 247 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 248 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 249 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 250 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 251 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 252 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 253 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 254 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 255 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 256 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 257 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 258 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 259 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 260 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 261 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 262 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 263 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 264 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 265 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 266 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 267 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 268 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 269 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 270 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 271 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 272 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 273 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 274 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 275 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 276 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 277 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 278 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 279 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 280 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 281 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 282 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 283 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 284 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 285 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 286 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 287 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 288 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 289 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 290 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 291 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 292 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 293 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 294 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 295 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 296 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 297 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 298 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 299 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 300 | gopkg.in/ini.v1 v1.44.0 h1:YRJzTUp0kSYWUVFF5XAbDFfyiqwsl0Vb9R8TVP5eRi0= 301 | gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 302 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 303 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 304 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 305 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 306 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 307 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 308 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 309 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 310 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 311 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 312 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 313 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 314 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 315 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 316 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/alicek106/go-ec2-ssh-autoconnect/pkg/cmd" 5 | "log" 6 | ) 7 | 8 | func main() { 9 | err := cmd.NewCommand().Execute() 10 | if err != nil { 11 | log.Fatalf("Error: %s", err) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pkg/aws/ec2.go: -------------------------------------------------------------------------------- 1 | package aws 2 | 3 | import ( 4 | "fmt" 5 | "github.com/alicek106/go-ec2-ssh-autoconnect/pkg/config" 6 | "github.com/aws/aws-sdk-go/service/ec2" 7 | "log" 8 | "os" 9 | "sort" 10 | "strings" 11 | "text/tabwriter" 12 | "time" 13 | 14 | "github.com/aws/aws-sdk-go/aws" 15 | "github.com/aws/aws-sdk-go/aws/awserr" 16 | "github.com/aws/aws-sdk-go/aws/credentials" 17 | "github.com/aws/aws-sdk-go/aws/session" 18 | ) 19 | 20 | var svc *AwsEc2Manager 21 | 22 | func GetEC2Service() *AwsEc2Manager { 23 | if svc == nil { 24 | svc = &AwsEc2Manager{Ec2StartWaitTimeout: 30} 25 | svc.CheckCredentials() 26 | } 27 | return svc 28 | } 29 | 30 | // Ec2InstanceInfo : Data struct for storing EC2 instance data 31 | type Ec2InstanceInfo struct { 32 | instancdID string 33 | instanceName string 34 | status string 35 | publicIP string 36 | } 37 | 38 | // AwsEc2Manager : AWS EC2 Session and client amanger 39 | type AwsEc2Manager struct { 40 | session *session.Session 41 | client *ec2.EC2 42 | Ec2StartWaitTimeout int 43 | } 44 | 45 | // CheckCredentials : Check existing credential from shell or configuartion 46 | func (aem *AwsEc2Manager) CheckCredentials() { 47 | // 1. Check fron env 48 | accessID := os.Getenv("AWS_ACCESS_KEY_ID") 49 | secretKey := os.Getenv("AWS_SECRET_ACCESS_KEY") 50 | var err error 51 | if len(accessID) == 1 && len(secretKey) == 1 { 52 | log.Println("Loading credentials from environment values..") 53 | aem.loadCredentialFromSecret(accessID, secretKey) 54 | // Load session from env key 55 | } 56 | 57 | // 2. Check from configuration file 58 | ep := config.GetEnvparser() 59 | accessID, secretKey, err = ep.GetCredentials() 60 | if err == nil { 61 | log.Println("Loading credentials from configuration file..") 62 | aem.loadCredentialFromSecret(accessID, secretKey) 63 | } 64 | 65 | // 3. Check from AWS Profile (AWS_PROFILE) 66 | // It covers (1) assume role profile (AWS_PROFILE refer to ~/.aws/config when using role_arn and shared config) 67 | // (2) and AWS_PROFILE with static credentials only defined in ~/.aws/credentials 68 | err = aem.loadCredentialFromProfile() 69 | if err != nil { 70 | log.Fatalf("Error to load : %s", err) 71 | os.Exit(100) 72 | } 73 | } 74 | 75 | func (aem *AwsEc2Manager) loadCredentialFromProfile() (err error) { 76 | aem.session = session.Must(session.NewSessionWithOptions(session.Options{ 77 | Config: aws.Config{ 78 | Region: aws.String(config.GetEnvparser().GetRegion()), 79 | }, 80 | SharedConfigState: session.SharedConfigEnable, 81 | })) 82 | aem.client = ec2.New(aem.session) 83 | _, err = aem.client.DescribeInstances(nil) 84 | if err != nil { 85 | log.Fatal(err) 86 | } else { 87 | log.Printf("Succeed to validate AWS credential.") 88 | } 89 | return err 90 | } 91 | 92 | func (aem *AwsEc2Manager) loadCredentialFromSecret(accessID string, secretKey string) { 93 | // Load session 94 | aem.session = session.Must(session.NewSession(&aws.Config{ 95 | Region: aws.String(config.GetEnvparser().GetRegion()), 96 | Credentials: credentials.NewStaticCredentials(accessID, secretKey, ""), 97 | })) 98 | 99 | // Test AWS function using provided credential 100 | aem.client = ec2.New(aem.session) 101 | _, err := aem.client.DescribeInstances(nil) 102 | if err != nil { 103 | log.Fatal(err) 104 | } else { 105 | log.Printf("Succeed to validate AWS credential.") 106 | } 107 | } 108 | 109 | // GetInstanceIDs : Return instance IDs from instanceNames 110 | func (aem *AwsEc2Manager) GetInstanceIDs(instanceNames []string) []*string { 111 | var instanceIDs = []*string{} 112 | for _, instanceName := range instanceNames { 113 | // If filters is defined directly in input parameter, it triggers syntax error. 114 | filter := aem.getFilterForName(instanceName) 115 | result, err := aem.client.DescribeInstances(filter) 116 | if err != nil { 117 | fmt.Println(err) 118 | } else { 119 | if len(result.Reservations) == 0 { 120 | log.Fatalf("Cannot find instance name [%s]. Abort", instanceName) 121 | } 122 | instanceIDs = append(instanceIDs, result.Reservations[0].Instances[0].InstanceId) 123 | } 124 | } 125 | return instanceIDs 126 | } 127 | 128 | // ListInstances : List multiple instances. 129 | func (aem *AwsEc2Manager) ListInstances() { 130 | result, err := aem.client.DescribeInstances(nil) 131 | if err != nil { 132 | log.Fatal(err) 133 | } else { 134 | // var ec2NameMaxLength int 135 | var ec2InstanceList = []Ec2InstanceInfo{} 136 | for _, reservation := range result.Reservations { 137 | for _, instance := range reservation.Instances { 138 | var ec2InstanceInfo = Ec2InstanceInfo{ 139 | status: *instance.State.Name, 140 | instancdID: *instance.InstanceId, 141 | } 142 | 143 | if instance.PublicIpAddress == nil { 144 | ec2InstanceInfo.publicIP = "Unknown" 145 | } else { 146 | ec2InstanceInfo.publicIP = *instance.PublicIpAddress 147 | } 148 | 149 | for _, tag := range instance.Tags { 150 | if *tag.Key == "Name" { 151 | ec2InstanceInfo.instanceName = *tag.Value 152 | } 153 | } 154 | ec2InstanceList = append(ec2InstanceList, ec2InstanceInfo) 155 | } 156 | } 157 | 158 | sort.Slice(ec2InstanceList, func(i, j int) bool { 159 | return ec2InstanceList[i].instanceName < ec2InstanceList[j].instanceName 160 | }) 161 | 162 | writer := tabwriter.NewWriter(os.Stdout, 16, 8, 2, '\t', 0) 163 | fmt.Fprintln(writer, "Instance ID\tInstance Name\tIP Address\tStatus") 164 | for _, ec2InstanceInfo := range ec2InstanceList { 165 | formatting := fmt.Sprintf("%s\t%s\t%s\t%s", ec2InstanceInfo.instancdID, 166 | ec2InstanceInfo.instanceName, ec2InstanceInfo.publicIP, ec2InstanceInfo.status) 167 | fmt.Fprintln(writer, formatting) 168 | } 169 | 170 | writer.Flush() 171 | } 172 | } 173 | 174 | // StartInstances : Start multiple instances. 175 | func (aem *AwsEc2Manager) StartInstances(instanceIDs []*string) { 176 | input := &ec2.StartInstancesInput{ 177 | InstanceIds: instanceIDs, // It should be used with pointer 178 | DryRun: aws.Bool(true), 179 | } 180 | _, err := aem.client.StartInstances(input) 181 | awsErr, ok := err.(awserr.Error) 182 | 183 | if ok && awsErr.Code() == "DryRunOperation" { 184 | input.DryRun = aws.Bool(false) 185 | _, err := aem.client.StartInstances(input) 186 | if err != nil { 187 | log.Fatal("Error", err) 188 | } else { 189 | log.Printf("Succeed to start EC2 instances.") 190 | } 191 | } else { // This could be due to a lack of permissions 192 | log.Fatal("Error", err) 193 | } 194 | } 195 | 196 | // WaitUntilActive : Wait unil all instances are up and running. 197 | // Order of instanceIDs and instanceNames is same. (Refer to GetInstanceIDs) 198 | func (aem *AwsEc2Manager) WaitUntilActive(instanceIDs []*string, instanceNames []string) { 199 | for index := range instanceIDs { 200 | log.Printf("Start to waiting EC2 instance %s (instance ID : %s)...", instanceNames[index], *instanceIDs[index]) 201 | for tries := 1; tries <= aem.Ec2StartWaitTimeout; tries++ { 202 | // If EC2 instance is not running state 203 | if aem.GetInstanceStatus(instanceIDs[index:index+1]) != "running" { 204 | // If EC2 instance is not running state after 30s, continue to next instance. 205 | if tries == 30 { 206 | log.Printf("Failed to wait for EC2 instance to be active.") 207 | break 208 | } else { 209 | // Wait seconds (aem.Ec2StartWaitTimeout) 210 | log.Printf("Waiting for starting EC2 instance.. %d tries.", tries) 211 | time.Sleep(time.Second) 212 | } 213 | } else { 214 | // EC2 instance is already running, pass to wait 30 seconds for warm-up 215 | if tries == 1 { 216 | log.Printf("EC2 instance is in active.") 217 | break 218 | } 219 | // Wait 30 seconds until SSH daemon is ready 220 | log.Printf("EC2 instance is in active. Waiting for 30 seconds for warm-up.") 221 | time.Sleep(30 * time.Second) 222 | break 223 | } 224 | } 225 | } 226 | } 227 | 228 | // GetInstancePublicIP : Return EC2 instance public IP from instance name 229 | func (aem *AwsEc2Manager) GetInstancePublicIP(instanceName string) (publicIP string) { 230 | filter := aem.getFilterForName(instanceName) 231 | result, err := aem.client.DescribeInstances(filter) 232 | if err != nil { 233 | fmt.Println(err) 234 | } 235 | return *result.Reservations[0].Instances[0].PublicIpAddress 236 | } 237 | 238 | // StopInstances : Stop multiple instances. 239 | func (aem *AwsEc2Manager) StopInstances(instanceIDs []*string) { 240 | input := &ec2.StopInstancesInput{ 241 | InstanceIds: instanceIDs, // It should be used with pointer 242 | DryRun: aws.Bool(true), 243 | } 244 | _, err := aem.client.StopInstances(input) 245 | awsErr, ok := err.(awserr.Error) 246 | 247 | if ok && awsErr.Code() == "DryRunOperation" { 248 | input.DryRun = aws.Bool(false) 249 | _, err := aem.client.StopInstances(input) 250 | if err != nil { 251 | log.Fatal("Error", err) 252 | } else { 253 | log.Printf("Succeed to stop EC2 instances.") 254 | } 255 | } else { // This could be due to a lack of permissions 256 | log.Fatal("Error", err) 257 | } 258 | } 259 | 260 | // GetUsernamePerOS : Return proper SSH username per EC2 instsance OS image 261 | func (aem *AwsEc2Manager) GetUsernamePerOS(instanceName string) (sshUsername string) { 262 | filter := aem.getFilterForName(instanceName) 263 | result, err := aem.client.DescribeInstances(filter) 264 | if err != nil { 265 | fmt.Println(err) 266 | } 267 | 268 | amiImageID := *result.Reservations[0].Instances[0].ImageId 269 | image, err := aem.client.DescribeImages(&ec2.DescribeImagesInput{ 270 | ImageIds: []*string{ 271 | aws.String(amiImageID), 272 | }, 273 | }) 274 | if err != nil { 275 | fmt.Println(err) 276 | } 277 | 278 | imageName := *image.Images[0].Name 279 | if strings.Contains(imageName, "ubuntu") { 280 | log.Printf("Found AMI name : %s, trying to ssh using ubuntu", imageName) 281 | return "ubuntu" 282 | } else if strings.Contains(imageName, "amazon") || strings.Contains(imageName, "redhat") { 283 | log.Printf("Found AMI name : %s, trying to ssh using ec2-user", imageName) 284 | return "ec2-user" 285 | } 286 | 287 | log.Fatalf("Not found appropriate user name for ami : %s", imageName) 288 | return "" 289 | } 290 | 291 | func (aem *AwsEc2Manager) GetInstanceStatus(instanceID []*string) (status string) { 292 | input := &ec2.DescribeInstancesInput{ 293 | InstanceIds: instanceID, 294 | } 295 | result, err := aem.client.DescribeInstances(input) 296 | if err != nil { 297 | log.Println("Error in waiting for EC2 instances to be active") 298 | log.Fatal(err) 299 | } else { 300 | status = *result.Reservations[0].Instances[0].State.Name 301 | } 302 | return status 303 | } 304 | 305 | // getFilterForName : Return filter for describing instances 306 | func (aem *AwsEc2Manager) getFilterForName(instanceName string) (input *ec2.DescribeInstancesInput) { 307 | filters := []*ec2.Filter{ 308 | &ec2.Filter{ 309 | Name: aws.String("tag:Name"), 310 | Values: []*string{aws.String(instanceName)}, 311 | }, 312 | } 313 | input = &ec2.DescribeInstancesInput{ 314 | Filters: filters, 315 | } 316 | return input 317 | } 318 | -------------------------------------------------------------------------------- /pkg/cmd/cmd.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "github.com/alicek106/go-ec2-ssh-autoconnect/pkg/aws" 7 | "github.com/alicek106/go-ec2-ssh-autoconnect/pkg/config" 8 | "github.com/spf13/cobra" 9 | "log" 10 | "os" 11 | "os/exec" 12 | ) 13 | 14 | var ( 15 | key string 16 | version = "v0.7" // TODO : version should be injected in build time 17 | buildDate = "1970-01-01T00:00:00Z" 18 | gitCommit = "" 19 | ) 20 | 21 | func NewListCommand() *cobra.Command { 22 | versionCmd := cobra.Command{ 23 | Use: "list", 24 | Short: "List EC2 instances", 25 | Example: ` # List all EC2 instances. 26 | ec2-connect list`, 27 | Run: func(cmd *cobra.Command, args []string) { 28 | svc := aws.GetEC2Service() 29 | svc.ListInstances() 30 | }, 31 | } 32 | return &versionCmd 33 | } 34 | 35 | func NewStartCommand() *cobra.Command { 36 | startCmd := cobra.Command{ 37 | Use: "start", 38 | Args: func(cmd *cobra.Command, args []string) error { 39 | if len(args) < 1 { 40 | return errors.New("Require a instance name.") 41 | } 42 | return nil 43 | }, 44 | Short: "Start EC2 instances", 45 | Example: ` # Start a EC2 instances. 46 | ec2-connect start myserver`, 47 | Run: func(cmd *cobra.Command, args []string) { 48 | svc := aws.GetEC2Service() 49 | instanceName := args[0] 50 | instanceIDs := svc.GetInstanceIDs([]string{instanceName}) 51 | for index, instanceName := range []string{instanceName} { 52 | log.Printf("Starting EC2 instance : %s (instance ID: %s)", instanceName, *instanceIDs[index]) 53 | } 54 | svc.StartInstances(instanceIDs) 55 | }, 56 | } 57 | return &startCmd 58 | } 59 | 60 | func NewStopCommand() *cobra.Command { 61 | stopCmd := cobra.Command{ 62 | Use: "stop", 63 | Args: func(cmd *cobra.Command, args []string) error { 64 | if len(args) < 1 { 65 | return errors.New("Require a instance name.") 66 | } 67 | return nil 68 | }, 69 | Short: "Stop EC2 instances", 70 | Example: ` # Stop a EC2 instances. 71 | ec2-connect stop myserver`, 72 | Run: func(cmd *cobra.Command, args []string) { 73 | svc := aws.GetEC2Service() 74 | instanceIDs := svc.GetInstanceIDs([]string{args[0]}) 75 | for index, instanceName := range []string{args[0]} { 76 | log.Printf("Stoping EC2 instance : %s (instance ID: %s)", instanceName, *instanceIDs[index]) 77 | } 78 | svc.StopInstances(instanceIDs) 79 | }, 80 | } 81 | return &stopCmd 82 | } 83 | 84 | func NewGroupCommand() *cobra.Command { 85 | groupCmd := cobra.Command{ 86 | Use: "group", 87 | Short: "Manage EC2 instance as a group", 88 | Example: ` # Start a group of instances 89 | ec2-connect group start mygroup 90 | 91 | # Stop EC2 instance as a group 92 | ec2-connect group stop mygroup`, 93 | Run: func(cmd *cobra.Command, args []string) { 94 | cmd.HelpFunc()(cmd, args) 95 | os.Exit(1) 96 | }, 97 | } 98 | 99 | groupCmd.AddCommand(newGroupStartCommand()) 100 | groupCmd.AddCommand(newGroupStopCommand()) 101 | return &groupCmd 102 | } 103 | 104 | func newGroupStartCommand() *cobra.Command { 105 | groupStartCmd := cobra.Command{ 106 | Use: "start", 107 | Args: func(cmd *cobra.Command, args []string) error { 108 | if len(args) < 1 { 109 | return errors.New("Require a group name.") 110 | } 111 | return nil 112 | }, 113 | Short: "Start EC2 instance as a group", 114 | Example: ` # Start a group of instances 115 | ec2-connect group start mygroup`, 116 | Run: func(cmd *cobra.Command, args []string) { 117 | svc := aws.GetEC2Service() 118 | instanceNames := config.GetEnvparser().GetGroupInstanceNames(args[0]) 119 | instanceIDs := svc.GetInstanceIDs(instanceNames) 120 | for index, instanceName := range instanceNames { 121 | log.Printf("Starting EC2 instance : %s (instance ID: %s)", instanceName, *instanceIDs[index]) 122 | } 123 | svc.StartInstances(instanceIDs) 124 | }, 125 | } 126 | return &groupStartCmd 127 | } 128 | 129 | func newGroupStopCommand() *cobra.Command { 130 | groupStopCmd := cobra.Command{ 131 | Use: "stop", 132 | Args: func(cmd *cobra.Command, args []string) error { 133 | if len(args) < 1 { 134 | return errors.New("Require a group name.") 135 | } 136 | return nil 137 | }, 138 | Short: "Stop EC2 instance as a group", 139 | Example: ` # Stop a group of instances 140 | ec2-connect group stop mygroup`, 141 | Run: func(cmd *cobra.Command, args []string) { 142 | svc := aws.GetEC2Service() 143 | instanceNames := config.GetEnvparser().GetGroupInstanceNames(args[0]) 144 | instanceIDs := svc.GetInstanceIDs(instanceNames) 145 | for index, instanceName := range instanceNames { 146 | log.Printf("Stoping EC2 instance : %s (instance ID: %s)", instanceName, *instanceIDs[index]) 147 | } 148 | svc.StopInstances(instanceIDs) 149 | }, 150 | } 151 | return &groupStopCmd 152 | } 153 | 154 | func NewConnectCommand() *cobra.Command { 155 | connectCmd := cobra.Command{ 156 | Use: "connect", 157 | Args: func(cmd *cobra.Command, args []string) error { 158 | if len(args) < 1 { 159 | return errors.New("Require a instance name.") 160 | } 161 | return nil 162 | }, 163 | Short: "Connect to a EC2 instance using SSH", 164 | Example: ` # Connect to a EC2 instance 165 | ec2-connect connect myserver 166 | 167 | # Connect to a EC2 instance using user-defined key in configuration file. 168 | ec2-connect connect myserver --key=mykey`, 169 | Run: func(cmd *cobra.Command, args []string) { 170 | svc := aws.GetEC2Service() 171 | 172 | if cmd.Flags().Changed("key") { 173 | keyName, err := cmd.Flags().GetString("key") 174 | key = config.GetEnvparser().GetCustomKey(keyName) 175 | if err != nil { 176 | log.Fatalf("Something wrong to get key flag: %s", err) 177 | } 178 | } 179 | instanceName := args[0] 180 | instanceID := svc.GetInstanceIDs([]string{instanceName}) 181 | if svc.GetInstanceStatus(instanceID) == "running" { 182 | log.Println("Instance in active.") 183 | } else { 184 | svc.StartInstances(instanceID) 185 | svc.WaitUntilActive(instanceID, []string{instanceName}) 186 | } 187 | 188 | instanceIP := svc.GetInstancePublicIP(instanceName) 189 | sshUserName := svc.GetUsernamePerOS(instanceName) 190 | execCmd := exec.Command("ssh", "-oStrictHostKeyChecking=no", fmt.Sprintf("%s@%s", sshUserName, instanceIP), fmt.Sprintf("-i%s", key)) 191 | execCmd.Stdin = os.Stdin 192 | execCmd.Stdout = os.Stdout 193 | execCmd.Stderr = os.Stderr 194 | err := execCmd.Run() 195 | if err != nil { 196 | log.Fatalf("Error: %s", err) 197 | } 198 | }, 199 | } 200 | 201 | defaultKey := config.GetEnvparser().GetDefaultKey() 202 | connectCmd.Flags().StringVar(&key, "key", defaultKey, "SSH key to connect EC2 instance") 203 | return &connectCmd 204 | } 205 | 206 | func NewVersionCommand() *cobra.Command { 207 | versionCmd := cobra.Command{ 208 | Use: "version", 209 | Short: "Print version information", 210 | Example: ` # Print version of binary. 211 | ec2-connect version 212 | `, 213 | Run: func(cmd *cobra.Command, args []string) { 214 | fmt.Printf(" Version: %s\n", version) 215 | fmt.Printf(" Build Date: %s\n", buildDate) 216 | fmt.Printf(" Git Commit: %s\n", gitCommit) 217 | }, 218 | } 219 | return &versionCmd 220 | } 221 | -------------------------------------------------------------------------------- /pkg/cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | const ( 8 | cliName = "ec2-connect" 9 | ) 10 | 11 | func NewCommand() *cobra.Command { 12 | var command = &cobra.Command{ 13 | Use: cliName, 14 | Short: "Connect, start, stop, list EC2 instances!", 15 | Run: func(c *cobra.Command, args []string) { 16 | c.HelpFunc()(c, args) 17 | }, 18 | DisableAutoGenTag: true, 19 | } 20 | 21 | command.AddCommand(NewVersionCommand()) 22 | command.AddCommand(NewListCommand()) 23 | command.AddCommand(NewStartCommand()) 24 | command.AddCommand(NewStopCommand()) 25 | command.AddCommand(NewGroupCommand()) 26 | command.AddCommand(NewConnectCommand()) 27 | return command 28 | } 29 | -------------------------------------------------------------------------------- /pkg/config/envparser.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "gopkg.in/yaml.v2" 7 | "io/ioutil" 8 | "log" 9 | ) 10 | 11 | // TODO : Replace this package to viper 12 | type YamlParserV1 struct { 13 | Version string `yaml:"version"` 14 | Spec struct { 15 | Region string `yaml:"region"` 16 | Credentials struct { 17 | AccessKey string `yaml:"accessKey"` 18 | SecretKey string `yaml:"secretKey"` 19 | } `yaml:"credentials"` 20 | 21 | PrivateKeys []struct { 22 | Name string `yaml:"name"` 23 | Path string `yaml:"path"` 24 | } `yaml:"privateKeys"` 25 | 26 | InstanceGroups []struct { 27 | GroupName string `yaml:"name"` 28 | InstanceName []string `yaml:"instances"` 29 | } `yaml:"instanceGroups"` 30 | } 31 | } 32 | 33 | // Envparser : It parses configuration file in /etc/ec2_connect_config.yaml 34 | type Envparser struct { 35 | configPath string 36 | yamlContent YamlParserV1 37 | } 38 | 39 | // GetEnvparser : It returns envparser instance 40 | func GetEnvparser() *Envparser { 41 | var envParser = Envparser{configPath: "/etc/ec2_connect_config.yaml"} 42 | envParser.OpenConfigFile() 43 | return &envParser 44 | } 45 | 46 | // GetCredentials : Return AWS credentials from file 47 | func (ep *Envparser) GetCredentials() (string, string, error) { 48 | // TODO : Check yamlContent if keys exist 49 | accessID := ep.yamlContent.Spec.Credentials.AccessKey 50 | secretKey := ep.yamlContent.Spec.Credentials.SecretKey 51 | 52 | if accessID == "" || secretKey == "" { 53 | return "", "", errors.New("Cannot find credentials in configuration file") 54 | } 55 | return accessID, secretKey, nil 56 | } 57 | 58 | // GetDefaultKey : Return default SSH key from configuration file 59 | func (ep *Envparser) GetDefaultKey() (defaultKey string) { 60 | // Should I check whether EC2_SSH.. key exists? :D 61 | for _, element := range ep.yamlContent.Spec.PrivateKeys { 62 | if element.Name == "default" { 63 | return element.Path 64 | } 65 | } 66 | // TODO : return non-nil if default not exists 67 | log.Fatal("Cannot found default key (.spec.privateKeys -> 'default' key)") 68 | return defaultKey 69 | } 70 | 71 | // OpenConfigFile Return osfile pointer to parse configuration file 72 | func (ep *Envparser) OpenConfigFile() (result map[string]interface{}) { 73 | yamlFile, err := ioutil.ReadFile(ep.configPath) 74 | if err != nil { 75 | log.Fatal("Unable to open /etc/ec2_connect_config.yaml. Abort") 76 | } 77 | err = yaml.Unmarshal(yamlFile, &ep.yamlContent) 78 | if err != nil { 79 | log.Fatal("Failed to unmarshal /etc/ec2_connect_config.yaml. Abort") 80 | } 81 | return result 82 | } 83 | 84 | // GetCustomKey : Return custom key path from configuration file 85 | func (ep *Envparser) GetCustomKey(key string) (customKeyPath string) { 86 | for _, element := range ep.yamlContent.Spec.PrivateKeys { 87 | if element.Name == key { 88 | return element.Path 89 | } 90 | } 91 | log.Fatal(fmt.Sprintf("Cannot find key [%s] in configuration file", key)) 92 | return customKeyPath 93 | } 94 | 95 | // GetGroupInstanceNames : Return instance names of named group in configuration file 96 | func (ep *Envparser) GetGroupInstanceNames(groupName string) (instanceNames []string) { 97 | for _, element := range ep.yamlContent.Spec.InstanceGroups { 98 | if element.GroupName == groupName { 99 | return element.InstanceName 100 | } 101 | } 102 | log.Fatal(fmt.Sprintf("Cannot find group [%s] in configuration file", groupName)) 103 | return instanceNames 104 | } 105 | 106 | func (ep *Envparser) GetRegion() string { 107 | region := ep.yamlContent.Spec.Region 108 | return region 109 | } 110 | 111 | //func checkKeys(secretData map[string]interface{}, data []string) error { 112 | // for val := range data { 113 | // if _, ok := secretData[data[val]]; !ok { 114 | // return errors.New(fmt.Sprint("Cannot found key in configuration file : ", data[val])) 115 | // } 116 | // } 117 | // return nil 118 | //} 119 | -------------------------------------------------------------------------------- /test/aws_sdk_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "fmt" 5 | aws2 "github.com/alicek106/go-ec2-ssh-autoconnect/pkg/aws" 6 | "testing" 7 | 8 | "github.com/aws/aws-sdk-go/aws" 9 | "github.com/aws/aws-sdk-go/aws/session" 10 | "github.com/aws/aws-sdk-go/service/ec2" 11 | ) 12 | 13 | func TestDescribeEc2Instances(t *testing.T) { 14 | session.Must(session.NewSession()) 15 | 16 | // Load session from shared config 17 | sess := session.Must(session.NewSession(&aws.Config{ 18 | Region: aws.String("ap-northeast-2"), 19 | })) 20 | 21 | // Create new EC2 client 22 | ec2Svc := ec2.New(sess) 23 | // Call to get detailed information on each instance 24 | _, err := ec2Svc.DescribeInstances(nil) 25 | if err != nil { 26 | fmt.Println("TestDescribeEc2Instances: Error", err) 27 | } else { 28 | fmt.Println("TestDescribeEc2Instances: Success to describe instances") 29 | } 30 | } 31 | 32 | func TestGetUsernamePerOS(t *testing.T) { 33 | aem := aws2.AwsEc2Manager{Ec2StartWaitTimeout: 30} 34 | aem.CheckCredentials() 35 | 36 | username := aem.GetUsernamePerOS("bakery") 37 | fmt.Printf("TestGetUsernamePerOS: Found username: %s", username) 38 | } 39 | --------------------------------------------------------------------------------