Class: Acme::Client
- Inherits:
-
Object
- Object
- Acme::Client
- Defined in:
- lib/acme/version.rb,
lib/acme/client.rb
Constant Summary collapse
- VERSION =
'0.1.0'
- DEFAULT_ENDPOINT =
'http://127.0.0.1:4000'
Instance Attribute Summary collapse
-
#nonces ⇒ Object
readonly
Returns the value of attribute nonces.
-
#operation_endpoints ⇒ Object
readonly
Returns the value of attribute operation_endpoints.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
Instance Method Summary collapse
- #authorize(domain:) ⇒ Object
- #connection ⇒ Object
-
#initialize(endpoint: DEFAULT_ENDPOINT, directory_uri: nil, private_key:) ⇒ Client
constructor
A new instance of Client.
- #load_directory! ⇒ Object
- #new_certificate(csr) ⇒ Object
- #register(contact:) ⇒ Object
Constructor Details
#initialize(endpoint: DEFAULT_ENDPOINT, directory_uri: nil, private_key:) ⇒ Client
Returns a new instance of Client.
4 5 6 7 8 |
# File 'lib/acme/client.rb', line 4 def initialize(endpoint: DEFAULT_ENDPOINT, directory_uri: nil, private_key:) @endpoint, @private_key, @directory_uri = endpoint, private_key, directory_uri @nonces ||= [] load_directory! end |
Instance Attribute Details
#nonces ⇒ Object (readonly)
Returns the value of attribute nonces.
10 11 12 |
# File 'lib/acme/client.rb', line 10 def nonces @nonces end |
#operation_endpoints ⇒ Object (readonly)
Returns the value of attribute operation_endpoints.
10 11 12 |
# File 'lib/acme/client.rb', line 10 def operation_endpoints @operation_endpoints end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
10 11 12 |
# File 'lib/acme/client.rb', line 10 def private_key @private_key end |
Instance Method Details
#authorize(domain:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/acme/client.rb', line 21 def (domain:) payload = { resource: "new-authz", identifier: { type: "dns", value: domain } } response = connection.post(@operation_endpoints.fetch('new-authz'), payload) ::Acme::Resources::Authorization.new(self, response) end |
#connection ⇒ Object
44 45 46 47 48 49 |
# File 'lib/acme/client.rb', line 44 def connection @connection ||= Faraday.new(@endpoint) do |configuration| configuration.use Acme::FaradayMiddleware, client: self configuration.adapter Faraday.default_adapter end end |
#load_directory! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/acme/client.rb', line 51 def load_directory! @operation_endpoints = if @directory_uri response = connection.get(@directory_uri) body = response.body { 'new-reg' => body.fetch('new-reg'), 'recover-reg' => body.fetch('recover-reg'), 'new-authz' => body.fetch('new-authz'), 'new-cert' => body.fetch('new-cert'), 'revoke-cert' => body.fetch('revoke-cert'), } else DIRECTORY_DEFAULT end end |
#new_certificate(csr) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/acme/client.rb', line 34 def new_certificate(csr) payload = { resource: 'new-cert', csr: UrlSafeBase64.encode64(csr.to_der) } response = connection.post(@operation_endpoints.fetch('new-cert'), payload) OpenSSL::X509::Certificate.new(response.body) end |
#register(contact:) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/acme/client.rb', line 12 def register(contact:) payload = { resource: 'new-reg', contact: Array.wrap(contact) } response = connection.post(@operation_endpoints.fetch('new-reg'), payload) ::Acme::Resources::Registration.new(self, response) end |