Add changing TLS Zone Settings capability

This commit is contained in:
Marlin-Ops.com - Jurgen Coetsiers
2018-10-21 11:16:57 +02:00
parent 8c68295daa
commit 90e01ff095
3 changed files with 14 additions and 17 deletions

View File

@@ -10,7 +10,7 @@ namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Adapter\Adapter;
class ZoneSettings implements API class TLS implements API
{ {
private $adapter; private $adapter;
@@ -19,20 +19,23 @@ class ZoneSettings implements API
$this->adapter = $adapter; $this->adapter = $adapter;
} }
public function enableTLS13($zoneID, $enable=false) { public function enableTLS13($zoneID, $enable=false)
{
$return = $this->adapter->patch( $return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/tls_1_3', 'zones/' . $zoneID . '/settings/tls_1_3',
['value' => $enable ? 'on' : 'off'] ['value' => $enable ? 'on' : 'off']
); );
$body = json_decode($return->getBody()); $body = json_decode($return->getBody());
return $body->result; if ($body->success) {
return true;
}
return false;
} }
public function changeMinimumTLSVersion($zoneID, $minimumVersion) { public function changeMinimumTLSVersion($zoneID, $minimumVersion)
{
$return = $this->adapter->patch( $return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/min_tls_version', 'zones/' . $zoneID . '/settings/min_tls_version',
[ [
@@ -42,9 +45,5 @@ class ZoneSettings implements API
$body = json_decode($return->getBody()); $body = json_decode($return->getBody());
return $body->result; return $body->result;
} }
}
}

View File

@@ -7,7 +7,7 @@
* Time: 09:09 * Time: 09:09
*/ */
class ZoneSettingsTest extends TestCase class TLSTest extends TestCase
{ {
public function testEnableTLS13() public function testEnableTLS13()
{ {
@@ -23,11 +23,9 @@ class ZoneSettingsTest extends TestCase
$this->equalTo(['value' => 'on']) $this->equalTo(['value' => 'on'])
); );
$zoneSettings = new \Cloudflare\API\Endpoints\ZoneSettings($mock); $ZoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
$result = $zoneSettings->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $result = $ZoneTLSSettings->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$this->assertTrue($result); $this->assertTrue($result);
} }
} }

View File

@@ -2,5 +2,5 @@
"success": true, "success": true,
"errors": [], "errors": [],
"messages": [], "messages": [],
"result": "off" "result": "on"
} }