aell 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0b9cdfe35653662f3cf6138a6774aa262ba50d0b9a2e3a04c138b247a07c2c5
4
- data.tar.gz: 240d89e6c92569f2cb4dd3d0755cf017cbce6a76a6f3045bf320ab7d92cef7e9
3
+ metadata.gz: 031b6bea2559754ae447585a7ac017b3c8ade5f7ea26464e965b758dcbecba11
4
+ data.tar.gz: 49dc4035c5c1c15355a9c992516f1111ee5e7e58af03c0b71e12e718bcfc5eb7
5
5
  SHA512:
6
- metadata.gz: 480f57e121f0eed90a5b084934bbb63ed0dc1e2eb45f092f52d5df9f8ec0ccb46e434dec4747937d940b1c795b666828971461779cabcabd88d52088d93cfa53
7
- data.tar.gz: 3065df9c0cae53b6d9a2b63c9a4b15acee5f7a85f3b27df131a50372cc79c2e3390d678122d2a385797d55c033a06da16d88736dd18369a2419918c9fefeb552
6
+ metadata.gz: 6d06c6be39d5e8b2797810dfe432a98f8d60ccd671f031ecaa32a2884e2aacc85ef1a9f000fed549d1fe271f2fb72997757289d42d2a8e3c6f083646e0e97fe7
7
+ data.tar.gz: 58059ab781c83dbe6044dbeed83cb0201eb336f17414fd71f640bbd396df8500c36ba64d4486b2b0977e463b2f219bb646a59a9bd09935a8474dd1b3330c8fae
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aell (0.1.2)
4
+ aell (0.2.0)
5
5
  aws-sdk-ec2 (~> 1.137)
6
6
  net-ssh-multi (~> 1.2.1)
7
7
 
@@ -9,7 +9,7 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  aws-eventstream (1.0.3)
12
- aws-partitions (1.267.0)
12
+ aws-partitions (1.269.0)
13
13
  aws-sdk-core (3.89.1)
14
14
  aws-eventstream (~> 1.0, >= 1.0.2)
15
15
  aws-partitions (~> 1, >= 1.239.0)
@@ -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,38 @@ 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
42
  .collect { |i| i.private_ip_address }.compact
43
+
44
+ rescue Aws::EC2::Errors::AuthFailure, Aws::Errors::Unauthorized => 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,
50
55
  }
51
56
 
57
+ class Hash
58
+ def except(*keys)
59
+ self.reject { |k,v| keys.include?(k) }
60
+ end
61
+ end
62
+
52
63
  OptionParser.new do |opts|
53
64
  opts.banner = <<-BANNER
54
65
  Aell - Run commands in multiple servers querying by your AWS Infrastructure
@@ -92,6 +103,15 @@ BANNER
92
103
  options[:region] = region
93
104
  end
94
105
 
106
+ 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|
107
+ options[:profile] = profile
108
+ options.reject! { |k, v| [:access_key_id, :secret_access_key, :region, :session_token].include?(k) }
109
+ end
110
+
111
+ opts.on("--session-token SESSION_TOKEN ", "Sets the session token when using AWS MFA") do |session_token|
112
+ options[:session_token] = session_token
113
+ end
114
+
95
115
  opts.on_tail("-h", "--help", "Show this message") do
96
116
  puts opts
97
117
  exit
@@ -100,7 +120,7 @@ end.parse!
100
120
 
101
121
  verify_options!(options)
102
122
 
103
- servers = options[:hosts] || get_servers_ips(options[:access_key_id], options[:secret_access_key], options[:region], options[:tag])
123
+ servers = options[:hosts] || get_servers_ips(**options.except(:user, :hosts, :command))
104
124
 
105
125
  begin
106
126
  Thread.report_on_exception = false
@@ -1,3 +1,3 @@
1
1
  module Aell
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.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.2
4
+ version: 0.2.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: 2020-06-17 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