lib/acme/client/resources/challenges/base.rb in acme-client-1.0.0 vs lib/acme/client/resources/challenges/base.rb in acme-client-2.0.0
- old
+ new
@@ -1,39 +1,43 @@
+# frozen_string_literal: true
+
class Acme::Client::Resources::Challenges::Base
- attr_reader :authorization, :status, :uri, :token, :error
+ attr_reader :status, :url, :token, :error
- def initialize(authorization)
- @authorization = authorization
+ def initialize(client, **arguments)
+ @client = client
+ assign_attributes(arguments)
end
- def client
- authorization.client
+ def challenge_type
+ self.class::CHALLENGE_TYPE
end
- def verify_status
- authorization.verify_status
+ def key_authorization
+ "#{token}.#{@client.jwk.thumbprint}"
+ end
- status
+ def reload
+ assign_attributes **@client.challenge(url: url).to_h
+ true
end
- def request_verification
- response = client.connection.post(@uri, resource: 'challenge', type: challenge_type, keyAuthorization: authorization_key)
- response.success?
+ def request_validation
+ assign_attributes **@client.request_challenge_validation(
+ url: url, key_authorization: key_authorization
+ ).to_h
+ true
end
- def assign_attributes(attributes)
- @status = attributes.fetch('status', 'pending')
- @uri = attributes.fetch('uri')
- @token = attributes.fetch('token')
- @error = attributes['error']
+ def to_h
+ { status: status, url: url, token: token, error: error }
end
private
- def challenge_type
- self.class::CHALLENGE_TYPE
- end
-
- def authorization_key
- "#{token}.#{client.jwk.thumbprint}"
+ def assign_attributes(status:, url:, token:, error: nil)
+ @status = status
+ @url = url
+ @token = token
+ @error = error
end
end