Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoints for listCertificatePacks and getCertificatePack #212

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/Endpoints/SSL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
41 changes: 41 additions & 0 deletions tests/Endpoints/SSLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
35 changes: 35 additions & 0 deletions tests/Fixtures/Endpoints/getCertificatePack.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
37 changes: 37 additions & 0 deletions tests/Fixtures/Endpoints/listCertificatePacks.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}