lib/acme/client/resources/directory.rb in acme-client-2.0.15 vs lib/acme/client/resources/directory.rb in acme-client-2.0.16
- old
+ new
@@ -15,16 +15,17 @@
website: 'website',
caa_identities: 'caaIdentities',
external_account_required: 'externalAccountRequired'
}
- def initialize(url, connection_options)
- @url, @connection_options = url, connection_options
+ def initialize(client, **arguments)
+ @client = client
+ assign_attributes(**arguments)
end
def endpoint_for(key)
- directory.fetch(key) do |missing_key|
+ @directory.fetch(key) do |missing_key|
raise Acme::Client::Error::UnsupportedOperation,
"Directory at #{@url} does not include `#{missing_key}`"
end
end
@@ -43,33 +44,18 @@
def external_account_required
meta[DIRECTORY_META[:external_account_required]]
end
def meta
- directory[:meta]
+ @directory[:meta]
end
private
- def directory
- @directory ||= load_directory
- end
-
- def load_directory
- body = fetch_directory
- result = {}
- result[:meta] = body.delete('meta')
+ def assign_attributes(directory:)
+ @directory = {}
+ @directory[:meta] = directory.delete('meta')
DIRECTORY_RESOURCES.each do |key, entry|
- result[key] = URI(body[entry]) if body[entry]
+ @directory[key] = URI(directory[entry]) if directory[entry]
end
- result
- rescue JSON::ParserError => exception
- raise Acme::Client::Error::InvalidDirectory,
- "Invalid directory url\n#{@directory} did not return a valid directory\n#{exception.inspect}"
- end
-
- def fetch_directory
- http_client = Acme::Client::HTTPClient.new_acme_connection(url: @directory, options: @connection_options, client: nil, mode: nil)
- response = http_client.get(@url)
- response.body
end
end