Class: AwsUtils::Route53ListResourceRecord
- Inherits:
-
Object
- Object
- AwsUtils::Route53ListResourceRecord
- Defined in:
- lib/awsutils/r53ls.rb
Instance Method Summary collapse
- #apex? ⇒ Boolean
- #connection ⇒ Object
- #display_record(record) ⇒ Object
-
#initialize ⇒ Route53ListResourceRecord
constructor
A new instance of Route53ListResourceRecord.
- #list_all ⇒ Object
- #parse_opts ⇒ Object
- #print_table ⇒ Object
- #record_by_name ⇒ Object
- #run ⇒ Object
- #zone ⇒ Object
- #zone_name ⇒ Object
- #zone_to_json(zone_records) ⇒ Object
Constructor Details
#initialize ⇒ Route53ListResourceRecord
Returns a new instance of Route53ListResourceRecord.
32 33 34 |
# File 'lib/awsutils/r53ls.rb', line 32 def initialize @opts = parse_opts end |
Instance Method Details
#apex? ⇒ Boolean
28 29 30 |
# File 'lib/awsutils/r53ls.rb', line 28 def apex? @opts[:name].split('.')[-3].nil? ? true : false end |
#connection ⇒ Object
8 9 10 |
# File 'lib/awsutils/r53ls.rb', line 8 def connection @connection ||= Fog::DNS::AWS.new end |
#display_record(record) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
76 77 78 79 80 81 82 |
# 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 ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/awsutils/r53ls.rb', line 12 def parse_opts opts = Optimist. do opt :format, 'Output format', default: 'table' end opts[:name] = ARGV.last opts end |
#print_table ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
48 49 50 51 |
# 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 ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/awsutils/r53ls.rb', line 84 def run if apex? list_all else display_record(record_by_name) end end |
#zone ⇒ Object
20 21 22 |
# File 'lib/awsutils/r53ls.rb', line 20 def zone @zone ||= connection.zones.all('domain' => zone_name).first end |
#zone_name ⇒ Object
24 25 26 |
# File 'lib/awsutils/r53ls.rb', line 24 def zone_name @zone_name ||= @opts[:name].split('.')[-2..-1].join('.') + '.' end |
#zone_to_json(zone_records) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# 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 |