Class: Dev::Aws::Route53

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/aws/route53.rb

Overview

Class for performing Route53 functions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domains = nil) ⇒ Route53

Returns a new instance of Route53.



9
10
11
12
# File 'lib/firespring_dev_commands/aws/route53.rb', line 9

def initialize(domains = nil)
  @client = ::Aws::Route53::Client.new
  @domains = Array(domains || [])
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/firespring_dev_commands/aws/route53.rb', line 7

def client
  @client
end

Instance Method Details

#activate_query_logging(log_group) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/firespring_dev_commands/aws/route53.rb', line 104

def activate_query_logging(log_group)
  zones do |zone|
    response = client.create_query_logging_config(
      hosted_zone_id: zone.id,
      cloud_watch_logs_log_group_arn: log_group
    )
    puts format('%-50s => %s', zone.id, response.location)
  rescue ::Aws::Route53::Errors::Throttling
    sleep(1)
    retry
  rescue ::Aws::Route53::Errors::ServiceError => e
    raise "Error: #{e.message}" unless e.instance_of?(::Aws::Route53::Errors::QueryLoggingConfigAlreadyExists)

    puts format('%-50s => %s', zone.id, e.message)
  end
end

#deactivate_query_loggingObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/firespring_dev_commands/aws/route53.rb', line 121

def deactivate_query_logging
  zones do |zone|
    target_config_id = target_config_id(zone.id)
    if target_config_id
      client.delete_query_logging_config(
        id: target_config_id
      )
      puts format('%-50s => %s', zone.id, 'Query logging config removed.'.colorize(:green))
    else
      puts format('%-50s => %s', zone.id, 'No query logging config assigned.'.colorize(:red))
    end
  rescue ::Aws::Route53::Errors::Throttling
    sleep(1)
    retry
  end
end

#list_query_configsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/firespring_dev_commands/aws/route53.rb', line 89

def list_query_configs
  zones do |zone|
    target_config_id = target_config_id(zone.id)
    message = if target_config_id
                "Config\t=>\t#{target_config_id}".colorize(:green)
              else
                'No query logging config assigned.'.colorize(:red)
              end
    puts format('%-50s => %s', zone.name, message)
  rescue ::Aws::Route53::Errors::Throttling
    sleep(1)
    retry
  end
end

#list_zone_detailsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/firespring_dev_commands/aws/route53.rb', line 70

def list_zone_details
  zones do |zone|
    puts
    zone_details, delegation_set = details(zone.id)
    dns_resource = Dev::Dns::Resource.new(zone_details.name)

    puts "#{zone_details.name.chomp('.').light_white} (#{zone_details.id}):"
    puts format('  %-50s %s', 'Delegation Set:', delegation_set.id)
    puts format('  %-50s %s', 'Delegation Defined Nameservers:', delegation_set.name_servers.sort.join(', '))
    puts format('  %-50s %s', 'DNS Reported Nameservers:', dns_resource.recursive_nameserver_lookup.sort.join(', '))
    puts format('  %-50s %s', 'DNS Reported Nameserver IPs:', dns_resource.recursive_nameserver_lookup.sort.map { |it| dns_resource.recursive_a_lookup(it) }.join(', '))
    puts format('  %-50s %s', 'Domain Apex IP Resolution:', dns_resource.recursive_a_lookup.sort.join(', '))
  rescue ::Aws::Route53::Errors::Throttling
    sleep(1)
    retry
  end
  puts
end

#zonesObject



14
15
16
17
18
19
20
# File 'lib/firespring_dev_commands/aws/route53.rb', line 14

def zones(&)
  if @domains.empty?
    each_zone(&)
  else
    each_zone_by_domains(&)
  end
end