Module: Awspec::Helper::Finder::Nlb
- Included in:
- Awspec::Helper::Finder
- Defined in:
- lib/awspec/helper/finder/nlb.rb
Instance Method Summary collapse
- #find_nlb(id) ⇒ Object
- #find_nlb_listener(arn) ⇒ Object
- #find_nlb_target_group(id) ⇒ Object
- #select_nlb_by_vpc_id(vpc_id) ⇒ Object
- #select_nlb_listener_by_nlb_arn(arn) ⇒ Object
- #select_rule_by_nlb_listener_id(id) ⇒ Object
Instance Method Details
#find_nlb(id) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/awspec/helper/finder/nlb.rb', line 6 def find_nlb(id) res = elbv2_client.describe_load_balancers({ names: [id] }) res.load_balancers.select do |lb| lb.type == 'network' end.single_resource(id) rescue StandardError nil end |
#find_nlb_listener(arn) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/awspec/helper/finder/nlb.rb', line 22 def find_nlb_listener(arn) res = elbv2_client.describe_listeners({ listener_arns: [arn] }) res.listeners.single_resource(arn) rescue StandardError nil end |
#find_nlb_target_group(id) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/awspec/helper/finder/nlb.rb', line 40 def find_nlb_target_group(id) res = elbv2_client.describe_target_groups({ names: [id] }) httpx_res = res.target_groups.select do |tg| %w[HTTP HTTPS].include?(tg.protocol) end if !httpx_res || httpx_res.empty? raise "ERROR: Found no HTTP nor HTTPS -protocol target group named '#{id}'." end httpx_res.single_resource(id) rescue StandardError # Prefer the HTTP/HTTPS protocol target group, but survive without it: begin res.target_groups.single_resource(id) rescue StandardError nil end end |
#select_nlb_by_vpc_id(vpc_id) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/awspec/helper/finder/nlb.rb', line 15 def select_nlb_by_vpc_id(vpc_id) res = elbv2_client.describe_load_balancers res.load_balancers.select do |lb| lb.vpc_id == vpc_id && lb.type == 'network' end end |
#select_nlb_listener_by_nlb_arn(arn) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/awspec/helper/finder/nlb.rb', line 29 def select_nlb_listener_by_nlb_arn(arn) selected = [] next_marker = nil loop do res = elbv2_client.describe_listeners({ marker: next_marker, load_balancer_arn: arn }) selected += res.listeners unless res.nil? (res.nil? && next_marker = res.next_marker) || break end selected end |
#select_rule_by_nlb_listener_id(id) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/awspec/helper/finder/nlb.rb', line 59 def select_rule_by_nlb_listener_id(id) selected = [] next_marker = nil loop do res = elbv2_client.describe_rules(marker: next_marker, listener_arn: id) selected += res.rules unless res.nil? (res.nil? && next_marker = res.next_marker) || break end selected end |