Skip to content

Commit

Permalink
Deprecate Certificate expires_on in favor of expires_at
Browse files Browse the repository at this point in the history
We deprecated expires_on attribute in our documentation in favor of
expires_at. This commit introduces the new field and deprecates the old
one. It also updates to use the new fixtures.
  • Loading branch information
duduribeiro committed Jun 19, 2020
1 parent d9643e0 commit aba8493
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 141 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This project uses [Semantic Versioning 2.0.0](http://semver.org/).

## master
- CHANGED: `Certificate#expires_on` (date only) is deprecated in favor of `Certificate#expires_at` (timestamp). (dnsimple/dnsimple-ruby#190)

## 5.1.0

- CHANGED: `Domain#expires_on` (date only) is deprecated in favor of `Domain#expires_at` (timestamp). (dnsimple/dnsimple-ruby#186)
Expand Down
23 changes: 21 additions & 2 deletions lib/dnsimple/struct/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module Dnsimple
module Struct

class Certificate < Base

def initialize(attributes = {})
attributes.delete("expires_on")
super
@expires_on = Date.parse(expires_at).to_s if expires_at
end

# @return [Integer] The certificate ID in DNSimple.
attr_accessor :id

Expand Down Expand Up @@ -40,8 +47,20 @@ class Certificate < Base
# @return [String] When the certificate was last updated in DNSimple.
attr_accessor :updated_at

# @return [String] When the certificate will expire.
attr_accessor :expires_on
# @return [String] The timestamp when certificate will expire.
attr_accessor :expires_at

# @deprecated Please use #expires_at instead.
# @return [String] The date the certificate will expire.
def expires_on
warn "[DEPRECATION] Certificate#expires_on is deprecated. Please use `expires_at` instead."
@expires_on
end

def expires_on=(expiration_date)
warn "[DEPRECATION] Certificate#expires_on= is deprecated. Please use `expires_at=` instead."
@expires_on = expiration_date
end
end

end
Expand Down
67 changes: 34 additions & 33 deletions spec/dnsimple/client/certificates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@
end

let(:account_id) { 1010 }
let(:domain_id) { "example.com" }
let(:domain_id) { "dnsimple.us" }

it "delegates to client.paginate" do
expect(subject).to receive(:paginate).with(:certificates, account_id, domain_id, foo: "bar")
subject.all_certificates(account_id, domain_id, foo: "bar")
end

it "supports sorting" do
subject.all_certificates(account_id, domain_id, sort: "id:asc,expires_on:desc")
subject.all_certificates(account_id, domain_id, sort: "id:asc,expiration:desc")

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/certificates?page=1&per_page=100&sort=id:asc,expires_on:desc")
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/certificates?page=1&per_page=100&sort=id:asc,expiration:desc")
end
end

describe "#certificate" do
let(:account_id) { 1010 }
let(:domain_id) { "weppos.net" }
let(:certificate_id) { 1 }
let(:domain_id) { "bingo.pizza" }
let(:certificate_id) { 101967 }

before do
stub_request(:get, %r{/v2/#{account_id}/domains/#{domain_id}/certificates/#{certificate_id}})
Expand All @@ -108,19 +108,20 @@

result = response.data
expect(result).to be_a(Dnsimple::Struct::Certificate)
expect(result.id).to eq(1)
expect(result.domain_id).to eq(2)
expect(result.contact_id).to eq(3)
expect(result.common_name).to eq("www.weppos.net")
expect(result.alternate_names).to eq(%w( weppos.net www.weppos.net ))
expect(result.id).to eq(101967)
expect(result.domain_id).to eq(289333)
expect(result.contact_id).to eq(2511)
expect(result.common_name).to eq("www.bingo.pizza")
expect(result.alternate_names).to eq([])
expect(result.years).to eq(1)
expect(result.csr).to eq("-----BEGIN CERTIFICATE REQUEST-----\nMIICljCCAX4CAQAwGTEXMBUGA1UEAwwOd3d3LndlcHBvcy5uZXQwggEiMA0GCSqG\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC3MJwx9ahBG3kAwRjQdRvYZqtovUaxY6jp\nhd09975gO+2eYPDbc1yhNftVJ4KBT0zdEqzX0CwIlxE1MsnZ2YOsC7IJO531hMBp\ndBxM4tSG07xPz70AVUi9rY6YCUoJHmxoFbclpHFbtXZocR393W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hCNtVN4+0vpgPQ59pqwYo8TfdYzK7WSKeL7geu\nCqVE3bHAqU6dLtgHOZfTkLwGycUh4p9aawuc6fsXHHYDpIL8s3vAvwIDAQABoDow\nOAYJKoZIhvcNAQkOMSswKTAnBgNVHREEIDAeggtiaW5nby5waXp6YYIPd3d3LmJp\nbmdvLnBpenphMA0GCSqGSIb3DQEBCwUAA4IBAQBwOLKv+PO5hSJkgqS6wL/wRqLh\nQ1zbcHRHAjRjnpRz06cDvN3X3aPI+lpKSNFCI0A1oKJG7JNtgxX3Est66cuO8ESQ\nPIb6WWN7/xlVlBCe7ZkjAFgN6JurFdclwCp/NI5wBCwj1yb3Ar5QQMFIZOezIgTI\nAWkQSfCmgkB96d6QlDWgidYDDjcsXugQveOQRPlHr0TsElu47GakxZdJCFZU+WPM\nodQQf5SaqiIK2YaH1dWO//4KpTS9QoTy1+mmAa27apHcmz6X6+G5dvpHZ1qH14V0\nJoMWIK+39HRPq6mDo1UMVet/xFUUrG/H7/tFlYIDVbSpVlpVAFITd/eQkaW/\n-----END CERTIFICATE REQUEST-----\n")
expect(result.state).to eq("issued")
expect(result.authority_identifier).to eq("letsencrypt")
expect(result.auto_renew).to be(false)
expect(result.created_at).to eq("2016-06-11T18:47:08Z")
expect(result.updated_at).to eq("2016-06-11T18:47:37Z")
expect(result.expires_on).to eq("2016-09-09")
expect(result.created_at).to eq("2020-06-18T18:54:17Z")
expect(result.updated_at).to eq("2020-06-18T19:10:14Z")
expect(result.expires_on).to eq("2020-09-16")
expect(result.expires_at).to eq("2020-09-16T18:10:13Z")
end

context "when the certificate does not exist" do
Expand Down Expand Up @@ -231,7 +232,7 @@

describe "#purchase_letsencrypt_certificate" do
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }
let(:domain_id) { "bingo.pizza" }
let(:contact_id) { 100 }

before do
Expand Down Expand Up @@ -264,9 +265,9 @@
result = response.data
expect(result).to be_a(Dnsimple::Struct::CertificatePurchase)

expect(result.id).to eq(300)
expect(result.certificate_id).to eq(300)
expect(result.state).to eq("requesting")
expect(result.id).to eq(101967)
expect(result.certificate_id).to eq(101967)
expect(result.state).to eq("new")
expect(result.auto_renew).to be(false)
end

Expand All @@ -284,8 +285,8 @@

describe "#issue_letsencrypt_certificate" do
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }
let(:certificate_id) { 200 }
let(:domain_id) { "bingo.pizza" }
let(:certificate_id) { 101967 }

before do
stub_request(:post, %r{/v2/#{account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/issue})
Expand All @@ -306,9 +307,9 @@
result = response.data
expect(result).to be_a(Dnsimple::Struct::Certificate)

expect(result.id).to eq(200)
expect(result.domain_id).to eq(300)
expect(result.common_name).to eq("www.example.com")
expect(result.id).to eq(101967)
expect(result.domain_id).to eq(289333)
expect(result.common_name).to eq("www.bingo.pizza")
expect(result.alternate_names).to eq([])
expect(result.years).to eq(1)
expect(result.csr).to be(nil)
Expand Down Expand Up @@ -342,8 +343,8 @@

describe "#purchase_letsencrypt_certificate_renewal" do
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }
let(:certificate_id) { 200 }
let(:domain_id) { "bingo.pizza" }
let(:certificate_id) { 101967 }

before do
stub_request(:post, %r{/v2/#{account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals})
Expand Down Expand Up @@ -373,9 +374,9 @@
result = response.data
expect(result).to be_a(Dnsimple::Struct::CertificateRenewal)

expect(result.id).to eq(999)
expect(result.id).to eq(65082)
expect(result.old_certificate_id).to eq(certificate_id)
expect(result.new_certificate_id).to eq(300)
expect(result.new_certificate_id).to eq(101972)
expect(result.state).to eq("new")
end

Expand All @@ -393,9 +394,9 @@

describe "#issue_letsencrypt_certificate_renewal" do
let(:account_id) { 1010 }
let(:domain_id) { "example.com" }
let(:certificate_id) { 300 }
let(:certificate_renewal_id) { 999 }
let(:domain_id) { "bingo.pizza" }
let(:certificate_id) { 101972 }
let(:certificate_renewal_id) { 65082 }

before do
stub_request(:post, %r{/v2/#{account_id}/domains/#{domain_id}/certificates/letsencrypt/#{certificate_id}/renewals/#{certificate_renewal_id}/issue})
Expand All @@ -416,9 +417,9 @@
result = response.data
expect(result).to be_a(Dnsimple::Struct::Certificate)

expect(result.id).to eq(300)
expect(result.domain_id).to eq(300)
expect(result.common_name).to eq("www.example.com")
expect(result.id).to eq(101972)
expect(result.domain_id).to eq(289333)
expect(result.common_name).to eq("www.bingo.pizza")
expect(result.alternate_names).to eq([])
expect(result.years).to eq(1)
expect(result.csr).to be(nil)
Expand Down
22 changes: 11 additions & 11 deletions spec/fixtures.http/getCertificate/success.http
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 08 Jul 2016 15:38:13 GMT
Date: Thu, 18 Jun 2020 19:16:29 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Transfer-Encoding: identity
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2396
X-RateLimit-Reset: 1467993483
ETag: W/"cf565290606493623c2dd9fee039b9f1"
X-RateLimit-Limit: 4800
X-RateLimit-Remaining: 4797
X-RateLimit-Reset: 1592510057
ETag: W/"9ace4f536d7b618fd4b38efd3cea9d1f"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: b6d5717d-d660-41dd-996c-4cc151d1f872
X-Runtime: 0.037324
X-Request-Id: 83905116-1333-4b07-ace4-d0db9e90c4fa
X-Runtime: 0.012798
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000

{"data":{"id":1,"domain_id":2,"contact_id":3,"name":"www","common_name":"www.weppos.net","years":1,"csr":"-----BEGIN CERTIFICATE REQUEST-----\nMIICljCCAX4CAQAwGTEXMBUGA1UEAwwOd3d3LndlcHBvcy5uZXQwggEiMA0GCSqG\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC3MJwx9ahBG3kAwRjQdRvYZqtovUaxY6jp\nhd09975gO+2eYPDbc1yhNftVJ4KBT0zdEqzX0CwIlxE1MsnZ2YOsC7IJO531hMBp\ndBxM4tSG07xPz70AVUi9rY6YCUoJHmxoFbclpHFbtXZocR393WyzUK8047uM2mlz\n03AZKcMdyfeuo2/9TcxpTSCkklGqwqS9wtTogckaDHJDoBunAkMioGfOSMe7Yi6E\nYRtG4yPJYsDaq2yPJWV8+i0PFR1Wi5RCnPt0YdQWstHuZrxABi45+XVkzKtz3TUc\nYxrvPBucVa6uzd953u8CixNFkiOefvb/dajsv1GIwH6/Cvc1ftz1AgMBAAGgODA2\nBgkqhkiG9w0BCQ4xKTAnMCUGA1UdEQQeMByCDnd3dy53ZXBwb3MubmV0ggp3ZXBw\nb3MubmV0MA0GCSqGSIb3DQEBCwUAA4IBAQCDnVBO9RdJX0eFeZzlv5c8yG8duhKP\nl0Vl+V88fJylb/cbNj9qFPkKTK0vTXmS2XUFBChKPtLucp8+Z754UswX+QCsdc7U\nTTSG0CkyilcSubdZUERGej1XfrVQhrokk7Fu0Jh3BdT6REP0SIDTpA8ku/aRQiAp\np+h19M37S7+w/DMGDAq2LSX8jOpJ1yIokRDyLZpmwyLxutC21DXMGoJ3xZeUFrUT\nqRNwzkn2dJzgTrPkzhaXalUBqv+nfXHqHaWljZa/O0NVCFrHCdTdd53/6EE2Yabv\nq5SFTkRCpaxrvM/7a8Tr4ixD1/VKD6rw3+WC00000000000000000000\n-----END CERTIFICATE REQUEST-----\n","state":"issued","auto_renew":false,"alternate_names":["weppos.net", "www.weppos.net"],"authority_identifier":"letsencrypt","created_at":"2016-06-11T18:47:08Z","updated_at":"2016-06-11T18:47:37Z","expires_on":"2016-09-09"}}
{"data":{"id":101967,"domain_id":289333,"contact_id":2511,"name":"www","common_name":"www.bingo.pizza","years":1,"csr":"-----BEGIN CERTIFICATE REQUEST-----\nMIICmTCCAYECAQAwGjEYMBYGA1UEAwwPd3d3LmJpbmdvLnBpenphMIIBIjANBgkq\nhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw4+KoZ9IDCK2o5qAQpi+Icu5kksmjQzx\n5o5g4B6XhRxhsfHlK/i3iU5hc8CONjyVv8j82835RNsiKrflnxGa9SH68vbQfcn4\nIpbMz9c+Eqv5h0Euqlc3A4DBzp0unEu5QAUhR6Xu1TZIWDPjhrBOGiszRlLQcp4F\nzy6fD6j5/d/ylpzTp5v54j+Ey31Bz86IaBPtSpHI+Qk87Hs8DVoWxZk/6RlAkyur\nXDGWnPu9n3RMfs9ag5anFhggLIhCNtVN4+0vpgPQ59pqwYo8TfdYzK7WSKeL7geu\nCqVE3bHAqU6dLtgHOZfTkLwGycUh4p9aawuc6fsXHHYDpIL8s3vAvwIDAQABoDow\nOAYJKoZIhvcNAQkOMSswKTAnBgNVHREEIDAeggtiaW5nby5waXp6YYIPd3d3LmJp\nbmdvLnBpenphMA0GCSqGSIb3DQEBCwUAA4IBAQBwOLKv+PO5hSJkgqS6wL/wRqLh\nQ1zbcHRHAjRjnpRz06cDvN3X3aPI+lpKSNFCI0A1oKJG7JNtgxX3Est66cuO8ESQ\nPIb6WWN7/xlVlBCe7ZkjAFgN6JurFdclwCp/NI5wBCwj1yb3Ar5QQMFIZOezIgTI\nAWkQSfCmgkB96d6QlDWgidYDDjcsXugQveOQRPlHr0TsElu47GakxZdJCFZU+WPM\nodQQf5SaqiIK2YaH1dWO//4KpTS9QoTy1+mmAa27apHcmz6X6+G5dvpHZ1qH14V0\nJoMWIK+39HRPq6mDo1UMVet/xFUUrG/H7/tFlYIDVbSpVlpVAFITd/eQkaW/\n-----END CERTIFICATE REQUEST-----\n","state":"issued","auto_renew":false,"alternate_names":[],"authority_identifier":"letsencrypt","created_at":"2020-06-18T18:54:17Z","updated_at":"2020-06-18T19:10:14Z","expires_at":"2020-09-16T18:10:13Z","expires_on":"2020-09-16"}}
40 changes: 19 additions & 21 deletions spec/fixtures.http/issueLetsencryptCertificate/success.http
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
HTTP/1.1 202 Accepted
Server: nginx
Date: Wed, 18 Oct 2017 15:42:19 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2398
X-RateLimit-Reset: 1508344833
ETag: W/"2d6bbf090ba2144b097e33cb3d8964e4"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 50628584-cc2f-4543-8775-4f7c8196078b
X-Runtime: 0.771481
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000

{"data":{"id":200,"domain_id":300,"contact_id":100,"name":"www","common_name":"www.example.com","years":1,"csr":null,"state":"requesting","auto_renew":false,"alternate_names":[],"authority_identifier":"letsencrypt","created_at":"2017-10-18T15:40:32Z","updated_at":"2017-10-18T15:42:18Z","expires_on":null}}
HTTP/1.1 202 Accepted
Server: nginx
Date: Thu, 18 Jun 2020 18:56:21 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: identity
Connection: keep-alive
X-RateLimit-Limit: 4800
X-RateLimit-Remaining: 4798
X-RateLimit-Reset: 1592510057
Cache-Control: no-cache
X-Request-Id: 1d6bdd7c-a88e-4ac2-9d12-36699a32b006
X-Runtime: 0.884870
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none

{"data":{"id":101967,"domain_id":289333,"contact_id":2511,"name":"www","common_name":"www.bingo.pizza","years":1,"csr":null,"state":"requesting","auto_renew":false,"alternate_names":[],"authority_identifier":"letsencrypt","created_at":"2020-06-18T18:54:17Z","updated_at":"2020-06-18T18:56:20Z","expires_at":null,"expires_on":null}}
40 changes: 19 additions & 21 deletions spec/fixtures.http/issueRenewalLetsencryptCertificate/success.http
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
HTTP/1.1 202 Accepted
Server: nginx
Date: Thu, 19 Oct 2017 08:22:17 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2398
X-RateLimit-Reset: 1508404733
ETag: W/"8dfa538f5255d47f11d016dbb1c26059"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 185ad43f-1e34-43fb-a4aa-0359c9f95f2d
X-Runtime: 0.853294
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000

{"data":{"id":300,"domain_id":300,"contact_id":100,"name":"www","common_name":"www.example.com","years":1,"csr":null,"state":"requesting","auto_renew":false,"alternate_names":[],"authority_identifier":"letsencrypt","created_at":"2017-10-19T08:18:53Z","updated_at":"2017-10-19T08:22:17Z","expires_on":null}}
HTTP/1.1 202 Accepted
Server: nginx
Date: Thu, 18 Jun 2020 20:05:26 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: identity
Connection: keep-alive
X-RateLimit-Limit: 4800
X-RateLimit-Remaining: 4798
X-RateLimit-Reset: 1592513780
Cache-Control: no-cache
X-Request-Id: a7194bb4-aea4-42c6-846f-cd96f5f3cf5c
X-Runtime: 0.897152
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none

{"data":{"id":101972,"domain_id":289333,"contact_id":2511,"name":"www","common_name":"www.bingo.pizza","years":1,"csr":null,"state":"requesting","auto_renew":false,"alternate_names":[],"authority_identifier":"letsencrypt","created_at":"2020-06-18T19:56:20Z","updated_at":"2020-06-18T20:05:26Z","expires_at":null,"expires_on":null}}

0 comments on commit aba8493

Please sign in to comment.