sty 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sty/auth.rb +3 -4
- data/lib/sty/cli.rb +8 -2
- data/lib/sty/ssm.rb +20 -24
- data/sty.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ceaafb4b92a0332aabcc49bd368a523a4be721c4bcc1bd1cb5cee40e662d2f6
|
4
|
+
data.tar.gz: 57e5292eeeb81d7a550c1a923493369927ad6d6a68536675b609c25cf5d3f239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c4af2cfa09c0149cb2d9bfb702271f1bf5d7d535c723b74da5289a4e9b8f5afc1b424b640827dab9c54112c84f6781b8851812c9a71fa7f34423bf5710bf9d8
|
7
|
+
data.tar.gz: d7c6e93effa758489e3577ab8de14ec33d0ffbc70ab8236eda737a755a913bd4e334e8f926800ede30e9d5da7a7af0ddc472d4c5ca78000391a7f7846a9ca94e
|
data/lib/sty/auth.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require_relative 'functions'
|
2
2
|
require_relative 'dig'
|
3
3
|
|
4
|
-
SESSION_DURATION_SECONDS = 43_200
|
5
|
-
DEFAULT_ROLE_NAME = 'ReadOnlyRole'
|
6
|
-
DEFAULT_REGION = 'ap-southeast-2'
|
7
|
-
|
8
4
|
class Auth
|
5
|
+
SESSION_DURATION_SECONDS = 43_200
|
6
|
+
DEFAULT_ROLE_NAME = 'ReadOnlyRole'
|
7
|
+
DEFAULT_REGION = 'ap-southeast-2'
|
9
8
|
|
10
9
|
def logout
|
11
10
|
current = ENV['AWS_ACTIVE_ACCOUNT']
|
data/lib/sty/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative 'auth'
|
|
4
4
|
require_relative 'console'
|
5
5
|
require_relative 'proxy'
|
6
6
|
require_relative 'ssh'
|
7
|
+
require_relative 'ssm'
|
7
8
|
|
8
9
|
class Cli < Thor
|
9
10
|
map auth: :login, acct: :account, px: :proxy
|
@@ -12,7 +13,12 @@ class Cli < Thor
|
|
12
13
|
'sty'
|
13
14
|
end
|
14
15
|
|
15
|
-
desc "
|
16
|
+
desc "ssm [OPTIONS] <SEARCH_TERMS...>","Creates ssm session to an EC2 instance. SEARCH_TERMS to search in EC2 instance ID, name or IP address"
|
17
|
+
def ssm(*search_term)
|
18
|
+
Ssm.new.connect(search_term)
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "ssh [OPTIONS] <SEARCH_TERMS...>","Creates ssh connection to an EC2 instance through existing jumphost. SEARCH_TERMS to search in EC2 instance ID, name or IP address"
|
16
22
|
method_option :no_jumphost, type: :boolean, default: false, aliases: "-n", desc: "Connect directly without jumphost"
|
17
23
|
method_option :select_jumphost, type: :boolean, aliases: "-s", desc: "Select jumphost instance"
|
18
24
|
method_option :use_key, type: :boolean, aliases: "-k", desc: "Use private key auth for target instance. Keys are searched recursively in ~/.sty/keys"
|
@@ -32,7 +38,7 @@ class Cli < Thor
|
|
32
38
|
method_option :role, aliases: "-r", dssc: "Override role name"
|
33
39
|
def login(path)
|
34
40
|
source_run(__method__)
|
35
|
-
Auth.new.login(path, options[:
|
41
|
+
Auth.new.login(path, options[:role])
|
36
42
|
end
|
37
43
|
|
38
44
|
desc "logout", "Forget current credentials and clear cache"
|
data/lib/sty/ssm.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
require_relative 'functions'
|
2
|
-
require '
|
3
|
-
require 'aws-sdk-ssm'
|
4
|
-
require 'optparse'
|
5
|
-
require 'ostruct'
|
2
|
+
require 'pathname'
|
6
3
|
require 'uri'
|
7
|
-
require 'pry'
|
8
4
|
require 'json'
|
9
|
-
require 'os'
|
10
5
|
|
11
|
-
|
6
|
+
class Ssm
|
7
|
+
MINIMAL_AGENT_VERSION = '2.3.612.0'
|
8
|
+
DEFAULT_REGION = 'ap-southeast-2'
|
9
|
+
SSM_PLUGIN = "/usr/local/bin/session-manager-plugin"
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def initialize
|
12
|
+
require 'aws-sdk-ec2'
|
13
|
+
require 'aws-sdk-ssm'
|
14
|
+
Aws.config.update(:http_proxy => ENV['https_proxy'])
|
15
|
+
end
|
17
16
|
|
18
17
|
def region
|
19
18
|
ENV['AWS_REGION'] || DEFAULT_REGION
|
@@ -126,21 +125,21 @@ class SSM
|
|
126
125
|
target
|
127
126
|
end
|
128
127
|
|
128
|
+
|
129
129
|
def session_manager
|
130
|
-
|
131
|
-
|
132
|
-
"
|
133
|
-
|
134
|
-
"#{dir}/bin/linux/session-manager-plugin"
|
135
|
-
else
|
136
|
-
raise "The tool doesn't have binary for #{OS.host}"
|
130
|
+
unless Pathname.new(SSM_PLUGIN).exist?
|
131
|
+
puts red("SSM plugin is not found: #{SSM_PLUGIN}.")
|
132
|
+
puts white("You must have SSM plugin to continue.\nSee: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html")
|
133
|
+
exit 1
|
137
134
|
end
|
135
|
+
SSM_PLUGIN
|
138
136
|
end
|
139
137
|
|
140
|
-
def connect(
|
141
|
-
|
138
|
+
def connect(search)
|
139
|
+
|
140
|
+
found = find(all_ec2_instances, search)
|
142
141
|
if found.empty?
|
143
|
-
puts "No instances found for search terms: #{
|
142
|
+
puts "No instances found for search terms: #{search.join(', ')}"
|
144
143
|
exit 1
|
145
144
|
end
|
146
145
|
target = refine(found) {|found| print_refine_instances(found, 'target')}
|
@@ -156,9 +155,6 @@ class SSM
|
|
156
155
|
mappings = {session_id: 'SessionId', token_value: 'TokenValue', stream_url: 'StreamUrl'}
|
157
156
|
reqest_str = resp.to_h.map {|k, v| [mappings[k], v] }.to_h.to_json
|
158
157
|
exec "#{session_manager} \'#{reqest_str}\' ap-southeast-2 StartSession"
|
159
|
-
|
160
158
|
end
|
161
159
|
|
162
160
|
end
|
163
|
-
|
164
|
-
SSM.new.connect(ARGV)
|
data/sty.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Sozonnyk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,7 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: 1.3.5
|
152
152
|
requirements: []
|
153
|
-
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.7.7
|
154
155
|
signing_key:
|
155
156
|
specification_version: 4
|
156
157
|
summary: Command line tools
|