Sha256: 7565bdd084af305f9e43d2e99ea546d9deca210c94821c770a35f8e75094ef02

Contents?: true

Size: 1.62 KB

Versions: 27

Compression:

Stored size: 1.62 KB

Contents

module Awspec::Helper
  module Finder
    module Nlb
      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
        return nil
      end

      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

      def find_nlb_listener(arn)
        res = elbv2_client.describe_listeners({ listener_arns: [arn] })
        res.listeners.single_resource(arn)
      rescue
        return nil
      end

      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
        # Prefer the HTTP/HTTPS protocol target group, but survive without it:
        begin
          res.target_groups.single_resource(id)
        rescue
          return nil
        end
      end

      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
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
awspec-1.12.7 lib/awspec/helper/finder/nlb.rb
awspec-1.12.6 lib/awspec/helper/finder/nlb.rb
awspec-1.12.5 lib/awspec/helper/finder/nlb.rb
awspec-1.12.4 lib/awspec/helper/finder/nlb.rb
awspec-1.12.3 lib/awspec/helper/finder/nlb.rb
awspec-1.12.2 lib/awspec/helper/finder/nlb.rb
awspec-1.12.1 lib/awspec/helper/finder/nlb.rb
awspec-1.12.0 lib/awspec/helper/finder/nlb.rb
awspec-1.11.1 lib/awspec/helper/finder/nlb.rb
awspec-1.11.0 lib/awspec/helper/finder/nlb.rb
awspec-1.10.0 lib/awspec/helper/finder/nlb.rb
awspec-1.9.0 lib/awspec/helper/finder/nlb.rb
awspec-1.8.0 lib/awspec/helper/finder/nlb.rb
awspec-1.7.0 lib/awspec/helper/finder/nlb.rb
awspec-1.6.1 lib/awspec/helper/finder/nlb.rb
awspec-1.6.0 lib/awspec/helper/finder/nlb.rb
awspec-1.5.4 lib/awspec/helper/finder/nlb.rb
awspec-1.5.3 lib/awspec/helper/finder/nlb.rb
awspec-1.5.2 lib/awspec/helper/finder/nlb.rb
awspec-1.5.1 lib/awspec/helper/finder/nlb.rb