bjn_inventory 1.6.1 → 1.7.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
  SHA1:
3
- metadata.gz: 7c369f7e212b129cc8ac7a5250d52871f2deacc8
4
- data.tar.gz: 21598b6ea85a9a682ae56f9225427d77c87b189d
3
+ metadata.gz: 21424b757dc88cdcc3a45e9b73048cdc6ab89aca
4
+ data.tar.gz: 29ccd6111924efa1aad46597613d314672e2b56e
5
5
  SHA512:
6
- metadata.gz: f9a44ce178222496e27deeb2d5f4ac243d16f281380e88acfd138ece48e906f4cc62bd5ebeaffe3ca695a18144daf0f6acf365725011982ea96ca9001ccd5f30
7
- data.tar.gz: 14822ee517b05531ffb82397316658d9794f13482639d3135d909dc63826058ec396393bdb225518ba23868253d135f81288283544b1b32410e4c5bd72553f8b
6
+ metadata.gz: a80b616041802f4627d4226f667dbf6f9cf5ed016a4754ac9cdde94b67eb01f6e01f55ce7586ad9e5f1b694a49879e15318459d991c88b914b20bbe1f85199ae
7
+ data.tar.gz: 2bb3e6f0181a5808c51201431a7b0ed3294550567062903b7c583c68b6ab1f016daa43e18faf3c0f1edafa78b3ae65cfe519ba29a7c75260afd868a0cc817624
data/bin/aws-elb-source CHANGED
@@ -11,7 +11,7 @@ parser = Trollop::Parser.new do
11
11
  banner <<-USAGE.gsub(/^\s{8}/,'')
12
12
  Usage:
13
13
  aws-elb-source [options]
14
- Download entries corresponding to classic elastic loadbalancers (not application load balancers)
14
+ Download entries corresponding to classic, application, and network elastic loadbalancers
15
15
  USAGE
16
16
 
17
17
  opt :region, "Specify region (default is all regions)", type: :string, multi: true
@@ -24,11 +24,11 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_dependency 'jsonpath', "~> 0.7.2"
27
- spec.add_dependency 'trollop'
28
- spec.add_dependency 'aws-sdk'
27
+ spec.add_dependency 'trollop', "~> 2.0"
28
+ spec.add_dependency 'aws-sdk', "~> 3.0"
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.9"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
- spec.add_development_dependency "rspec_junit_formatter"
33
+ spec.add_development_dependency "rspec_junit_formatter", "~> 0"
34
34
  end
@@ -39,7 +39,7 @@ module BjnInventory
39
39
  Aws::EC2::Client.new(opts)
40
40
  end
41
41
 
42
- def new_client(region=nil)
42
+ def new_classic_client(region=nil)
43
43
  opts = {
44
44
  region: (region || @regions.first)
45
45
  }
@@ -47,36 +47,79 @@ module BjnInventory
47
47
  Aws::ElasticLoadBalancing::Client.new(opts)
48
48
  end
49
49
 
50
+ def new_client(region=nil)
51
+ opts = {
52
+ region: (region || @regions.first)
53
+ }
54
+ opts.update({profile: @profile}) if @profile
55
+ Aws::ElasticLoadBalancingV2::Client.new(opts)
56
+ end
57
+
50
58
  def retrieve_entries(override_client=nil)
51
59
  entries = @regions.map do |region|
52
- client = override_client || @client || new_client(region)
53
- _retrieve_entries([], client)
60
+ if override_client || @client
61
+ client = override_client || @client
62
+ logger.debug "client: #{client.class.to_s}"
63
+ all_lbs = _retrieve_entries([], client)
64
+ else
65
+ logger.debug "region: #{region}"
66
+ classic_lbs = _retrieve_entries([], new_classic_client(region))
67
+ v2_lbs = _retrieve_entries([], new_client(region))
68
+ all_lbs = classic_lbs + v2_lbs
69
+ end
54
70
  end.flatten
55
71
  end
56
72
 
57
73
  def _retrieve_entries(current, client, marker=nil)
58
- logger.debug "Describing load balancers (page #{marker})"
74
+ logger.debug "client: #{client.class.to_s}"
75
+ logger.debug "Describing load balancers (page #{marker || 0})"
59
76
  chunk_result = client.describe_load_balancers(marker: marker, page_size: @page_size)
60
77
  logger.debug "... described"
61
- marker = chunk_result.next_marker
78
+ new_marker = chunk_result.next_marker
79
+ if client.class.to_s.include?('Aws::ElasticLoadBalancing::Client')
80
+ chunk_list = _retrieve_classic_entries(current, client, chunk_result)
81
+ else
82
+ chunk_list = _retrieve_v2_entries(current, client, chunk_result)
83
+ end
84
+ if new_marker
85
+ return _retrieve_entries(current + chunk_list, client, new_marker)
86
+ else
87
+ return current + chunk_list
88
+ end
89
+ end
90
+
91
+ def _retrieve_classic_entries(current, client, chunk_result)
62
92
  if chunk_result.load_balancer_descriptions.length > 0
63
93
  chunk = Hash[chunk_result.load_balancer_descriptions.map { |lb| [lb.load_balancer_name, lb.to_h] }]
64
94
  logger.debug "Describing load balancer tags"
65
95
  # Amazon only allows 20 names to be submitted
66
96
  chunk_tags = Hash[client.describe_tags(load_balancer_names: chunk.keys).tag_descriptions.map do |lbtags|
67
- [lbtags.load_balancer_name, { tags: lbtags.to_h[:tags] }]
68
- end]
97
+ [lbtags.load_balancer_name, { tags: lbtags.to_h[:tags] }]
98
+ end]
69
99
  logger.debug "... described"
70
100
  chunk_list = chunk.map { |lbname, lb| lb.merge(chunk_tags[lbname]) }
71
101
  else
72
102
  chunk_list = [ ]
73
103
  end
74
104
  chunk_list = @filters.select(chunk_list)
75
- if marker
76
- return _retrieve_entries(current + chunk_list, client, marker)
105
+ return chunk_list
106
+ end
107
+
108
+ def _retrieve_v2_entries(current, client, chunk_result)
109
+ if chunk_result.load_balancers.length > 0
110
+ chunk = Hash[chunk_result.load_balancers.map { |lb| [lb.load_balancer_arn, lb.to_h] }]
111
+ logger.debug "Describing load balancer tags"
112
+ # Amazon only allows 20 names to be submitted
113
+ chunk_tags = Hash[client.describe_tags(resource_arns: chunk.keys).tag_descriptions.map do |lbtags|
114
+ [lbtags.resource_arn, { tags: lbtags.to_h[:tags] }]
115
+ end]
116
+ logger.debug "... described"
117
+ chunk_list = chunk.map { |lbname, lb| lb.merge(chunk_tags[lbname]) }
77
118
  else
78
- return current + chunk_list
119
+ chunk_list = [ ]
79
120
  end
121
+ chunk_list = @filters.select(chunk_list)
122
+ return chunk_list
80
123
  end
81
124
 
82
125
  end
@@ -1,3 +1,3 @@
1
1
  module BjnInventory
2
- VERSION = "1.6.1"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bjn_inventory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Brinkley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonpath
@@ -28,30 +28,30 @@ dependencies:
28
28
  name: trollop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: aws-sdk
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,14 +98,14 @@ dependencies:
98
98
  name: rspec_junit_formatter
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: