Module: Dnsimple::Client::Certificates

Included in:
CertificatesService
Defined in:
lib/dnsimple/client/certificates.rb

Instance Method Summary collapse

Instance Method Details

#all_certificates(account_id, domain_name, options = {}) ⇒ Dnsimple::CollectionResponse<Dnsimple::Struct::Certificate>

List ALL the certificates for the domain in the account.

This method is similar to #certificates, but instead of returning the results of a specific page it iterates all the pages and returns the entire collection.

Please use this method carefully, as fetching the entire collection will increase the number of requests you send to the API server and you may eventually risk to hit the throttle limit.

Parameters:

  • account_id (Integer)

    the account ID

  • domain_name (#to_s)

    The domain ID or domain name

  • options (Hash) (defaults to: {})

    the filtering and sorting option

Options Hash (options):

  • :page (Integer)

    current page (pagination)

  • :per_page (Integer)

    number of entries to return (pagination)

  • :sort (String)

    sorting policy

Returns:

Raises:

See Also:



56
57
58
# File 'lib/dnsimple/client/certificates.rb', line 56

def all_certificates(, domain_name, options = {})
  paginate(:certificates, , domain_name, options)
end

#certificate(account_id, domain_id, certificate_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Certificate>

Get the details of a certificate.

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

  • certificate_id (Integer)

    the certificate ID

  • options (Hash) (defaults to: {})

Returns:

Raises:

See Also:



72
73
74
75
76
# File 'lib/dnsimple/client/certificates.rb', line 72

def certificate(, domain_id, certificate_id, options = {})
  response = client.get(Client.versioned("/%s/domains/%s/certificates/%s" % [, domain_id, certificate_id]), options)

  Dnsimple::Response.new(response, Struct::Certificate.new(response["data"]))
end

#certificate_private_key(account_id, domain_id, certificate_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::CertificateBundle>

Get the PEM-encoded certificate private key.

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

  • certificate_id (Integer)

    the certificate ID

  • options (Hash) (defaults to: {})

Returns:

Raises:

See Also:



108
109
110
111
112
# File 'lib/dnsimple/client/certificates.rb', line 108

def certificate_private_key(, domain_id, certificate_id, options = {})
  response = client.get(Client.versioned("/%s/domains/%s/certificates/%s/private_key" % [, domain_id, certificate_id]), options)

  Dnsimple::Response.new(response, Struct::CertificateBundle.new(response["data"]))
end

#certificates(account_id, domain_name, options = {}) ⇒ Dnsimple::PaginatedResponse<Dnsimple::Struct::Certificate> Also known as: list_certificates

List the certificates for the domain in the account.

Examples:

List certificates in the first page

client.certificates.list(1010, "example.com")

List certificates, provide a specific page

client.certificates.list(1010, "example.com", page: 2)

List certificates, provide a sorting policy

client.certificates.list(1010, "example.com", sort: "email:asc")

Parameters:

  • account_id (Integer)

    the account ID

  • domain_name (#to_s)

    The domain ID or domain name

  • options (Hash) (defaults to: {})

    the filtering and sorting options

Options Hash (options):

  • :page (Integer)

    current page (pagination)

  • :per_page (Integer)

    number of entries to return (pagination)

Returns:

Raises:

See Also:



29
30
31
32
33
# File 'lib/dnsimple/client/certificates.rb', line 29

def certificates(, domain_name, options = {})
  response = client.get(Client.versioned("/%s/domains/%s/certificates" % [, domain_name]), Options::ListOptions.new(options))

  Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Certificate.new(r) })
end

#download_certificate(account_id, domain_id, certificate_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::CertificateBundle>

Get the PEM-encoded certificate, along with the root certificate and intermediate chain.

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

  • certificate_id (Integer)

    the certificate ID

  • options (Hash) (defaults to: {})

Returns:

Raises:

See Also:



90
91
92
93
94
# File 'lib/dnsimple/client/certificates.rb', line 90

def download_certificate(, domain_id, certificate_id, options = {})
  response = client.get(Client.versioned("/%s/domains/%s/certificates/%s/download" % [, domain_id, certificate_id]), options)

  Dnsimple::Response.new(response, Struct::CertificateBundle.new(response["data"]))
end

#issue_letsencrypt_certificate(account_id, domain_id, certificate_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Certificate>

Issue a pending Let’s Encrypt certificate order.

Note that the issuance process is async. A successful response means the issuance request has been successfully acknowledged and queued for processing.

Examples:

Basic usage

reponse     = client.certificates.issue_letsencrypt_certificate(1010, "example.com", 100)
certificate = response.data

certificate.state # => "requesting"

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

  • certificate_id (Integer)

    the certificate ID returned by the purchase method

  • options (Hash) (defaults to: {})

Returns:

Raises:

See Also:



207
208
209
210
211
# File 'lib/dnsimple/client/certificates.rb', line 207

def issue_letsencrypt_certificate(, domain_id, certificate_id, options = {})
  response = client.post(Client.versioned("/%s/domains/%s/certificates/letsencrypt/%s/issue" % [, domain_id, certificate_id]), options)

  Dnsimple::Response.new(response, Struct::Certificate.new(response["data"]))
end

#issue_letsencrypt_certificate_renewal(account_id, domain_id, certificate_id, certificate_renewal_id, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::Certificate>

Issue a pending Let’s Encrypt certificate renewal order.

Note that the issuance process is async. A successful response means the issuance request has been successfully acknowledged and queued for processing.

Examples:

Basic usage

response    = client.certificates.issue_letsencrypt_certificate_renewal(1010, "example.com", 100, 999)
certificate = response.data

certificate.state # => "requesting"

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

  • certificate_id (Integer)

    the certificate ID

  • certificate_renewal_id (Integer)

    the certificate renewal ID

  • options (Hash) (defaults to: {})

Returns:

Raises:

See Also:



282
283
284
285
286
# File 'lib/dnsimple/client/certificates.rb', line 282

def issue_letsencrypt_certificate_renewal(, domain_id, certificate_id, certificate_renewal_id, options = {})
  response = client.post(Client.versioned("/%s/domains/%s/certificates/letsencrypt/%s/renewals/%s/issue" % [, domain_id, certificate_id, certificate_renewal_id]), options)

  Dnsimple::Response.new(response, Struct::Certificate.new(response["data"]))
end

#purchase_letsencrypt_certificate(account_id, domain_id, attributes = {}, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::CertificatPurchase>

Purchase a Let’s Encrypt certificate.

This method creates a new certificate order. The certificate ID should be used to request the issuance of the certificate using #issue_letsencrypt_certificate.

Examples:

Basic usage

response    = client.certificates.purchase_letsencrypt_certificate(1010, "example.com")
certificate = response.data

certificate.id              # => 100
certificate.common_name     # => "www.example.com"
certificate.alternate_names # => []
certificate.auto_renew      # => false

Custom name

response    = client.certificates.purchase_letsencrypt_certificate(1010, "example.com", name: "docs")
certificate = response.data

certificate.id              # => 100
certificate.common_name     # => "docs.example.com"
certificate.alternate_names # => []
certificate.auto_renew      # => false

SAN names

response    = client.certificates.purchase_letsencrypt_certificate(1010, "example.com", alternate_names: ["api.example.com", "status.example.com"])
certificate = response.data

certificate.id              # => 100
certificate.common_name     # => "www.example.com"
certificate.alternate_names # => ["api.example.com", "status.example.com"]
certificate.auto_renew      # => false

Auto renew

response    = client.certificates.purchase_letsencrypt_certificate(1010, "example.com", auto_renew: true)
certificate = response.data

certificate.id              # => 100
certificate.common_name     # => "www.example.com"
certificate.alternate_names # => []
certificate.auto_renew      # => true

Signature Algorithm

response    = client.certificates.purchase_letsencrypt_certificate(1010, "example.com", signature_algorithm: "RSA")
certificate = response.data

certificate.id              # => 100
certificate.common_name     # => "www.example.com"
certificate.alternate_names # => []
certificate.auto_renew      # => false

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

  • attributes (Hash) (defaults to: {})
  • options (Hash) (defaults to: {})

Options Hash (attributes):

  • :name (String)

    the certificate name (optional)

  • :alternate_names (Array<String>)

    the certificate alternate names (optional)

  • :auto_renew (TrueClass, FalseClass)

    enable certificate auto renew (optional)

  • :signature_algorithm (String)

    the signature algorithm used to sign the certificate (optional)

Returns:

Raises:

See Also:



179
180
181
182
183
# File 'lib/dnsimple/client/certificates.rb', line 179

def purchase_letsencrypt_certificate(, domain_id, attributes = {}, options = {})
  response = client.post(Client.versioned("/%s/domains/%s/certificates/letsencrypt" % [, domain_id]), attributes, options)

  Dnsimple::Response.new(response, Struct::CertificatePurchase.new(response["data"]))
end

#purchase_letsencrypt_certificate_renewal(account_id, domain_id, certificate_id, attributes = {}, options = {}) ⇒ Dnsimple::Response<Dnsimple::Struct::CertificateRenewal>

Purchase a Let’s Encrypt certificate renewal.

Examples:

Basic usage

response            = client.certificates.purchase_letsencrypt_certificate_renewal(1010, "example.com", 200)
certificate_renewal = response.data

certificate_renewal.id                 # => 999
certificate_renewal.old_certificate_id # => 200
certificate_renewal.new_certificate_id # => 300

Auto renew

response            = client.certificates.purchase_letsencrypt_certificate_renewal(1010, "example.com", 200, auto_renew: true)
certificate_renewal = response.data

certificate_renewal.id                 # => 999
certificate_renewal.old_certificate_id # => 200
certificate_renewal.new_certificate_id # => 300

Signature Algorithm

response            = client.certificates.purchase_letsencrypt_certificate_renewal(1010, "example.com", 200, signature_algorithm: "RSA")
certificate_renewal = response.data

certificate_renewal.id                 # => 999
certificate_renewal.old_certificate_id # => 200
certificate_renewal.new_certificate_id # => 300

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

  • certificate_id (Integer)

    the certificate ID

  • attributes (Hash) (defaults to: {})
  • options (Hash) (defaults to: {})

Options Hash (attributes):

  • :auto_renew (TrueClass, FalseClass)

    enable certificate auto renew (optional)

  • :signature_algorithm (String)

    the signature algorithm used to sign the certificate (optional)

Returns:

Raises:

See Also:



253
254
255
256
257
# File 'lib/dnsimple/client/certificates.rb', line 253

def purchase_letsencrypt_certificate_renewal(, domain_id, certificate_id, attributes = {}, options = {})
  response = client.post(Client.versioned("/%s/domains/%s/certificates/letsencrypt/%s/renewals" % [, domain_id, certificate_id]), attributes, options)

  Dnsimple::Response.new(response, Struct::CertificateRenewal.new(response["data"]))
end