aws_recon 0.2.1 → 0.2.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/aws_recon.rb +0 -1
- data/lib/aws_recon/aws_recon.rb +36 -34
- data/lib/aws_recon/options.rb +2 -2
- data/lib/aws_recon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 233f4b10a4360186449d4046d61bb0ae0e78511483e4dac27ae0dfee89a8ff04
|
4
|
+
data.tar.gz: 1cde6970d7f06cdfa0d52cefd9d931794c832cceeb98c7b8fe5e2f7aa5a447ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38ee33272bf5980f4c4e5a764790e29222febaf435bab4c7a7b478a688b07211432a281b762ec94565d052be2f7496a45b028b501f1c741446b06a87da75611f
|
7
|
+
data.tar.gz: 5691d204c31c2423e92c86bcb05b27406c95285ef5777d1f5225496750aae35a6642c52f3b4b92ac36859c05692bced6c0968f11d41ee12a43ed628a98f74afc
|
data/Gemfile.lock
CHANGED
data/lib/aws_recon.rb
CHANGED
data/lib/aws_recon/aws_recon.rb
CHANGED
@@ -4,37 +4,39 @@ SERVICES_CONFIG_FILE = File.join(File.dirname(__FILE__), 'services.yaml').freeze
|
|
4
4
|
|
5
5
|
module AwsRecon
|
6
6
|
class CLI
|
7
|
-
|
8
|
-
|
7
|
+
def initialize
|
8
|
+
# parse options
|
9
|
+
@options = Parser.parse ARGV.length < 1 ? %w[-h] : ARGV
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
# timing
|
12
|
+
@starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
# AWS account id
|
15
|
+
@account_id = Aws::STS::Client.new.get_caller_identity.account
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
# AWS services
|
18
|
+
@aws_services = YAML.load(File.read(SERVICES_CONFIG_FILE), symbolize_names: true)
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
# User config services
|
21
|
+
if @options.config_file
|
22
|
+
user_config = YAML.load(File.read(@options.config_file), symbolize_names: true)
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
@services = user_config[:services]
|
25
|
+
@regions = user_config[:regions]
|
26
|
+
else
|
27
|
+
@regions = @options.regions
|
28
|
+
@services = @options.services
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
# collection
|
32
|
+
@resources = []
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
# formatter
|
35
|
+
@formatter = Formatter.new
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
unless @options.stream_output
|
38
|
+
puts "\nStarting collection with #{@options.threads} threads...\n"
|
39
|
+
end
|
38
40
|
end
|
39
41
|
|
40
42
|
#
|
@@ -66,16 +68,16 @@ module AwsRecon
|
|
66
68
|
#
|
67
69
|
# main wrapper
|
68
70
|
#
|
69
|
-
def start
|
71
|
+
def start(_args)
|
70
72
|
#
|
71
73
|
# global services
|
72
74
|
#
|
73
|
-
aws_services.map { |x| OpenStruct.new(x) }.filter { |s| s.global }.each do |service|
|
75
|
+
@aws_services.map { |x| OpenStruct.new(x) }.filter { |s| s.global }.each do |service|
|
74
76
|
# user included this service in the args
|
75
|
-
next unless services.include?(service.name)
|
77
|
+
next unless @services.include?(service.name)
|
76
78
|
|
77
79
|
# user did not exclude 'global'
|
78
|
-
next unless regions.include?('global')
|
80
|
+
next unless @regions.include?('global')
|
79
81
|
|
80
82
|
collect(service, 'global')
|
81
83
|
end
|
@@ -83,28 +85,28 @@ module AwsRecon
|
|
83
85
|
#
|
84
86
|
# regional services
|
85
87
|
#
|
86
|
-
regions.filter { |x| x != 'global' }.each do |region|
|
87
|
-
Parallel.map(aws_services.map { |x| OpenStruct.new(x) }.filter { |s| !s.global }.each, in_threads: @options.threads) do |service|
|
88
|
+
@regions.filter { |x| x != 'global' }.each do |region|
|
89
|
+
Parallel.map(@aws_services.map { |x| OpenStruct.new(x) }.filter { |s| !s.global }.each, in_threads: @options.threads) do |service|
|
88
90
|
# some services aren't available in some regions
|
89
|
-
skip_region = service&.excluded_regions&.include?(region)
|
91
|
+
skip_region = @service&.excluded_regions&.include?(region)
|
90
92
|
|
91
93
|
# user included this region in the args
|
92
|
-
next unless regions.include?(region) && !skip_region
|
94
|
+
next unless @regions.include?(region) && !skip_region
|
93
95
|
|
94
96
|
# user included this service in the args
|
95
|
-
next unless services.include?(service.name) || services.include?(service.alias) # rubocop:disable Layout/LineLength
|
97
|
+
next unless @services.include?(service.name) || @services.include?(service.alias) # rubocop:disable Layout/LineLength
|
96
98
|
|
97
99
|
collect(service, region)
|
98
100
|
end
|
99
101
|
end
|
100
102
|
rescue Interrupt # ctrl-c
|
101
|
-
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting
|
103
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @starting
|
102
104
|
|
103
105
|
puts "\nStopped early after \x1b[32m#{elapsed.to_i}\x1b[0m seconds.\n"
|
104
106
|
ensure
|
105
107
|
# write output file
|
106
108
|
if @options.output_file
|
107
|
-
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting
|
109
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @starting
|
108
110
|
|
109
111
|
puts "\nFinished in \x1b[32m#{elapsed.to_i}\x1b[0m seconds. Saving resources to \x1b[32m#{@options.output_file}\x1b[0m.\n\n"
|
110
112
|
|
data/lib/aws_recon/options.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class Parser
|
4
4
|
DEFAULT_CONFIG_FILE = nil
|
5
|
-
DEFAULT_OUTPUT_FILE = File.
|
5
|
+
DEFAULT_OUTPUT_FILE = File.expand_path(File.join(Dir.pwd, 'output.json')).freeze
|
6
6
|
SERVICES_CONFIG_FILE = File.join(File.dirname(__FILE__), 'services.yaml').freeze
|
7
7
|
DEFAULT_FORMAT = 'aws'
|
8
8
|
DEFAULT_THREADS = 8
|
@@ -86,7 +86,7 @@ class Parser
|
|
86
86
|
|
87
87
|
# output file
|
88
88
|
opts.on('-o', '--output [OUTPUT]', 'Specify output file (default: output.json)') do |output|
|
89
|
-
args.output_file = output
|
89
|
+
args.output_file = File.expand_path(File.join(Dir.pwd, output))
|
90
90
|
end
|
91
91
|
|
92
92
|
# output format
|
data/lib/aws_recon/version.rb
CHANGED