class AwsUtils::Route53ListResourceRecord
Public Class Methods
new()
click to toggle source
# File lib/awsutils/r53ls.rb, line 32 def initialize @opts = parse_opts end
Public Instance Methods
apex?()
click to toggle source
# File lib/awsutils/r53ls.rb, line 28 def apex? @opts[:name].split('.')[-3].nil? ? true : false end
connection()
click to toggle source
# File lib/awsutils/r53ls.rb, line 8 def connection @connection ||= Fog::DNS::AWS.new end
display_record(record)
click to toggle source
# File lib/awsutils/r53ls.rb, line 36 def display_record(record) if @opts[:format] == 'json' puts JSON.pretty_generate(zone_to_json([record]).first) else puts 'Name: ' + record.name puts 'Type: ' + record.type puts 'TTL: ' + record.ttl puts record.value.count < 2 ? 'Value:' : 'Values:' record.value.each { |rr| puts " #{rr}" } end end
list_all()
click to toggle source
# File lib/awsutils/r53ls.rb, line 76 def list_all if @opts[:format] == 'json' puts JSON.pretty_generate(zone_to_json(zone.records)) else print_table end end
parse_opts()
click to toggle source
# File lib/awsutils/r53ls.rb, line 12 def parse_opts opts = Optimist.options do opt :format, 'Output format', default: 'table' end opts[:name] = ARGV.last opts end
print_table()
click to toggle source
# File lib/awsutils/r53ls.rb, line 64 def print_table zone.records.each do |r| printf( "%-40s%-8s%-8s%-40s\n", r.name, r.type, r.ttl, r.value.join(' ') ) end end
record_by_name()
click to toggle source
# File lib/awsutils/r53ls.rb, line 48 def record_by_name name = @opts[:name].split('.').join('.') + '.' zone.records.find { |r| r.name == name } end
run()
click to toggle source
# File lib/awsutils/r53ls.rb, line 84 def run if apex? list_all else display_record(record_by_name) end end
zone()
click to toggle source
# File lib/awsutils/r53ls.rb, line 20 def zone @zone ||= connection.zones.all('domain' => zone_name).first end
zone_name()
click to toggle source
# File lib/awsutils/r53ls.rb, line 24 def zone_name @zone_name ||= @opts[:name].split('.')[-2..-1].join('.') + '.' end
zone_to_json(zone_records)
click to toggle source
# File lib/awsutils/r53ls.rb, line 53 def zone_to_json(zone_records) zone_records.map do |r| { 'name' => r.name, 'type' => r.type, 'ttl' => r.ttl, 'value' => r.value } end end