Class: ApartmentAcmeClient::Verifier

Inherits:
Object
  • Object
show all
Defined in:
app/models/apartment_acme_client/verifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Verifier

Returns a new instance of Verifier.



7
8
9
10
# File 'app/models/apartment_acme_client/verifier.rb', line 7

def initialize(url)
  @url = url
  @verify_over_https = ApartmentAcmeClient.verify_over_https ? true : false
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'app/models/apartment_acme_client/verifier.rb', line 5

def url
  @url
end

Instance Method Details

#properly_configured?Boolean

Determine whether this alias is properly configured Causes makes a request to a remote server (which should be THIS server) and determines whether the request was properly received

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/apartment_acme_client/verifier.rb', line 15

def properly_configured?
  options = {
    open_timeout: 5,
    use_ssl: @verify_over_https,
    verify_mode: OpenSSL::SSL::VERIFY_NONE # because we might not have a valid cert yet
  }
  Net::HTTP.start(url, options) do |http|
    # Because the engine could be mounted anywhere, we need to get the target
    # path from the Engine Routes
    verify_path = ApartmentAcmeClient::Engine.routes.url_helpers.verify_path
    response = http.get(verify_path)

    return false unless response.is_a?(Net::HTTPSuccess)

    response.body == "TRUE"
  end
rescue SocketError, Net::OpenTimeout, Errno::ECONNREFUSED
  # SocketError if the server name doesn't exist in DNS
  # OpenTimeout if no server responds
  # ECONNREFUSED if the server responds with "No"
  false
end