Class: Acme::Client
- Inherits:
-
Object
- Object
- Acme::Client
- Defined in:
- lib/acme/client.rb,
lib/acme/client.rb,
lib/acme/client/version.rb
Defined Under Namespace
Modules: Resources Classes: Certificate, CertificateRequest, Crypto, Error, FaradayMiddleware, SelfSignCertificate
Constant Summary collapse
- DEFAULT_ENDPOINT =
'http://127.0.0.1:4000'.freeze
- DIRECTORY_DEFAULT =
{ 'new-authz' => '/acme/new-authz', 'new-cert' => '/acme/new-cert', 'new-reg' => '/acme/new-reg', 'revoke-cert' => '/acme/revoke-cert' }.freeze
- VERSION =
'0.5.5'.freeze
Instance Attribute Summary collapse
-
#directory_uri ⇒ Object
readonly
Returns the value of attribute directory_uri.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #authorize(domain:) ⇒ Object
- #connection ⇒ Object
- #fetch_authorization(uri) ⇒ Object
-
#initialize(private_key:, endpoint: DEFAULT_ENDPOINT, directory_uri: nil, connection_options: {}) ⇒ Client
constructor
A new instance of Client.
- #new_certificate(csr) ⇒ Object
- #register(contact:) ⇒ Object
- #revoke_certificate(certificate) ⇒ Object
Constructor Details
#initialize(private_key:, endpoint: DEFAULT_ENDPOINT, directory_uri: nil, connection_options: {}) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 |
# File 'lib/acme/client.rb', line 32 def initialize(private_key:, endpoint: DEFAULT_ENDPOINT, directory_uri: nil, connection_options: {}) @endpoint, @private_key, @directory_uri, @connection_options = endpoint, private_key, directory_uri, @nonces ||= [] load_directory! end |
Instance Attribute Details
#directory_uri ⇒ Object (readonly)
Returns the value of attribute directory_uri.
38 39 40 |
# File 'lib/acme/client.rb', line 38 def directory_uri @directory_uri end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
38 39 40 |
# File 'lib/acme/client.rb', line 38 def endpoint @endpoint end |
#nonces ⇒ Object (readonly)
Returns the value of attribute nonces.
38 39 40 |
# File 'lib/acme/client.rb', line 38 def nonces @nonces end |
#operation_endpoints ⇒ Object (readonly)
Returns the value of attribute operation_endpoints.
38 39 40 |
# File 'lib/acme/client.rb', line 38 def operation_endpoints @operation_endpoints end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
38 39 40 |
# File 'lib/acme/client.rb', line 38 def private_key @private_key end |
Class Method Details
.revoke_certificate(certificate, *arguments) ⇒ Object
84 85 86 87 |
# File 'lib/acme/client.rb', line 84 def self.revoke_certificate(certificate, *arguments) client = new(*arguments) client.revoke_certificate(certificate) end |
Instance Method Details
#authorize(domain:) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/acme/client.rb', line 49 def (domain:) payload = { resource: 'new-authz', identifier: { type: 'dns', value: domain } } response = connection.post(@operation_endpoints.fetch('new-authz'), payload) ::Acme::Client::Resources::Authorization.new(self, response.headers['Location'], response) end |
#connection ⇒ Object
89 90 91 92 93 94 |
# File 'lib/acme/client.rb', line 89 def connection @connection ||= Faraday.new(@endpoint, **@connection_options) do |configuration| configuration.use Acme::Client::FaradayMiddleware, client: self configuration.adapter Faraday.default_adapter end end |
#fetch_authorization(uri) ⇒ Object
62 63 64 65 |
# File 'lib/acme/client.rb', line 62 def (uri) response = connection.get(uri) ::Acme::Client::Resources::Authorization.new(self, uri, response) end |
#new_certificate(csr) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/acme/client.rb', line 67 def new_certificate(csr) payload = { resource: 'new-cert', csr: Base64.urlsafe_encode64(csr.to_der) } response = connection.post(@operation_endpoints.fetch('new-cert'), payload) ::Acme::Client::Certificate.new(OpenSSL::X509::Certificate.new(response.body), response.headers['location'], fetch_chain(response), csr) end |
#register(contact:) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/acme/client.rb', line 40 def register(contact:) payload = { resource: 'new-reg', contact: Array(contact) } response = connection.post(@operation_endpoints.fetch('new-reg'), payload) ::Acme::Client::Resources::Registration.new(self, response) end |
#revoke_certificate(certificate) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/acme/client.rb', line 77 def revoke_certificate(certificate) payload = { resource: 'revoke-cert', certificate: Base64.urlsafe_encode64(certificate.to_der) } endpoint = @operation_endpoints.fetch('revoke-cert') response = connection.post(endpoint, payload) response.success? end |