Class: Encryptbot::Services::Dyn
- Inherits:
-
Object
- Object
- Encryptbot::Services::Dyn
- Defined in:
- lib/encryptbot/services/dyn.rb
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#customer_name ⇒ Object
Returns the value of attribute customer_name.
-
#dns_entry ⇒ Object
Returns the value of attribute dns_entry.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#full_domain_name ⇒ Object
Returns the value of attribute full_domain_name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#add_challenge ⇒ Object
sign in check for txt record, update if already exists, otherwise create new one publish changes sign out.
- #add_dns_record ⇒ Object
- #find_dns_record ⇒ Object
-
#initialize(domain, dns_entry) ⇒ Dyn
constructor
A new instance of Dyn.
- #publish_changes ⇒ Object
- #setup_dns_record ⇒ Object
- #sign_in ⇒ Object
- #sign_out ⇒ Object
- #update_dns_record(txt_endpoint) ⇒ Object
Constructor Details
#initialize(domain, dns_entry) ⇒ Dyn
Returns a new instance of Dyn.
11 12 13 14 15 16 17 18 19 |
# File 'lib/encryptbot/services/dyn.rb', line 11 def initialize(domain, dns_entry) @domain = domain.to_s.gsub("*.", "") # cleanup wildcard by removing *. infront @dns_entry = dns_entry # {content: "txt-record-content", type: "TXT", name: "_acme-challenge.domain.com"} @full_domain_name = "#{dns_entry[:name]}.#{@domain}" @api_token = nil @customer_name = Encryptbot.configuration.dyn_customer_name @username = Encryptbot.configuration.dyn_username @password = Encryptbot.configuration.dyn_password end |
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
9 10 11 |
# File 'lib/encryptbot/services/dyn.rb', line 9 def api_token @api_token end |
#customer_name ⇒ Object
Returns the value of attribute customer_name.
9 10 11 |
# File 'lib/encryptbot/services/dyn.rb', line 9 def customer_name @customer_name end |
#dns_entry ⇒ Object
Returns the value of attribute dns_entry.
9 10 11 |
# File 'lib/encryptbot/services/dyn.rb', line 9 def dns_entry @dns_entry end |
#domain ⇒ Object
Returns the value of attribute domain.
9 10 11 |
# File 'lib/encryptbot/services/dyn.rb', line 9 def domain @domain end |
#full_domain_name ⇒ Object
Returns the value of attribute full_domain_name.
9 10 11 |
# File 'lib/encryptbot/services/dyn.rb', line 9 def full_domain_name @full_domain_name end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/encryptbot/services/dyn.rb', line 9 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/encryptbot/services/dyn.rb', line 9 def username @username end |
Instance Method Details
#add_challenge ⇒ Object
sign in check for txt record, update if already exists, otherwise create new one publish changes sign out
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/encryptbot/services/dyn.rb', line 25 def add_challenge begin sign_in success = setup_dns_record sign_out success rescue => e raise Encryptbot::Error::DynDNSError, e end end |
#add_dns_record ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/encryptbot/services/dyn.rb', line 73 def add_dns_record response = post("/REST/TXTRecord/#{domain}/#{full_domain_name}/", { rdata: { txtdata: dns_entry[:content] }, ttl: "30" }) if response && response["status"] == "success" return publish_changes end false end |
#find_dns_record ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/encryptbot/services/dyn.rb', line 65 def find_dns_record response = get("/REST/TXTRecord/#{domain}/#{full_domain_name}/") if response && response["status"] == "success" return response["data"][0] end nil end |
#publish_changes ⇒ Object
99 100 101 102 |
# File 'lib/encryptbot/services/dyn.rb', line 99 def publish_changes response = put("/REST/Zone/#{domain}/", {publish: true}) response && response["status"] == "success" end |
#setup_dns_record ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/encryptbot/services/dyn.rb', line 55 def setup_dns_record txt_endpoint = find_dns_record if txt_endpoint update_dns_record(txt_endpoint) else add_dns_record end end |
#sign_in ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/encryptbot/services/dyn.rb', line 37 def sign_in response = post("/REST/Session/", { customer_name: customer_name, user_name: username, password: password }) if response && response["status"] == "success" @api_token = response["data"]["token"] end if @api_token.nil? raise Encryptbot::Error::DynDNSError, "Unable to get Dyn API Token" end end |
#sign_out ⇒ Object
51 52 53 |
# File 'lib/encryptbot/services/dyn.rb', line 51 def sign_out response = delete("/REST/Session/") end |
#update_dns_record(txt_endpoint) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/encryptbot/services/dyn.rb', line 86 def update_dns_record(txt_endpoint) response = put(txt_endpoint, { rdata: { txtdata: dns_entry[:content] }, ttl: "30" }) if response && response["status"] == "success" return publish_changes end false end |