Merge pull request #180 from phily245/179-missing-support-for-custom-hostname-update-properties

Missing Support For Custom Hostname Update Properties
This commit is contained in:
Jacob Bednarz
2021-06-23 10:17:15 +10:00
committed by GitHub
2 changed files with 63 additions and 9 deletions

View File

@@ -143,16 +143,33 @@ class CustomHostnames implements API
/**
* @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;
@@ -166,6 +183,22 @@ class CustomHostnames implements API
$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

View File

@@ -121,6 +121,8 @@ class CustomHostnamesTest extends TestCase
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json');
$customSsl = $this->getCustomSsl();
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
@@ -137,7 +139,12 @@ class CustomHostnamesTest extends TestCase
'http2' => 'on',
'http3' => 'on',
'min_tls_version' => '1.2'
]
],
'bundle_method' => 'optimal',
'custom_key' => $customSsl['key'],
'custom_certificate' => $customSsl['certificate'],
'wildcard' => true,
]
])
);
@@ -148,7 +155,21 @@ class CustomHostnamesTest extends TestCase
'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);
@@ -194,7 +215,7 @@ class CustomHostnamesTest extends TestCase
$this->assertObjectHasAttribute('origin', $result);
$this->assertObjectHasAttribute('status', $result);
}
private function getCustomSsl(): array
{
$customKey = <<<KEY