aell 0.1.0 → 0.3.0

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: c21d73c186534e4f439d42d762ffe4cf97ac7590981fea017de02e384d5d9dc9
4
- data.tar.gz: 6145658d3ef742ad3989e61b9d69ed1643f94a51eeea36016c96cd9c0e635810
3
+ metadata.gz: 6a366cd9a2b0a141f24e8270b81aa32e3ae1f6fe0c0a30c1c09b10bbd3056796
4
+ data.tar.gz: d890e5c9b5148cfb13653eef9fde2dcf993e0d0ea80eab4e4c54653240c886f3
5
5
  SHA512:
6
- metadata.gz: 87fb47f0f0084fb13ede06a4acb00111d2531c5950f34f58d4bdaa27bb3f057fbbe1cb0fab60c17d67ca460e6ed5e3dc641b5eea1281bb3fb7c20fb41e86d8f0
7
- data.tar.gz: 254553736aaa335d3d1dfa897e0eaa8fe51e0d011feb130009e4c719809e916e63f60483032a135ef2e517168be6d005e0d7cbc32f5ab54c557c21dd9d2cb03b
6
+ metadata.gz: 2858561b28f5779e03b3858803cef5e658796e88207ed5cd2074cafee0ab111ebfc9f79fc41e9b421f3ed2581d5cd5dc6e1faaa3762f7c516083fdd34a1300fd
7
+ data.tar.gz: 579d2b0931b72141f57d7e94a3ebe86c1784b9c4ea803764db3a7ffab8ae96cf00739fd4631045d1eab66276aca9e09050f3e2e5bf841ed06c635f4f3c1d6c10
@@ -1,30 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aell (0.1.0)
4
+ aell (0.3.0)
5
5
  aws-sdk-ec2 (~> 1.137)
6
6
  net-ssh-multi (~> 1.2.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- aws-eventstream (1.0.3)
12
- aws-partitions (1.267.0)
13
- aws-sdk-core (3.89.1)
14
- aws-eventstream (~> 1.0, >= 1.0.2)
11
+ aws-eventstream (1.1.0)
12
+ aws-partitions (1.354.0)
13
+ aws-sdk-core (3.104.3)
14
+ aws-eventstream (~> 1, >= 1.0.2)
15
15
  aws-partitions (~> 1, >= 1.239.0)
16
16
  aws-sigv4 (~> 1.1)
17
17
  jmespath (~> 1.0)
18
- aws-sdk-ec2 (1.137.0)
19
- aws-sdk-core (~> 3, >= 3.71.0)
18
+ aws-sdk-ec2 (1.186.0)
19
+ aws-sdk-core (~> 3, >= 3.99.0)
20
20
  aws-sigv4 (~> 1.1)
21
- aws-sigv4 (1.1.0)
22
- aws-eventstream (~> 1.0, >= 1.0.2)
21
+ aws-sigv4 (1.2.1)
22
+ aws-eventstream (~> 1, >= 1.0.2)
23
23
  coderay (1.1.2)
24
24
  diff-lcs (1.3)
25
25
  jmespath (1.4.0)
26
26
  method_source (0.9.2)
27
- net-ssh (5.2.0)
27
+ net-ssh (6.1.0)
28
28
  net-ssh-gateway (2.0.0)
29
29
  net-ssh (>= 4.0.0)
30
30
  net-ssh-multi (1.2.1)
@@ -33,7 +33,7 @@ GEM
33
33
  pry (0.12.2)
34
34
  coderay (~> 1.1.0)
35
35
  method_source (~> 0.9.0)
36
- rake (10.5.0)
36
+ rake (13.0.1)
37
37
  rspec (3.9.0)
38
38
  rspec-core (~> 3.9.0)
39
39
  rspec-expectations (~> 3.9.0)
@@ -55,8 +55,8 @@ DEPENDENCIES
55
55
  aell!
56
56
  bundler (~> 1.17)
57
57
  pry
58
- rake (~> 10.0)
58
+ rake (>= 12.3.3)
59
59
  rspec (~> 3.0)
60
60
 
61
61
  BUNDLED WITH
62
- 1.17.2
62
+ 1.17.3
data/README.md CHANGED
@@ -22,20 +22,30 @@ To start using aell you need a `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and
22
22
  export AWS_ACCESS_KEY_ID=my_access_key
23
23
  export AWS_SECRET_ACCESS_KEY=secret_access_key
24
24
  export AWS_REGION=aws_region(eg: us-east-1)
25
+
26
+ # OPTIONAL (when using MFA)
27
+ export AWS_SESSION_TOKEN=secret_session_token
25
28
  ```
26
29
 
27
30
  Or set with the aell options in each command:
28
31
 
29
32
  ```bash
30
- aell - Application:some-app -u deploy-user --access_key_id access_key_id --secret_access_key secret_access_key --region us-east-1 -c 'echo "Hello Aell"'
33
+ aell -t Application:some-app -u deploy-user --access_key_id access_key_id --secret_access_key secret_access_key --region us-east-1 -c 'echo "Hello Aell"'
31
34
  ```
35
+
36
+ Aell can also use aws configuration in ~/.aws/, or use a specific profile with `--profile` option, eg:
37
+
38
+
39
+ ```bash
40
+ aell --profile my_other_profile -t Application:some-app -u deploy-user -c 'echo "Hello Aell"'
41
+ ```
42
+
32
43
  Aell use AWS tags to query the servers with the `-t`/ `--tag` flags, to know more just type `aell -h`
33
44
 
34
45
  ## TODO
35
46
 
36
- 1. Configure a Docker image
37
- 2. Separate concerns
38
- 3. Add specs
47
+ 1. Separate concerns
48
+ 2. Add specs
39
49
 
40
50
  ## Contributing
41
51
 
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency "pry"
30
30
  spec.add_development_dependency "bundler", "~> 1.17"
31
- spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rake", ">= 12.3.3"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
33
  end
data/exe/aell CHANGED
@@ -6,18 +6,18 @@ require 'aws-sdk-ec2'
6
6
  AWS_ACCESS_KEY_ID = ENV['AWS_ACCESS_KEY_ID']
7
7
  AWS_SECRET_ACCESS_KEY = ENV['AWS_SECRET_ACCESS_KEY']
8
8
  AWS_REGION = ENV['AWS_REGION']
9
+ AWS_SESSION_TOKEN = ENV['AWS_SESSION_TOKEN']
10
+
11
+ Signal.trap("INT") { exit 2 }
9
12
 
10
13
  def verify_options!(options)
11
- u error('Error: Missing user "-u my_user"') unless options[:user]
12
- error('Error: Missing tag "-t some_tag:example" or hosts "-h 10.0.0.1,my_domain.intra"') unless options[:tag] || options[:hosts]
13
- error('Error: Missing command "-c some_command"') unless options[:command]
14
- error('Error: Missing AWS_ACCESS_KEY_ID, set with AWS_ACCESS_KEY_ID environment variable or with "--access_key_id my_key"') unless options[:access_key_id] || options[:hosts]
15
- error('Error: Missing AWS_SECRET_ACCESS_KEY, set with AWS_SECRET_ACCESS_KEY environment variable or with "--secret_access_key my_key"') unless options[:secret_access_key] || options[:hosts]
16
- error('Error: Missing AWS_REGION, set with AWS_REGION environment variable or with "--region region"') unless options[:region] || options[:hosts]
14
+ error('Missing user "-u my_user"') unless options[:user]
15
+ error('Missing tag "-t some_tag:example" or hosts "-h 10.0.0.1,my_domain.intra"') unless options[:tag] || options[:hosts]
16
+ error('Missing command "-c some_command"') unless options[:command]
17
17
  end
18
18
 
19
19
  def error(message)
20
- $stderr.puts message
20
+ $stderr.puts "[ERROR] #{message}"
21
21
  exit 1
22
22
  end
23
23
 
@@ -28,27 +28,39 @@ def parse_tags(tags)
28
28
  [tag, parsed_values]
29
29
  end
30
30
 
31
- def get_servers_ips(access_key_id, secret_access_key, region, tags)
32
- tag, values = parse_tags(tags)
33
-
34
- ec2_client = Aws::EC2::Client.new(access_key_id: access_key_id, secret_access_key: secret_access_key, region: region)
31
+ def get_servers_ips(tag:, **aws_options)
32
+ tag_name, values = parse_tags(tag)
33
+ ec2_client = Aws::EC2::Client.new(**aws_options.compact)
35
34
  ec2 = Aws::EC2::Resource.new(client: ec2_client)
36
35
  ec2.instances({
37
36
  filters:
38
37
  [{
39
- name: "tag:#{tag}",
38
+ name: "tag:#{tag_name}",
40
39
  values: values
41
40
  }]
42
41
  })
43
- .collect { |i| i.private_ip_address }
42
+ .collect { |i| i.private_ip_address }.compact
43
+
44
+ rescue Aws::EC2::Errors::ServiceError => ex
45
+ error(ex.message)
46
+ rescue Interrupt
47
+ exit 2
44
48
  end
45
49
 
46
50
  options = {
47
51
  access_key_id: AWS_ACCESS_KEY_ID,
48
52
  secret_access_key: AWS_SECRET_ACCESS_KEY,
49
- region: AWS_REGION
53
+ session_token: AWS_SESSION_TOKEN,
54
+ region: AWS_REGION,
55
+ verify_host_key: :never,
50
56
  }
51
57
 
58
+ class Hash
59
+ def except(*keys)
60
+ self.reject { |k,v| keys.include?(k) }
61
+ end
62
+ end
63
+
52
64
  OptionParser.new do |opts|
53
65
  opts.banner = <<-BANNER
54
66
  Aell - Run commands in multiple servers querying by your AWS Infrastructure
@@ -75,6 +87,14 @@ BANNER
75
87
  options[:user] = user
76
88
  end
77
89
 
90
+ opts.on("--single", "Only runs in one host") do
91
+ options[:single] = true
92
+ end
93
+
94
+ opts.on("--verify-host-key HOST_VERIFICATION", "Check host key when connecting (never, accept_new_or_local_tunnel, accept_new or always), default: never") do |host_verification|
95
+ options[:verify_host_key] = host_verification.to_sym
96
+ end
97
+
78
98
  opts.on("-v", "--version", "Shows aell version") do
79
99
  puts Aell::VERSION
80
100
  exit
@@ -92,6 +112,15 @@ BANNER
92
112
  options[:region] = region
93
113
  end
94
114
 
115
+ opts.on("--profile PROFILE", "Sets the profile (using ~/.aws/credentials), overrides --access_key_id, --secret_access_key, --region, --session_token options and environment variables") do |profile|
116
+ options[:profile] = profile
117
+ options.reject! { |k, v| [:access_key_id, :secret_access_key, :region, :session_token].include?(k) }
118
+ end
119
+
120
+ opts.on("--session-token SESSION_TOKEN ", "Sets the session token when using AWS MFA") do |session_token|
121
+ options[:session_token] = session_token
122
+ end
123
+
95
124
  opts.on_tail("-h", "--help", "Show this message") do
96
125
  puts opts
97
126
  exit
@@ -100,13 +129,17 @@ end.parse!
100
129
 
101
130
  verify_options!(options)
102
131
 
103
- servers = options[:hosts] || get_servers_ips(options[:access_key_id], options[:secret_access_key], options[:region], options[:tag])
132
+ servers = options[:hosts] || get_servers_ips(**options.except(:user, :hosts, :command, :single, :verify_host_key))
133
+
134
+ servers = [servers.first] if options[:single]
104
135
 
105
136
  begin
106
137
  Thread.report_on_exception = false
107
138
  Net::SSH::Multi.start do |session|
108
139
  servers.each do |server|
109
- session.use(options[:user] ? "#{options[:user]}@#{server}" : server)
140
+ connection = options[:user] ? "#{options[:user]}@#{server}" : server
141
+
142
+ session.use(connection, verify_host_key: options[:verify_host_key])
110
143
  end
111
144
 
112
145
  session.exec options[:command]
@@ -1,3 +1,3 @@
1
1
  module Aell
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Atkinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2021-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ec2
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: 12.3.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: 12.3.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -135,7 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.0.3
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.6
139
140
  signing_key:
140
141
  specification_version: 4
141
142
  summary: Run commands on multiple servers in your AWS Infrastructure