Class: Awful::Route53

Inherits:
Cli
  • Object
show all
Defined in:
lib/awful/route53.rb

Instance Method Summary collapse

Methods inherited from Cli

#initialize

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#dump(name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/awful/route53.rb', line 79

def dump(name)
  zone = name.split('.').last(2).join('.')
  params = {
    hosted_zone_id:    get_zone_by_name(zone),
    start_record_name: name,
    start_record_type: options[:type],
    max_items:         options[:max_items]
  }
  route53.list_resource_record_sets(params).resource_record_sets.tap do |records|
    records.each do |record|
      puts YAML.dump(stringify_keys(record.to_hash))
    end
  end
end

#ls(name = /./) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/awful/route53.rb', line 33

def ls(name = /./)
  route53.list_hosted_zones.hosted_zones.select do |zone|
    zone.name.match(name)
  end.tap do |list|
    if options[:long]
      print_table list.map { |z| [z.name, z.id, z.resource_record_set_count, z.config.comment] }
    else
      puts list.map(&:name)
    end
  end
end

#records(zone) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/awful/route53.rb', line 50

def records(zone)
  ## match on given record types
  include_type = options[:type] ? ->(type) { options[:type].include?(type) } : ->(_) { true }

  ## match on given record names
  names = options.fetch('name', []).map { |name| name.gsub(/([^\.])$/, '\1.') } # append . to names if missing
  include_name = options[:name] ? ->(name) { names.include?(name) } : ->(_) { true }

  route53.list_resource_record_sets(
    hosted_zone_id: get_zone_by_name(zone),
    max_items:      options[:max_items]
  ).resource_record_sets.select do |rrset|
    include_type.call(rrset.type) and include_name.call(rrset.name)
  end.tap do |records|
    if options[:long]
      print_table records.map { |r|
        dns_name = r.alias_target.nil? ? [] : ['ALIAS ' + r.alias_target.dns_name]
        values = r.resource_records.map(&:value)
        [r.name, r.type, (dns_name + values).join(', ')]
      }
    else
      puts records.map(&:name)
    end
  end
end