Skip to content

Commit

Permalink
Merge pull request #180 from phily245/179-missing-support-for-custom-…
Browse files Browse the repository at this point in the history
…hostname-update-properties

Missing Support For Custom Hostname Update Properties
  • Loading branch information
jacobbednarz authored Jun 23, 2021
2 parents a73da76 + ba875c3 commit d97cf24
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
45 changes: 39 additions & 6 deletions src/Endpoints/CustomHostnames.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,33 @@ public function getHostname(string $zoneID, string $hostnameID)

/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @param string $zoneID
* @param string $hostnameID
* @param string $sslMethod
* @param string $sslType
* @param string $zoneID
* @param string $hostnameID
* @param string $sslMethod
* @param string $sslType
* @param array $sslSettings
* @param string $customOriginServer
* @param bool|null $wildcard
* @param string $bundleMethod
* @param array $customSsl
* @return \stdClass
*/
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = '', array $sslSettings = [], string $customOriginServer = ''): \stdClass
{
public function updateHostname(
string $zoneID,
string $hostnameID,
string $sslMethod = '',
string $sslType = '',
array $sslSettings = [],
string $customOriginServer = '',
bool $wildcard = null,
string $bundleMethod = '',
array $customSsl = []
): \stdClass {
$query = [];
$options = [];

if (!empty($sslMethod)) {
$query['method'] = $sslMethod;
Expand All @@ -166,6 +183,22 @@ public function updateHostname(string $zoneID, string $hostnameID, string $sslMe
$query['settings'] = $sslSettings;
}

if (!is_null($wildcard)) {
$query['wildcard'] = $wildcard;
}

if (!empty($bundleMethod)) {
$query['bundle_method'] = $bundleMethod;
}

if (!empty($customSsl['key'])) {
$query['custom_key'] = $customSsl['key'];
}

if (!empty($customSsl['certificate'])) {
$query['custom_certificate'] = $customSsl['certificate'];
}

if (!empty($query)) {
$options = [
'ssl' => $query
Expand Down
27 changes: 24 additions & 3 deletions tests/Endpoints/CustomHostnamesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public function testUpdateHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json');

$customSsl = $this->getCustomSsl();

$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);

Expand All @@ -137,7 +139,12 @@ public function testUpdateHostname()
'http2' => 'on',
'http3' => 'on',
'min_tls_version' => '1.2'
]
],
'bundle_method' => 'optimal',
'custom_key' => $customSsl['key'],
'custom_certificate' => $customSsl['certificate'],
'wildcard' => true,

]
])
);
Expand All @@ -148,7 +155,21 @@ public function testUpdateHostname()
'http3' => 'on',
'min_tls_version' => '1.2'
];
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv', $sslSettings, 'origin.example.com');

$result = $zones->updateHostname(
'023e105f4ecef8ad9ca31a8372d0c353',
'0d89c70d-ad9f-4843-b99f-6cc0252067e9',
'http',
'dv',
$sslSettings,
'origin.example.com',
true,
'optimal',
[
'key' => $customSsl['key'],
'certificate' => $customSsl['certificate'],
]
);

$this->assertObjectHasAttribute('id', $result);
$this->assertObjectHasAttribute('hostname', $result);
Expand Down Expand Up @@ -194,7 +215,7 @@ public function testGetHostnameFallbackOrigin()
$this->assertObjectHasAttribute('origin', $result);
$this->assertObjectHasAttribute('status', $result);
}

private function getCustomSsl(): array
{
$customKey = <<<KEY
Expand Down

0 comments on commit d97cf24

Please sign in to comment.