diff --git a/src/Endpoints/CustomHostnames.php b/src/Endpoints/CustomHostnames.php index 9e01fa2..592ed71 100644 --- a/src/Endpoints/CustomHostnames.php +++ b/src/Endpoints/CustomHostnames.php @@ -30,27 +30,50 @@ class CustomHostnames implements API * @param string $hostname * @param string $sslMethod * @param string $sslType - * @param array $sslSettings + * @param array $sslSettings * @param string $customOriginServer - * @param bool $wildcard + * @param bool $wildcard + * @param string $bundleMethod + * @param array $customSsl * @return \stdClass */ - public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv', array $sslSettings = [], string $customOriginServer = '', bool $wildcard = false): \stdClass - { + public function addHostname( + string $zoneID, + string $hostname, + string $sslMethod = 'http', + string $sslType = 'dv', + array $sslSettings = [], + string $customOriginServer = '', + bool $wildcard = false, + string $bundleMethod = '', + array $customSsl = [] + ): \stdClass { $options = [ 'hostname' => $hostname, 'ssl' => [ 'method' => $sslMethod, 'type' => $sslType, - 'settings' => $sslSettings + 'settings' => $sslSettings, + 'wildcard' => $wildcard, ], - 'wildcard' => $wildcard, ]; if (!empty($customOriginServer)) { $options['custom_origin_server'] = $customOriginServer; } + if (!empty($bundleMethod)) { + $options['ssl']['bundle_method'] = $bundleMethod; + } + + if (!empty($customSsl['key'])) { + $options['ssl']['custom_key'] = $customSsl['key']; + } + + if (!empty($customSsl['certificate'])) { + $options['ssl']['custom_certificate'] = $customSsl['certificate']; + } + $zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options); $this->body = json_decode($zone->getBody()); return $this->body->result; diff --git a/tests/Endpoints/CustomHostnamesTest.php b/tests/Endpoints/CustomHostnamesTest.php index b542c83..90dda06 100644 --- a/tests/Endpoints/CustomHostnamesTest.php +++ b/tests/Endpoints/CustomHostnamesTest.php @@ -14,6 +14,8 @@ class CustomHostnamesTest extends TestCase { $response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json'); + $customSsl = $this->getCustomSsl(); + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); $mock->method('post')->willReturn($response); @@ -30,10 +32,13 @@ class CustomHostnamesTest extends TestCase 'settings' => [ 'http2' => 'on', 'http3' => 'on', - 'min_tls_version' => '1.2' - ] + 'min_tls_version' => '1.2', + ], + 'bundle_method' => 'optimal', + 'custom_key' => $customSsl['key'], + 'custom_certificate' => $customSsl['certificate'], + 'wildcard' => true, ], - 'wildcard' => true, ]) ); @@ -43,7 +48,18 @@ class CustomHostnamesTest extends TestCase 'http3' => 'on', 'min_tls_version' => '1.2' ]; - $hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv', $sslSettings, 'origin.example.com', true); + + $hostname->addHostname( + '023e105f4ecef8ad9ca31a8372d0c353', + 'app.example.com', + 'http', + 'dv', + $sslSettings, + 'origin.example.com', + true, + 'optimal', + $customSsl + ); $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id); }