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) ⇒ Route53

Returns a new instance of Route53.



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

def initialize(domains)
  @client = ::Aws::Route53::Client.new
  @domains = domains
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/firespring_dev_commands/aws/route53.rb', line 5

def client
  @client
end

Instance Method Details

#activate_query_logging(log_group) ⇒ Object



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

def activate_query_logging(log_group)
  output = {}

  zones.each do |zone|
    response = client.create_query_logging_config(
      hosted_zone_id: zone.id,
      cloud_watch_logs_log_group_arn: log_group
    )
    output[zone.id] = response.location
  rescue ::Aws::Route53::Errors::ServiceError => e
    raise "Error: #{e.message}" unless e.instance_of?(::Aws::Route53::Errors::QueryLoggingConfigAlreadyExists)

    output[zone.id] = e.message
  end
  pretty_puts(output)
end

#deactivate_query_loggingObject



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

def deactivate_query_logging
  output = {}
  zones.each do |zone|
    target_config_id = target_config_id(zone.id)
    if target_config_id
      client.delete_query_logging_config(
        id: target_config_id
      )
      output[zone.id] = 'Query logging config removed.'.colorize(:green)
    else
      output[zone.id] = 'No query logging config assigned.'.colorize(:red)
    end
  end
  pretty_puts(output)
end

#list_query_configsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/firespring_dev_commands/aws/route53.rb', line 58

def list_query_configs
  output = {}
  zones.each do |zone|
    target_config_id = target_config_id(zone.id)

    output[zone.name] = if target_config_id
                          "Config\t=>\t#{target_config_id}".colorize(:green)
                        else
                          'No query logging config assigned.'.colorize(:red)
                        end
  end

  pretty_puts(output)
end