Class: Encryptbot::Services::Route53

Inherits:
Object
  • Object
show all
Defined in:
lib/encryptbot/services/route53.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, dns_entry) ⇒ Route53

Returns a new instance of Route53.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/encryptbot/services/route53.rb', line 10

def initialize(domain, dns_entry)
  @dns_entry = dns_entry
  @hosted_zone_id = Encryptbot.configuration.route53_hosted_zone_id
  @acme_name = Encryptbot.configuration.route53_acme_record_name
  @client = Aws::Route53::Client.new({
    region: "global",
    credentials: Aws::Credentials.new(
      Encryptbot.configuration.route53_access_key_id,
      Encryptbot.configuration.route53_secret_access_key
  )})
end

Instance Attribute Details

#aws_acme_record_nameObject

Returns the value of attribute aws_acme_record_name.



8
9
10
# File 'lib/encryptbot/services/route53.rb', line 8

def aws_acme_record_name
  @aws_acme_record_name
end

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/encryptbot/services/route53.rb', line 8

def client
  @client
end

#dns_entryObject

Returns the value of attribute dns_entry.



8
9
10
# File 'lib/encryptbot/services/route53.rb', line 8

def dns_entry
  @dns_entry
end

#domainObject

Returns the value of attribute domain.



8
9
10
# File 'lib/encryptbot/services/route53.rb', line 8

def domain
  @domain
end

#hosted_zone_idObject

Returns the value of attribute hosted_zone_id.



8
9
10
# File 'lib/encryptbot/services/route53.rb', line 8

def hosted_zone_id
  @hosted_zone_id
end

Instance Method Details

#add_challengeObject



22
23
24
25
26
27
28
29
30
31
32
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/encryptbot/services/route53.rb', line 22

def add_challenge
  begin
    response = @client.change_resource_record_sets({
      change_batch: {
        changes: [
          action: "UPSERT",
          resource_record_set: {
            name: @acme_name,
            resource_records: [
              {
                value: "\"#{@dns_entry[:content]}\"",
              },
            ],
            ttl: 0,
            type: "TXT",
          }
        ],
        comment: "ACME Challege update",
      },
      hosted_zone_id: @hosted_zone_id
    })
    change_id = response.change_info.id
    change_status = response.change_info.status
    while change_status == "PENDING"
      sleep(10)
      change_status = @client.get_change({id: change_id}).change_info.status
    end
    change_status == "INSYNC"

  rescue => e
    raise Encryptbot::Error::Route53DNSError, e
  end

end