Module: Certman::Resource::Route53

Included in:
Client
Defined in:
lib/certman/resource/route53.rb

Overview

rubocop:disable Metrics/ModuleLength

Instance Method Summary collapse

Instance Method Details

#check_hosted_zoneObject



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/certman/resource/route53.rb', line 105

def check_hosted_zone
  root_domain = PublicSuffix.domain(@domain)
  @hosted_zone_id = nil
  hosted_zone = route53.list_hosted_zones.hosted_zones.find do |zone|
    if PublicSuffix.domain(zone.name) == root_domain
      @hosted_zone_id = zone.id
      next true
    end
  end
  raise "Hosted Zone #{root_domain} does not exist" unless hosted_zone
end

#check_mx_rsetObject



126
127
128
129
130
131
132
133
# File 'lib/certman/resource/route53.rb', line 126

def check_mx_rset
  res = route53.test_dns_answer(
    hosted_zone_id: @hosted_zone_id,
    record_name: "#{@domain}.",
    record_type: 'MX'
  )
  raise "#{@domain} MX already exist" unless res.record_data.empty?
end

#check_txt_rsetObject



117
118
119
120
121
122
123
124
# File 'lib/certman/resource/route53.rb', line 117

def check_txt_rset
  res = route53.test_dns_answer(
    hosted_zone_id: @hosted_zone_id,
    record_name: "_amazonses.#{@domain}.",
    record_type: 'TXT'
  )
  raise "_amazonses.#{@domain} TXT already exist" unless res.record_data.empty?
end

#create_mx_rsetObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/certman/resource/route53.rb', line 33

def create_mx_rset
  route53.change_resource_record_sets(
    change_batch: {
      changes: [
        {
          action: 'CREATE',
          resource_record_set: {
            name: @domain,
            resource_records: [
              {
                value: "10 inbound-smtp.#{Aws.config[:region]}.amazonaws.com"
              }
            ],
            ttl: 60,
            type: 'MX'
          }
        }
      ],
      comment: 'Generate by certman'
    },
    hosted_zone_id: @hosted_zone.id
  )
end

#create_txt_rsetObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/certman/resource/route53.rb', line 5

def create_txt_rset
  root_domain = PublicSuffix.domain(@domain)
  @hosted_zone = route53.list_hosted_zones.hosted_zones.find do |zone|
    PublicSuffix.domain(zone.name) == root_domain
  end
  route53.change_resource_record_sets(
    change_batch: {
      changes: [
        {
          action: 'CREATE',
          resource_record_set: {
            name: "_amazonses.#{@domain}",
            resource_records: [
              {
                value: '"' + @token + '"'
              }
            ],
            ttl: 60,
            type: 'TXT'
          }
        }
      ],
      comment: 'Generate by certman'
    },
    hosted_zone_id: @hosted_zone.id
  )
end

#delete_mx_rsetObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/certman/resource/route53.rb', line 81

def delete_mx_rset
  route53.change_resource_record_sets(
    change_batch: {
      changes: [
        {
          action: 'DELETE',
          resource_record_set: {
            name: @domain,
            resource_records: [
              {
                value: "10 inbound-smtp.#{Aws.config[:region]}.amazonaws.com"
              }
            ],
            ttl: 60,
            type: 'MX'
          }
        }
      ],
      comment: 'Generate by certman'
    },
    hosted_zone_id: @hosted_zone.id
  )
end

#delete_txt_rsetObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/certman/resource/route53.rb', line 57

def delete_txt_rset
  route53.change_resource_record_sets(
    change_batch: {
      changes: [
        {
          action: 'DELETE',
          resource_record_set: {
            name: "_amazonses.#{@domain}",
            resource_records: [
              {
                value: '"' + @token + '"'
              }
            ],
            ttl: 60,
            type: 'TXT'
          }
        }
      ],
      comment: 'Generate by certman'
    },
    hosted_zone_id: @hosted_zone.id
  )
end

#route53Object



135
136
137
# File 'lib/certman/resource/route53.rb', line 135

def route53
  @route53 ||= Aws::Route53::Client.new
end