aws_recon 0.2.1 → 0.2.2

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: a8cd90cd73ab80c766882e88a2bbd5f03c106a7365805b7e50847997decd98de
4
- data.tar.gz: 1a605e550317fdbf2295f72c0df9df6bdb02b1cb70e940d83db3c779d165d7d3
3
+ metadata.gz: 233f4b10a4360186449d4046d61bb0ae0e78511483e4dac27ae0dfee89a8ff04
4
+ data.tar.gz: 1cde6970d7f06cdfa0d52cefd9d931794c832cceeb98c7b8fe5e2f7aa5a447ab
5
5
  SHA512:
6
- metadata.gz: f3f8600403036263543e0be3d9fee779d40a9cedbed38a982f8144e645c1184d0e4c135691d87d0e7809033c55e371dab4eaaba8ff80b6ba27baab7663d75ec0
7
- data.tar.gz: 7e4af190e9451570c40e90fdd222899bc11c072da15f496d7739cf057da5ee04615d6a6b0cfda375308fda88a9dd91796bb0ab8e31e6d3289f7cf4daf7286e3c
6
+ metadata.gz: 38ee33272bf5980f4c4e5a764790e29222febaf435bab4c7a7b478a688b07211432a281b762ec94565d052be2f7496a45b028b501f1c741446b06a87da75611f
7
+ data.tar.gz: 5691d204c31c2423e92c86bcb05b27406c95285ef5777d1f5225496750aae35a6642c52f3b4b92ac36859c05692bced6c0968f11d41ee12a43ed628a98f74afc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aws_recon (0.2.1)
4
+ aws_recon (0.2.2)
5
5
  aws-sdk (~> 3.0)
6
6
  parallel (~> 1.19)
7
7
 
@@ -8,7 +8,6 @@ require 'ostruct'
8
8
  require 'optparse'
9
9
  require 'yaml'
10
10
  require 'csv'
11
- require 'pry'
12
11
  require 'aws-sdk'
13
12
  require 'aws_recon/options.rb'
14
13
  require 'aws_recon/lib/mapper.rb'
@@ -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
- # parse options
8
- @options = Parser.parse ARGV.length < 1 ? %w[-h] : ARGV
7
+ def initialize
8
+ # parse options
9
+ @options = Parser.parse ARGV.length < 1 ? %w[-h] : ARGV
9
10
 
10
- # timing
11
- starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
11
+ # timing
12
+ @starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
13
 
13
- # AWS account id
14
- @account_id = Aws::STS::Client.new.get_caller_identity.account
14
+ # AWS account id
15
+ @account_id = Aws::STS::Client.new.get_caller_identity.account
15
16
 
16
- # AWS services
17
- aws_services = YAML.load(File.read(SERVICES_CONFIG_FILE), symbolize_names: true)
17
+ # AWS services
18
+ @aws_services = YAML.load(File.read(SERVICES_CONFIG_FILE), symbolize_names: true)
18
19
 
19
- # User config services
20
- if @options.config_file
21
- user_config = YAML.load(File.read(@options.config_file), symbolize_names: true)
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
- services = user_config[:services]
24
- regions = user_config[:regions]
25
- else
26
- regions = @options.regions
27
- services = @options.services
28
- end
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
- # collection
31
- @resources = []
31
+ # collection
32
+ @resources = []
32
33
 
33
- # formatter
34
- @formatter = Formatter.new
34
+ # formatter
35
+ @formatter = Formatter.new
35
36
 
36
- unless @options.stream_output
37
- puts "\nStarting collection with #{@options.threads} threads...\n"
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  class Parser
4
4
  DEFAULT_CONFIG_FILE = nil
5
- DEFAULT_OUTPUT_FILE = File.join(File.dirname(__FILE__), '../output.json').freeze
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
@@ -1,3 +1,3 @@
1
1
  module AwsRecon
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_recon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Larsen