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:



199
200
201
202
203
# File 'lib/dnsimple/client/certificates.rb', line 199

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:



265
266
267
268
269
# File 'lib/dnsimple/client/certificates.rb', line 265

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", contact_id: 1)
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", contact_id: 1, 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", contact_id: 1, 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", contact_id: 1, auto_renew: true)
certificate = response.data

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

Parameters:

  • account_id (Integer)

    the account ID

  • domain_id (#to_s)

    the domain ID or domain name

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

Options Hash (attributes):

  • :contact_id (Integer)

    the contact ID (mandatory)

  • :name (String)

    the certificate name (optional)

  • :alternate_names (Array<String>)

    the certificate alternate names (optional)

  • :auto_renew (TrueClass, FalseClass)

    enable certificate auto renew (optional)

Returns:

Raises:

See Also:



170
171
172
173
174
175
# File 'lib/dnsimple/client/certificates.rb', line 170

def purchase_letsencrypt_certificate(, domain_id, attributes, options = {})
  Extra.validate_mandatory_attributes(attributes, [:contact_id])
  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

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)

Returns:

Raises:

See Also:



236
237
238
239
240
# File 'lib/dnsimple/client/certificates.rb', line 236

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