sty 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be460e9dd95543a4956eddfaa6e45b8f1d8f9f89d74560bc769e23ad8284fd71
4
- data.tar.gz: 0f6383f3d4913d6997420b78b6a30a9c266d029a45b2539c2fee6fa0c33aba77
3
+ metadata.gz: 7ceaafb4b92a0332aabcc49bd368a523a4be721c4bcc1bd1cb5cee40e662d2f6
4
+ data.tar.gz: 57e5292eeeb81d7a550c1a923493369927ad6d6a68536675b609c25cf5d3f239
5
5
  SHA512:
6
- metadata.gz: 1a6cab7166156c2be6e4f4ca0e7c66fe34687ec30b738ad4b35cf229f04852540fcc29bd2488f583e09a666c3f837bad12c1eb01c7c12c065ce282dce53e4d90
7
- data.tar.gz: 67468b0793e2073b989d91d20d4e0e81e067b3e7cc9429bed8cb67de829e2161ce9cc0c898a9c97141dee04d9200e910bda0e6f8aa0d27bb902e0d19e8ce4400
6
+ metadata.gz: 6c4af2cfa09c0149cb2d9bfb702271f1bf5d7d535c723b74da5289a4e9b8f5afc1b424b640827dab9c54112c84f6781b8851812c9a71fa7f34423bf5710bf9d8
7
+ data.tar.gz: d7c6e93effa758489e3577ab8de14ec33d0ffbc70ab8236eda737a755a913bd4e334e8f926800ede30e9d5da7a7af0ddc472d4c5ca78000391a7f7846a9ca94e
@@ -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']
@@ -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 "ssh [OPTIONS] <SEARCH_TERM...>","Creates ssh connection to desired ec2 instance through existing jumphost. SEARCH_TERM to search in EC2 instance ID, name or IP address"
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[:browser])
41
+ Auth.new.login(path, options[:role])
36
42
  end
37
43
 
38
44
  desc "logout", "Forget current credentials and clear cache"
@@ -1,19 +1,18 @@
1
1
  require_relative 'functions'
2
- require 'aws-sdk-ec2'
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
- Aws.config.update(:http_proxy => ENV['https_proxy'])
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
- MINIMAL_AGENT_VERSION = '2.3.612.0'
14
- DEFAULT_REGION = 'ap-southeast-2'
15
-
16
- class SSM
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
- case
131
- when OS.mac?
132
- "#{dir}/bin/osx/session-manager-plugin"
133
- when OS.linux?
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(args)
141
- found = find(all_ec2_instances, args)
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: #{args.join(', ')}"
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)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'sty'
7
- s.version = '0.0.1'
7
+ s.version = '0.0.3'
8
8
  s.description = "Command line tools"
9
9
  s.authors = ["Andrew Sozonnyk"]
10
10
  s.email = ''
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.1
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-07 00:00:00.000000000 Z
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
- rubygems_version: 3.0.3
153
+ rubyforge_project:
154
+ rubygems_version: 2.7.7
154
155
  signing_key:
155
156
  specification_version: 4
156
157
  summary: Command line tools