Module: Model::AcmeIdentifier
- Extended by:
- ActiveSupport::Concern
- Included in:
- Com::AcmeIdentifier
- Defined in:
- app/models/com/model/acme_identifier.rb
Instance Method Summary collapse
- #authorization ⇒ Object
- #auto_verify ⇒ Object
- #compute_wildcard ⇒ Object
- #deactivate ⇒ Object
- #dns_host ⇒ Object
- #dns_resolv ⇒ Object
- #dns_verify? ⇒ Boolean
-
#ensure_dns ⇒ Object
todo use aliyun temply.
- #file_verify? ⇒ Boolean
- #renew_dns_valid ⇒ Object
- #renew_file_valid ⇒ Object
- #save_auth(auth = authorization) ⇒ Object
Instance Method Details
#authorization ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'app/models/com/model/acme_identifier.rb', line 118 def auth = acme_order.order..find { |i| domain == i.domain && wildcard.present? == i.wildcard.present? } rescue Acme::Client::Error::BadNonce retry else save_auth(auth) auth end |
#auto_verify ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/models/com/model/acme_identifier.rb', line 76 def auto_verify if file_name.present? && file_content.present? file_verify? else dns_verify? end end |
#compute_wildcard ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/models/com/model/acme_identifier.rb', line 39 def compute_wildcard if identifier.start_with?('*.') self.wildcard = true self.domain = identifier.delete_prefix('*.') else self.domain = identifier end end |
#deactivate ⇒ Object
127 128 129 |
# File 'app/models/com/model/acme_identifier.rb', line 127 def deactivate acme_order.acme_account.client.(url: url) end |
#dns_host ⇒ Object
114 115 116 |
# File 'app/models/com/model/acme_identifier.rb', line 114 def dns_host "#{record_name}.#{domain}" end |
#dns_resolv ⇒ Object
56 57 58 59 60 61 |
# File 'app/models/com/model/acme_identifier.rb', line 56 def dns_resolv Resolv::DNS.open do |dns| records = dns.getresources dns_host, Resolv::DNS::Resource::IN::TXT records.map!(&:data) end end |
#dns_verify? ⇒ Boolean
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/com/model/acme_identifier.rb', line 63 def dns_verify? unless dns_resolv.include?(record_content) ensure_dns end auth = auth.dns.request_validation if auth.reload && auth.status == 'valid' self.update dns_valid: true, status: 'valid' end dns_valid end |
#ensure_dns ⇒ Object
todo use aliyun temply
49 50 51 52 53 54 |
# File 'app/models/com/model/acme_identifier.rb', line 49 def ensure_dns r = AliDns.add_acme_record domain, record_content if r['RecordId'] AliDns.check_record(domain, record_content) end end |
#file_verify? ⇒ Boolean
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/models/com/model/acme_identifier.rb', line 84 def file_verify? file_path = Rails.root.join('public', file_name) unless file_path.file? && file_path.read == file_content file_path.dirname.exist? || file_path.dirname.mkpath File.open(file_path, 'w') do |f| f.write file_content end end auth = auth.http.request_validation if auth.reload && auth.status == 'valid' self.update file_valid: true, status: 'valid' end file_valid end |
#renew_dns_valid ⇒ Object
31 32 33 |
# File 'app/models/com/model/acme_identifier.rb', line 31 def renew_dns_valid self.dns_valid = false end |
#renew_file_valid ⇒ Object
35 36 37 |
# File 'app/models/com/model/acme_identifier.rb', line 35 def renew_file_valid self.file_valid = false end |
#save_auth(auth = authorization) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/com/model/acme_identifier.rb', line 103 def save_auth(auth = ) update( record_name: auth.dns&.record_name, record_content: auth.dns&.record_content, file_name: auth.http&.filename, file_content: auth.http&.file_content, url: auth.url, status: auth.status ) end |