diff --git a/src/Endpoints/SSL.php b/src/Endpoints/SSL.php index 2ed506b7..3270ad93 100644 --- a/src/Endpoints/SSL.php +++ b/src/Endpoints/SSL.php @@ -180,4 +180,50 @@ public function updateSSLCertificatePackValidationMethod(string $zoneID, string } return false; } + + /** + * List certificate packs + * + * @param string $zoneID The ID of the zone + * @param string|null $status Use "all" to include certificate packs of all statuses and not only active ones + * @return array + * @throws EndpointException + */ + public function listCertificatePacks(string $zoneID, string $status = null): array + { + if ($status != null && !in_array($status, ['all'])) { + throw new EndpointException('Certificate packs can only be listed by status of all.'); + } + + $return = $this->adapter->get( + 'zones/' . $zoneID . '/ssl/certificate_packs', + [ + 'status' => $status, + ] + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result; + } + return false; + } + + /** + * Get a specific certificate pack + * + * @param string $zoneID The ID of the zone + * @param string $certPackUUID The certificate pack UUID + * @return \stdClass + * @throws EndpointException + */ + public function getCertificatePack(string $zoneID, string $certPackUUID): \stdClass + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/ssl/certificate_packs/' . $certPackUUID + ); + $body = json_decode($return->getBody()); + if (isset($body->result)) { + return $body->result; + } + } } diff --git a/tests/Endpoints/SSLTest.php b/tests/Endpoints/SSLTest.php index c2a1b401..9d5bfbf1 100644 --- a/tests/Endpoints/SSLTest.php +++ b/tests/Endpoints/SSLTest.php @@ -158,4 +158,45 @@ public function testUpdateSSLCertificatePackValidationMethod() $this->assertTrue($result); } + + public function testListCertificatePacks() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/listCertificatePacks.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/ssl/certificate_packs'), + $this->equalTo([ + 'status' => 'all' + ]) + ); + + $sslMock = new Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->listCertificatePacks('023e105f4ecef8ad9ca31a8372d0c353', 'all'); + + $this->assertEquals('3822ff90-ea29-44df-9e55-21300bb9419b', $result[0]->id); + } + + public function testGetCertificatePack() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getCertificatePack.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/ssl/certificate_packs/3822ff90-ea29-44df-9e55-21300bb9419b') + ); + + $sslMock = new Cloudflare\API\Endpoints\SSL($mock); + $result = $sslMock->getCertificatePack('023e105f4ecef8ad9ca31a8372d0c353', '3822ff90-ea29-44df-9e55-21300bb9419b'); + + $this->assertEquals('3822ff90-ea29-44df-9e55-21300bb9419b', $result->id); + } } diff --git a/tests/Fixtures/Endpoints/getCertificatePack.json b/tests/Fixtures/Endpoints/getCertificatePack.json new file mode 100644 index 00000000..a01524cd --- /dev/null +++ b/tests/Fixtures/Endpoints/getCertificatePack.json @@ -0,0 +1,35 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "3822ff90-ea29-44df-9e55-21300bb9419b", + "type": "custom", + "hosts": [ + "example.com", + "*.example.com", + "www.example.com" + ], + "certificates": [ + { + "id": "2458ce5a-0c35-4c7f-82c7-8e9487d3ff60", + "hosts": [ + "example.com" + ], + "issuer": "GlobalSign", + "signature": "SHA256WithRSA", + "status": "active", + "bundle_method": "ubiquitous", + "geo_restrictions": { + "label": "us" + }, + "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", + "uploaded_on": "2014-01-01T05:20:00Z", + "modified_on": "2014-01-01T05:20:00Z", + "expires_on": "2016-01-01T05:20:00Z", + "priority": 1 + } + ], + "primary_certificate": "7e7b8deba8538af625850b7b2530034c" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/listCertificatePacks.json b/tests/Fixtures/Endpoints/listCertificatePacks.json new file mode 100644 index 00000000..9591d6fe --- /dev/null +++ b/tests/Fixtures/Endpoints/listCertificatePacks.json @@ -0,0 +1,37 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": [ + { + "id": "3822ff90-ea29-44df-9e55-21300bb9419b", + "type": "custom", + "hosts": [ + "example.com", + "*.example.com", + "www.example.com" + ], + "certificates": [ + { + "id": "2458ce5a-0c35-4c7f-82c7-8e9487d3ff60", + "hosts": [ + "example.com" + ], + "issuer": "GlobalSign", + "signature": "SHA256WithRSA", + "status": "active", + "bundle_method": "ubiquitous", + "geo_restrictions": { + "label": "us" + }, + "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", + "uploaded_on": "2014-01-01T05:20:00Z", + "modified_on": "2014-01-01T05:20:00Z", + "expires_on": "2016-01-01T05:20:00Z", + "priority": 1 + } + ], + "primary_certificate": "7e7b8deba8538af625850b7b2530034c" + } + ] +} \ No newline at end of file