awsrm 0.4.1 → 0.5.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: f20fbebe710966c2f9a378ea0ac221541fd4b7f4
4
- data.tar.gz: 570341d33be1ec4c5b79a4f0df33643292fcc428
3
+ metadata.gz: f3b49083839c8da0a8f155294f855350bd9dab43
4
+ data.tar.gz: 2d8ac89e9ac8cab58031c8dd12a8e46884c5cb7b
5
5
  SHA512:
6
- metadata.gz: 1339137f5c4e0a4382a7eade5f83f29dd4de7b50f403d03b50e0339d351a84d523a20c745ab965e0c9cf80627291d235cbf526f561a4648c1314b79ad686b671
7
- data.tar.gz: 026ba6311d240dd3689d359b31d9b6c41c256a774b70af655b771b56f5a416cbea8f012986915771847fadf69c79f6d359aa4cafe8c744392a45d5598206dfa0
6
+ metadata.gz: 111d5836a4ee98c125c79b9618df9fe4db33ff282bd7aa76b1ddc3bd45f1294acb0b9e3255b670fb7fdb33abd57b2f10067e519f12a2f16da4858b4a0dbad0f0
7
+ data.tar.gz: 6270e835d09e9eb62497137a6a2ddc1f00c6b0e501f356e513c90a42777e0ed6ca9fe12fb41805ef97fc702bb41f27006f6d0ade2c90e4d45a467d082dda6311
data/.rubocop.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.1
3
3
 
4
+ Layout/IndentHeredoc:
5
+ Enabled: false
6
+
4
7
  Lint/HandleExceptions:
5
8
  Enabled: false
6
9
 
data/awsrm.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
29
  spec.add_development_dependency 'rspec', '~> 3.0'
30
30
  spec.add_development_dependency 'awspec', '>= 0.80.0'
31
- spec.add_development_dependency 'rubocop', '~> 0.47.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.49.0'
32
32
  spec.add_development_dependency 'octorelease'
33
33
  spec.add_development_dependency 'pry'
34
34
  spec.add_development_dependency 'thor'
data/doc/resources.md CHANGED
@@ -5,6 +5,7 @@
5
5
  | [AlbTargetGroup](#alb_target_group)
6
6
  | [AutoscalingGroup](#autoscaling_group)
7
7
  | [Ec2](#ec2)
8
+ | [Elb](#elb)
8
9
  | [RouteTable](#route_table)
9
10
  | [Subnet](#subnet)
10
11
  | [Vpc](#vpc)
@@ -71,9 +72,23 @@
71
72
  | name | `tag:Name` |
72
73
  | vpc_id | `vpc-id` |
73
74
  | vpc | [`#<Proc>`](https://github.com/k1LoW/awsrm/blob/master/lib/awsrm/resources/ec2.rb) |
75
+ | elb | [`#<Proc>`](https://github.com/k1LoW/awsrm/blob/master/lib/awsrm/resources/ec2.rb) |
74
76
  | alb_target_group | [`#<Proc>`](https://github.com/k1LoW/awsrm/blob/master/lib/awsrm/resources/ec2.rb) |
75
77
 
76
78
 
79
+ ## <a name="elb">Awsrm::Elb</a>
80
+
81
+ ### Filter
82
+
83
+ | key | replaced filter |
84
+ | - | - |
85
+ | id | `load_balancer_name` |
86
+ | name | `load_balancer_name` |
87
+ | dns_name | `dns_name` |
88
+ | tags | [`#<Proc>`](https://github.com/k1LoW/awsrm/blob/master/lib/awsrm/resources/elb.rb) |
89
+ | vpc | [`#<Proc>`](https://github.com/k1LoW/awsrm/blob/master/lib/awsrm/resources/elb.rb) |
90
+
91
+
77
92
  ## <a name="route_table">Awsrm::RouteTable</a>
78
93
 
79
94
  ### Filter
data/lib/awsrm.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'erb'
1
2
  require 'awsrm/error'
2
3
  require 'awsrm/resource'
3
4
  require 'awsrm/resources/alb'
@@ -5,6 +6,7 @@ require 'awsrm/resources/alb_listener'
5
6
  require 'awsrm/resources/alb_target_group'
6
7
  require 'awsrm/resources/autoscaling_group'
7
8
  require 'awsrm/resources/ec2'
9
+ require 'awsrm/resources/elb'
8
10
  require 'awsrm/resources/route_table'
9
11
  require 'awsrm/resources/subnet'
10
12
  require 'awsrm/resources/vpc'
@@ -43,7 +43,7 @@ module Awsrm
43
43
 
44
44
  def one(params)
45
45
  res = all(params)
46
- res.first if check_one(res)
46
+ res.first if check_one(res, params)
47
47
  end
48
48
 
49
49
  def all(_params)
@@ -58,7 +58,7 @@ module Awsrm
58
58
  end
59
59
  end
60
60
 
61
- def check_one(resources)
61
+ def check_one(resources, params)
62
62
  raise Awsrm::NoResourceError, "No resource #{name} by #{params}" if resources.count == 0
63
63
  raise Awsrm::DuplicatedResourceError, "Duplicated resource #{name} by #{params}" if resources.count > 1
64
64
  true
@@ -14,7 +14,10 @@ module Awsrm
14
14
  lbs = elbv2_client.describe_load_balancers.map do |responce|
15
15
  responce.load_balancers
16
16
  end.flatten
17
- lbs.map do |lb|
17
+ albs = lbs.select do |lb|
18
+ lb.type == 'application'
19
+ end
20
+ albs.map do |lb|
18
21
  ret = params.all? do |key, value|
19
22
  raise UndefinedFilterParamError, key unless self::FILTER_MAP.key?(key)
20
23
  next self::FILTER_MAP[key].call(lb, value) if self::FILTER_MAP[key].is_a?(Proc)
@@ -24,7 +27,9 @@ module Awsrm
24
27
  end.compact
25
28
  end
26
29
 
27
- def filters(params) end
30
+ def filters(_params)
31
+ raise NoMethodError
32
+ end
28
33
 
29
34
  def has_tags?(arn, tag_hash)
30
35
  tag_descriptions = elbv2_client.describe_tags(resource_arns: [arn]).tag_descriptions.flatten
@@ -24,7 +24,9 @@ module Awsrm
24
24
  end
25
25
  end
26
26
 
27
- def filters(params) end
27
+ def filters(_params)
28
+ raise NoMethodError
29
+ end
28
30
  end
29
31
  end
30
32
 
@@ -23,7 +23,9 @@ module Awsrm
23
23
  end.compact
24
24
  end
25
25
 
26
- def filters(params) end
26
+ def filters(_params)
27
+ raise NoMethodError
28
+ end
27
29
  end
28
30
  end
29
31
 
@@ -6,6 +6,10 @@ module Awsrm
6
6
  name: 'tag:Name',
7
7
  vpc_id: 'vpc-id',
8
8
  vpc: ->(value) { { name: 'vpc-id', values: [Awsrm::Vpc.one(name: value).id] } },
9
+ elb: ->(value) do
10
+ { name: 'instance-id',
11
+ values: Awsrm::Elb.one(name: value).instances.map { |i| i.instance_id } }
12
+ end,
9
13
  alb_target_group: ->(value) do
10
14
  { name: 'instance-id',
11
15
  values: Awsrm::AlbTargetGroup.one(name: value).instance_ids }
@@ -0,0 +1,50 @@
1
+ module Awsrm
2
+ class Elb < Awsrm::Resource
3
+ FILTER_MAP = {
4
+ id: 'load_balancer_name',
5
+ name: 'load_balancer_name',
6
+ dns_name: 'dns_name',
7
+ tags: ->(lb, value) { Elb.has_tags?(lb.load_balancer_name, value) },
8
+ vpc: ->(lb, value) { lb.vpc_id == Awsrm::Vpc.one(name: value).id }
9
+ }.freeze
10
+
11
+ class << self
12
+ def all(params)
13
+ elbs = elb_client.describe_load_balancers.map do |responce|
14
+ responce.load_balancer_descriptions
15
+ end.flatten
16
+ elbs.map do |lb|
17
+ ret = params.all? do |key, value|
18
+ raise UndefinedFilterParamError, key unless self::FILTER_MAP.key?(key)
19
+ next self::FILTER_MAP[key].call(lb, value) if self::FILTER_MAP[key].is_a?(Proc)
20
+ lb[self::FILTER_MAP[key]] == value
21
+ end
22
+ ElbReader.new(lb) if ret
23
+ end.compact
24
+ end
25
+
26
+ def filters(_params)
27
+ raise NoMethodError
28
+ end
29
+
30
+ def has_tags?(name, tag_hash)
31
+ tag_descriptions = elb_client.describe_tags(load_balancer_names: [name]).tag_descriptions.flatten
32
+ ret = tag_descriptions.find do |desc|
33
+ desc.load_balancer_name == name
34
+ end
35
+ return false if ret.nil?
36
+ tag_hash.all? do |key, value|
37
+ ret.tags.any? do |tag|
38
+ tag.key == key.to_s && tag.value == value.to_s
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ class ElbReader < Awsrm::ResourceReader
46
+ def id
47
+ @resource.load_balancer_name
48
+ end
49
+ end
50
+ end
data/lib/awsrm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Awsrm
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-07 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: 0.47.0
95
+ version: 0.49.0
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: 0.47.0
102
+ version: 0.49.0
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: octorelease
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +185,7 @@ files:
185
185
  - lib/awsrm/resources/alb_target_group.rb
186
186
  - lib/awsrm/resources/autoscaling_group.rb
187
187
  - lib/awsrm/resources/ec2.rb
188
+ - lib/awsrm/resources/elb.rb
188
189
  - lib/awsrm/resources/route_table.rb
189
190
  - lib/awsrm/resources/subnet.rb
190
191
  - lib/awsrm/resources/vpc.rb
@@ -211,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
212
  version: '0'
212
213
  requirements: []
213
214
  rubyforge_project:
214
- rubygems_version: 2.6.12
215
+ rubygems_version: 2.6.13
215
216
  signing_key:
216
217
  specification_version: 4
217
218
  summary: Simple AWS Resource "READONLY" Mapper for awspec.