class Applb::DSL::EC2::LoadBalancer::Listeners::Listener::Result

Constants

ATTRIBUTES

Public Class Methods

new(context, lb_name) click to toggle source
# File lib/applb/dsl/listener.rb, line 18
def initialize(context, lb_name)
  @context = context
  @options = context.options
  @lb_name = lb_name
end

Public Instance Methods

aws(aws_listener) click to toggle source
# File lib/applb/dsl/listener.rb, line 28
def aws(aws_listener)
  @aws_listener = aws_listener
  self
end
create() click to toggle source
# File lib/applb/dsl/listener.rb, line 33
def create
  Applb.logger.info("#{@lb_name} Create listener for port #{port}")
  return if @options[:dry_run]
  client.create_listener(create_option).listeners.first
end
modify() click to toggle source
# File lib/applb/dsl/listener.rb, line 39
def modify
  dsl_hash = to_diff_h
  aws_hash = to_diff_h_aws
  return if dsl_hash == aws_hash

  Applb.logger.info("#{@lb_name} Modify listener for port #{port}")
  Applb.logger.info("<diff>\n#{Applb::Utils.diff(aws_hash, dsl_hash, color: @options[:color])}")
  return if @options[:dry_run]

  client.modify_listener(modify_option).listeners.first
end
to_h() click to toggle source
# File lib/applb/dsl/listener.rb, line 24
def to_h
  Hash[ATTRIBUTES.sort.map { |name| [name, public_send(name)] }]
end

Private Instance Methods

client() click to toggle source
# File lib/applb/dsl/listener.rb, line 82
def client
  @client ||= Applb::ClientWrapper.new(@options)
end
create_option() click to toggle source
# File lib/applb/dsl/listener.rb, line 72
def create_option
  options = to_h.reject { |k, _| %i/policy_name rules/.include?(k) }
  options[:default_actions].first.delete(:target_group_name)
  options
end
modify_option() click to toggle source
# File lib/applb/dsl/listener.rb, line 78
def modify_option
  to_diff_h.merge(listener_arn: @aws_listener.listener_arn)
end
to_diff_h() click to toggle source
# File lib/applb/dsl/listener.rb, line 53
def to_diff_h
  options = Applb::Utils.normalize_hash(to_h)
  target_group_name = options[:default_actions].first.delete(:target_group_name)
  if options[:ssl_policy] && options[:ssl_policy].empty?
    options.delete(:certificates)
    options.delete(:ssl_policy)
  end
  options.reject! { |k, v| %i/listener_arn load_balancer_arn rules/.include?(k) }
end
to_diff_h_aws() click to toggle source
# File lib/applb/dsl/listener.rb, line 63
def to_diff_h_aws
  options = Applb::Utils.normalize_hash(@aws_listener.to_h)
  if options[:ssl_policy] && options[:ssl_policy].empty?
    options.delete(:certificates)
    options.delete(:ssl_policy)
  end
  options.reject! { |k, v| %i/listener_arn load_balancer_arn rules/.include?(k) }
end