Class: VagrantPlugins::AwsDns::Action::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-aws-dns/action/base.rb

Direct Known Subclasses

AddRecord, RemoveRecord

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/vagrant-aws-dns/action/base.rb', line 10

def initialize(app, env)
  @app = app
  @machine = env[:machine]
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-aws-dns/action/base.rb', line 15

def call(env)
  return @app.call(env) if @machine.config.dns.record_sets.nil?

  @aws = AwsDns::Util::AwsUtil.new(@machine.provider_config.access_key_id,
                                   @machine.provider_config.secret_access_key,
                                   @machine.provider_config.region)
  public_ip = @aws.get_public_ip(@machine.id)
  private_ip = @aws.get_private_ip(@machine.id)

  @machine.config.dns.record_sets.each do |record_set|
    hosted_zone_id, record, type, value = record_set

    if @aws.is_private_zone(hosted_zone_id)
       yield hosted_zone_id, record, type, value || private_ip  if block_given?
    else
       yield hosted_zone_id, record, type, value || public_ip  if block_given?
    end
  end

  @app.call(env)
end