Add custom hostname options (#131)
* Add ability to set additional SSL settings * Add ability to specify a custom origin server * Add ability to set wildcard * Fix json parsing error with empty 'ssl' key Co-authored-by: Craig Menning <craig@bubbleup.net>
This commit is contained in:
@@ -30,18 +30,27 @@ class CustomHostnames implements API
|
||||
* @param string $hostname
|
||||
* @param string $sslMethod
|
||||
* @param string $sslType
|
||||
* @param array $sslSettings
|
||||
* @param string $customOriginServer
|
||||
* @param bool $wildcard
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv'): \stdClass
|
||||
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv', array $sslSettings = [], string $customOriginServer = '', bool $wildcard = false): \stdClass
|
||||
{
|
||||
$options = [
|
||||
'hostname' => $hostname,
|
||||
'ssl' => [
|
||||
'method' => $sslMethod,
|
||||
'type' => $sslType
|
||||
]
|
||||
'type' => $sslType,
|
||||
'settings' => $sslSettings
|
||||
],
|
||||
'wildcard' => $wildcard,
|
||||
];
|
||||
|
||||
if (!empty($customOriginServer)) {
|
||||
$options['custom_origin_server'] = $customOriginServer;
|
||||
}
|
||||
|
||||
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
return $this->body->result;
|
||||
@@ -118,7 +127,7 @@ class CustomHostnames implements API
|
||||
* @param string $sslType
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = ''): \stdClass
|
||||
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = '', array $sslSettings = [], string $customOriginServer = ''): \stdClass
|
||||
{
|
||||
$query = [];
|
||||
|
||||
@@ -130,9 +139,19 @@ class CustomHostnames implements API
|
||||
$query['type'] = $sslType;
|
||||
}
|
||||
|
||||
if (!empty($sslSettings)) {
|
||||
$query['settings'] = $sslSettings;
|
||||
}
|
||||
|
||||
if (!empty($query)) {
|
||||
$options = [
|
||||
'ssl' => $query
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($customOriginServer)) {
|
||||
$options['custom_origin_server'] = $customOriginServer;
|
||||
}
|
||||
|
||||
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
|
||||
@@ -23,15 +23,27 @@ class CustomHostnamesTest extends TestCase
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
||||
$this->equalTo([
|
||||
'hostname' => 'app.example.com',
|
||||
'custom_origin_server' => 'origin.example.com',
|
||||
'ssl' => [
|
||||
'method' => 'http',
|
||||
'type' => 'dv'
|
||||
'type' => 'dv',
|
||||
'settings' => [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2'
|
||||
]
|
||||
],
|
||||
'wildcard' => true,
|
||||
])
|
||||
);
|
||||
|
||||
$hostname = new CustomHostnames($mock);
|
||||
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv');
|
||||
$sslSettings = [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2'
|
||||
];
|
||||
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv', $sslSettings, 'origin.example.com', true);
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id);
|
||||
}
|
||||
|
||||
@@ -101,15 +113,26 @@ class CustomHostnamesTest extends TestCase
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
||||
$this->equalTo([
|
||||
'custom_origin_server' => 'origin.example.com',
|
||||
'ssl' => [
|
||||
'method' => 'http',
|
||||
'type' => 'dv'
|
||||
'type' => 'dv',
|
||||
'settings' => [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2'
|
||||
]
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv');
|
||||
$sslSettings = [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2'
|
||||
];
|
||||
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv', $sslSettings, 'origin.example.com');
|
||||
|
||||
$this->assertObjectHasAttribute('id', $result);
|
||||
$this->assertObjectHasAttribute('hostname', $result);
|
||||
|
||||
Reference in New Issue
Block a user