Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4694904b38 | ||
|
|
7e3e367f16 | ||
|
|
97af6a2ca6 | ||
|
|
3da4f053f0 | ||
|
|
1e369bd9cd | ||
|
|
5841936f04 | ||
|
|
a8017f864b | ||
|
|
ba2c37fe1e | ||
|
|
db0f0eed79 | ||
|
|
4e17cc8984 | ||
|
|
c1193f7f91 | ||
|
|
67a24c5784 | ||
|
|
8bb2e8a110 | ||
|
|
9d1750594e | ||
|
|
ed6b1ec5a2 | ||
|
|
90e01ff095 | ||
|
|
8c68295daa | ||
|
|
57318b2a56 | ||
|
|
099f383ef3 | ||
|
|
2639331c2b | ||
|
|
d871bdd007 | ||
|
|
c60064e542 | ||
|
|
0492e9b17b | ||
|
|
5bea924c76 | ||
|
|
943b0d85d4 | ||
|
|
e28fed86d1 | ||
|
|
45df26fec3 | ||
|
|
a39d6fb170 | ||
|
|
4c288c38d7 | ||
|
|
2dd4d8f883 | ||
|
|
59f6d72d0a | ||
|
|
f19f17ea6f | ||
|
|
a3a346ccb2 | ||
|
|
deb420d087 | ||
|
|
640b787540 | ||
|
|
8df0ec5511 | ||
|
|
938065cdf3 | ||
|
|
9076d714f4 | ||
|
|
c9d2782b88 | ||
|
|
1cca3e0724 | ||
|
|
63be6cf154 | ||
|
|
c06fe79ad0 | ||
|
|
cca073c809 |
@@ -4,7 +4,7 @@
|
||||
|
||||
## Installation
|
||||
|
||||
The recommended way to install this package is via the Packagist Dependency Manager ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)). You can specific usage examples on the Cloudflare Knowledge Base under: [Cloudflare PHP API Binding](https://support.cloudflare.com/hc/en-us/articles/115001661191)
|
||||
The recommended way to install this package is via the Packagist Dependency Manager ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)). You can get specific usage examples on the Cloudflare Knowledge Base under: [Cloudflare PHP API Binding](https://support.cloudflare.com/hc/en-us/articles/115001661191)
|
||||
|
||||
## Cloudflare API version 4
|
||||
|
||||
@@ -19,6 +19,7 @@ Each API call is provided via a similarly named function within various classes
|
||||
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
||||
- [ ] Virtual DNS Management
|
||||
- [x] Custom hostnames
|
||||
- [x] Manage TLS settings
|
||||
- [x] Zone Lockdown and User-Agent Block rules
|
||||
- [ ] Organization Administration
|
||||
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
|
||||
|
||||
3002
composer.lock
generated
Normal file
3002
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -31,46 +31,46 @@ interface Adapter
|
||||
* RFCs, it is never useful).
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $query
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $uri, array $query, array $headers): ResponseInterface;
|
||||
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param array $body
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function post(string $uri, array $headers, array $body): ResponseInterface;
|
||||
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param array $body
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function put(string $uri, array $headers, array $body): ResponseInterface;
|
||||
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param array $body
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function patch(string $uri, array $headers, array $body): ResponseInterface;
|
||||
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
* @param array $body
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(string $uri, array $headers, array $body): ResponseInterface;
|
||||
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||
}
|
||||
|
||||
@@ -37,79 +37,56 @@ class Guzzle implements Adapter
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(string $uri, array $query = [], array $headers = []): ResponseInterface
|
||||
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||
{
|
||||
$response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]);
|
||||
|
||||
$this->checkError($response);
|
||||
return $response;
|
||||
return $this->request('get', $uri, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function post(string $uri, array $headers = [], array $body = []): ResponseInterface
|
||||
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||
{
|
||||
$response = $this->client->post(
|
||||
$uri,
|
||||
[
|
||||
'headers' => $headers,
|
||||
'json' => $body
|
||||
]
|
||||
);
|
||||
|
||||
$this->checkError($response);
|
||||
return $response;
|
||||
return $this->request('post', $uri, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function put(string $uri, array $headers = [], array $body = []): ResponseInterface
|
||||
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||
{
|
||||
$response = $this->client->put(
|
||||
$uri,
|
||||
[
|
||||
'headers' => $headers,
|
||||
'json' => $body
|
||||
]
|
||||
);
|
||||
|
||||
$this->checkError($response);
|
||||
return $response;
|
||||
return $this->request('put', $uri, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function patch(string $uri, array $headers = [], array $body = []): ResponseInterface
|
||||
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||
{
|
||||
$response = $this->client->patch(
|
||||
$uri,
|
||||
[
|
||||
'headers' => $headers,
|
||||
'json' => $body
|
||||
]
|
||||
);
|
||||
|
||||
$this->checkError($response);
|
||||
return $response;
|
||||
return $this->request('patch', $uri, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(string $uri, array $headers = [], array $body = []): ResponseInterface
|
||||
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||
{
|
||||
$response = $this->client->delete(
|
||||
$uri,
|
||||
[
|
||||
'headers' => $headers,
|
||||
'json' => $body
|
||||
]
|
||||
);
|
||||
return $this->request('delete', $uri, $data, $headers);
|
||||
}
|
||||
|
||||
public function request(string $method, string $uri, array $data = [], array $headers = [])
|
||||
{
|
||||
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
|
||||
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
|
||||
}
|
||||
|
||||
$response = $this->client->$method($uri, [
|
||||
'headers' => $headers,
|
||||
($method === 'get' ? 'query' : 'json') => $data,
|
||||
]);
|
||||
|
||||
$this->checkError($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -261,7 +261,7 @@ class PageRulesActions implements Configurations
|
||||
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
||||
}
|
||||
|
||||
$this->addConfigurationOption('smart_errors', [
|
||||
$this->addConfigurationOption('ssl', [
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
@@ -301,19 +301,9 @@ class PageRulesActions implements Configurations
|
||||
|
||||
private function addConfigurationOption(string $setting, array $configuration)
|
||||
{
|
||||
/**
|
||||
* Transforms an, optionally nested, array in to a collection of
|
||||
* stdClass objects.
|
||||
*
|
||||
* @var array $array
|
||||
*/
|
||||
$getArrayAsObject = function (array $array) {
|
||||
return json_decode(json_encode($array));
|
||||
};
|
||||
|
||||
$configuration['id'] = $setting;
|
||||
|
||||
array_push($this->configs, $getArrayAsObject($configuration));
|
||||
array_push($this->configs, $configuration);
|
||||
}
|
||||
|
||||
private function getBoolAsOnOrOff(bool $value): string
|
||||
|
||||
@@ -15,9 +15,9 @@ class PageRulesTargets implements Configurations
|
||||
public function __construct(string $queryUrl)
|
||||
{
|
||||
$this->targets = [
|
||||
(object)[
|
||||
[
|
||||
'target' => 'url',
|
||||
'constraint' => (object)[
|
||||
'constraint' => [
|
||||
'operator' => 'matches',
|
||||
'value' => $queryUrl
|
||||
]
|
||||
|
||||
@@ -14,7 +14,7 @@ class UARules implements Configurations
|
||||
|
||||
public function addUA(string $value)
|
||||
{
|
||||
$this->configs[] = (object)['target' => 'ua', 'value' => $value];
|
||||
$this->configs[] = ['target' => 'ua', 'value' => $value];
|
||||
}
|
||||
|
||||
public function getArray(): array
|
||||
|
||||
@@ -14,12 +14,12 @@ class ZoneLockdown implements Configurations
|
||||
|
||||
public function addIP(string $value)
|
||||
{
|
||||
$this->configs[] = (object)['target' => 'ip', 'value' => $value];
|
||||
$this->configs[] = ['target' => 'ip', 'value' => $value];
|
||||
}
|
||||
|
||||
public function addIPRange(string $value)
|
||||
{
|
||||
$this->configs[] = (object)['target' => 'ip_range', 'value' => $value];
|
||||
$this->configs[] = ['target' => 'ip_range', 'value' => $value];
|
||||
}
|
||||
|
||||
public function getArray(): array
|
||||
|
||||
@@ -4,9 +4,12 @@ namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Configurations\Configurations;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class AccessRules implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -77,10 +80,10 @@ class AccessRules implements API
|
||||
$query['notes'] = $notes;
|
||||
}
|
||||
|
||||
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query, []);
|
||||
$body = json_decode($data->getBody());
|
||||
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query);
|
||||
$this->body = json_decode($data->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function createRule(
|
||||
@@ -91,18 +94,18 @@ class AccessRules implements API
|
||||
): bool {
|
||||
$options = [
|
||||
'mode' => $mode,
|
||||
'configuration' => (object) $configuration->getArray()
|
||||
'configuration' => $configuration->getArray()
|
||||
];
|
||||
|
||||
if ($notes !== null) {
|
||||
$options['notes'] = $notes;
|
||||
}
|
||||
|
||||
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', [], $options);
|
||||
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $options);
|
||||
|
||||
$body = json_decode($query->getBody());
|
||||
$this->body = json_decode($query->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -123,11 +126,11 @@ class AccessRules implements API
|
||||
$options['notes'] = $notes;
|
||||
}
|
||||
|
||||
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, [], $options);
|
||||
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
|
||||
|
||||
$body = json_decode($query->getBody());
|
||||
$this->body = json_decode($query->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -140,11 +143,11 @@ class AccessRules implements API
|
||||
'cascade' => $cascade
|
||||
];
|
||||
|
||||
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, [], $options);
|
||||
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
|
||||
|
||||
$body = json_decode($data->getBody());
|
||||
$this->body = json_decode($data->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class CustomHostnames implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -33,15 +36,15 @@ class CustomHostnames implements API
|
||||
{
|
||||
$options = [
|
||||
'hostname' => $hostname,
|
||||
'ssl' => (object)[
|
||||
'ssl' => [
|
||||
'method' => $sslMethod,
|
||||
'type' => $sslType
|
||||
]
|
||||
];
|
||||
|
||||
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', [], $options);
|
||||
$body = json_decode($zone->getBody());
|
||||
return $body->result;
|
||||
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,10 +90,10 @@ class CustomHostnames implements API
|
||||
$query['direction'] = $direction;
|
||||
}
|
||||
|
||||
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query, []);
|
||||
$body = json_decode($zone->getBody());
|
||||
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,10 +103,10 @@ class CustomHostnames implements API
|
||||
*/
|
||||
public function getHostname(string $zoneID, string $hostnameID)
|
||||
{
|
||||
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, [], []);
|
||||
$body = json_decode($zone->getBody());
|
||||
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,12 +131,12 @@ class CustomHostnames implements API
|
||||
}
|
||||
|
||||
$options = [
|
||||
'ssl' => (object)$query
|
||||
'ssl' => $query
|
||||
];
|
||||
|
||||
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, [], $options);
|
||||
$body = json_decode($zone->getBody());
|
||||
return $body->result;
|
||||
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,8 +146,8 @@ class CustomHostnames implements API
|
||||
*/
|
||||
public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
|
||||
{
|
||||
$zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, [], []);
|
||||
$body = json_decode($zone->getBody());
|
||||
return $body;
|
||||
$zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
return $this->body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class DNS implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -29,6 +32,7 @@ class DNS implements API
|
||||
* @param int $ttl
|
||||
* @param bool $proxied
|
||||
* @param string $priority
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function addRecord(
|
||||
@@ -38,7 +42,8 @@ class DNS implements API
|
||||
string $content,
|
||||
int $ttl = 0,
|
||||
bool $proxied = true,
|
||||
string $priority = ''
|
||||
string $priority = '',
|
||||
array $data = []
|
||||
): bool {
|
||||
$options = [
|
||||
'type' => $type,
|
||||
@@ -52,14 +57,18 @@ class DNS implements API
|
||||
}
|
||||
|
||||
if (!empty($priority)) {
|
||||
$options['priority'] = $priority;
|
||||
$options['priority'] = (int)$priority;
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
$options['data'] = $data;
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options);
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -103,32 +112,33 @@ class DNS implements API
|
||||
$query['direction'] = $direction;
|
||||
}
|
||||
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
||||
{
|
||||
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
|
||||
return json_decode($response->getBody());
|
||||
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
|
||||
$this->body = json_decode($response->getBody());
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function deleteRecord(string $zoneID, string $recordID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class IPs implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -21,9 +24,9 @@ class IPs implements API
|
||||
|
||||
public function listIPs(): \stdClass
|
||||
{
|
||||
$ips = $this->adapter->get('ips', [], []);
|
||||
$body = json_decode($ips->getBody());
|
||||
$ips = $this->adapter->get('ips');
|
||||
$this->body = json_decode($ips->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,12 @@ namespace Cloudflare\API\Endpoints;
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Configurations\PageRulesActions;
|
||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class PageRules implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -52,11 +55,11 @@ class PageRules implements API
|
||||
}
|
||||
|
||||
|
||||
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', [], $options);
|
||||
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', $options);
|
||||
|
||||
$body = json_decode($query->getBody());
|
||||
$this->body = json_decode($query->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -93,17 +96,17 @@ class PageRules implements API
|
||||
'match' => $match
|
||||
];
|
||||
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function updatePageRule(
|
||||
@@ -132,11 +135,11 @@ class PageRules implements API
|
||||
}
|
||||
|
||||
|
||||
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', [], $options);
|
||||
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', $options);
|
||||
|
||||
$body = json_decode($query->getBody());
|
||||
$this->body = json_decode($query->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -145,11 +148,11 @@ class PageRules implements API
|
||||
|
||||
public function deletePageRule(string $zoneID, string $ruleID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class Railgun implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -26,10 +29,10 @@ class Railgun implements API
|
||||
'name' => $name,
|
||||
];
|
||||
|
||||
$user = $this->adapter->post('railguns', [], $query);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->post('railguns', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body;
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function list(
|
||||
@@ -46,28 +49,28 @@ class Railgun implements API
|
||||
$query['direction'] = $direction;
|
||||
}
|
||||
|
||||
$user = $this->adapter->get('railguns', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('railguns', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function get(
|
||||
string $railgunID
|
||||
): \stdClass {
|
||||
$user = $this->adapter->get('railguns/' . $railgunID, [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('railguns/' . $railgunID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getZones(
|
||||
string $railgunID
|
||||
): \stdClass {
|
||||
$user = $this->adapter->get('railguns/' . $railgunID . '/zones', [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('railguns/' . $railgunID . '/zones');
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function update(
|
||||
@@ -78,19 +81,19 @@ class Railgun implements API
|
||||
'enabled' => $status
|
||||
];
|
||||
|
||||
$user = $this->adapter->patch('railguns/' . $railgunID, [], $query);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->patch('railguns/' . $railgunID, $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function delete(
|
||||
string $railgunID
|
||||
): bool {
|
||||
$user = $this->adapter->delete('railguns/' . $railgunID, [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->delete('railguns/' . $railgunID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
70
src/Endpoints/TLS.php
Normal file
70
src/Endpoints/TLS.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Jurgen Coetsiers
|
||||
* Date: 21/10/2018
|
||||
* Time: 09:10
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
|
||||
class TLS implements API
|
||||
{
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function enableTLS13($zoneID)
|
||||
{
|
||||
$return = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/settings/tls_1_3',
|
||||
['value' => 'on']
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function disableTLS13($zoneID)
|
||||
{
|
||||
$return = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/settings/tls_1_3',
|
||||
['value' => 'off']
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function changeMinimumTLSVersion($zoneID, $minimumVersion)
|
||||
{
|
||||
$return = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/settings/min_tls_version',
|
||||
[
|
||||
'value' => $minimumVersion
|
||||
]
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,12 @@ namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Configurations\Configurations;
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class UARules implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -30,10 +33,10 @@ class UARules implements API
|
||||
'per_page' => $perPage
|
||||
];
|
||||
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function createRule(
|
||||
@@ -56,11 +59,11 @@ class UARules implements API
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', [], $options);
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,9 +72,9 @@ class UARules implements API
|
||||
|
||||
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function updateRule(
|
||||
@@ -91,11 +94,11 @@ class UARules implements API
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], $options);
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -104,11 +107,11 @@ class UARules implements API
|
||||
|
||||
public function deleteRule(string $zoneID, string $ruleID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], []);
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class User implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -20,9 +23,9 @@ class User implements API
|
||||
|
||||
public function getUserDetails(): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('user', [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
$user = $this->adapter->get('user');
|
||||
$this->body = json_decode($user->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getUserID(): string
|
||||
@@ -37,7 +40,8 @@ class User implements API
|
||||
|
||||
public function updateUserDetails(array $details): \stdClass
|
||||
{
|
||||
$response = $this->adapter->patch('user', [], $details);
|
||||
return json_decode($response->getBody());
|
||||
$response = $this->adapter->patch('user', $details);
|
||||
$this->body = json_decode($response->getBody());
|
||||
return $this->body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class WAF implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -41,10 +44,10 @@ class WAF implements API
|
||||
$query['direction'] = $direction;
|
||||
}
|
||||
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
|
||||
@@ -52,10 +55,10 @@ class WAF implements API
|
||||
string $zoneID,
|
||||
string $packageID
|
||||
): \stdClass {
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID, [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getRules(
|
||||
@@ -80,10 +83,10 @@ class WAF implements API
|
||||
if (!empty($direction)) {
|
||||
$query['direction'] = $direction;
|
||||
}
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function getRuleInfo(
|
||||
@@ -91,14 +94,10 @@ class WAF implements API
|
||||
string $packageID,
|
||||
string $ruleID
|
||||
): \stdClass {
|
||||
$user = $this->adapter->get(
|
||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
||||
[],
|
||||
[]
|
||||
);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function updateRule(
|
||||
@@ -113,12 +112,11 @@ class WAF implements API
|
||||
|
||||
$user = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
||||
[],
|
||||
$query
|
||||
);
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getGroups(
|
||||
@@ -146,12 +144,11 @@ class WAF implements API
|
||||
|
||||
$user = $this->adapter->get(
|
||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
|
||||
$query,
|
||||
[]
|
||||
$query
|
||||
);
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function getGroupInfo(
|
||||
@@ -159,14 +156,10 @@ class WAF implements API
|
||||
string $packageID,
|
||||
string $groupID
|
||||
): \stdClass {
|
||||
$user = $this->adapter->get(
|
||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
||||
[],
|
||||
[]
|
||||
);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function updateGroup(
|
||||
@@ -181,11 +174,10 @@ class WAF implements API
|
||||
|
||||
$user = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
||||
[],
|
||||
$query
|
||||
);
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $body->result;
|
||||
return $this->body->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class ZoneLockdown implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -29,10 +32,10 @@ class ZoneLockdown implements API
|
||||
'per_page' => $perPage
|
||||
];
|
||||
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function createLockdown(
|
||||
@@ -55,11 +58,11 @@ class ZoneLockdown implements API
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', [], $options);
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,9 +71,9 @@ class ZoneLockdown implements API
|
||||
|
||||
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
|
||||
$this->body = json_decode($user->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function updateLockdown(
|
||||
@@ -90,11 +93,11 @@ class ZoneLockdown implements API
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], $options);
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -103,11 +106,11 @@ class ZoneLockdown implements API
|
||||
|
||||
public function deleteLockdown(string $zoneID, string $lockdownID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class Zones implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -35,20 +38,20 @@ class Zones implements API
|
||||
];
|
||||
|
||||
if (!empty($organizationID)) {
|
||||
$options['organization'] = (object)['id' => $organizationID];
|
||||
$options['organization'] = ['id' => $organizationID];
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones', [], $options);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
$user = $this->adapter->post('zones', $options);
|
||||
$this->body = json_decode($user->getBody());
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function activationCheck(string $zoneID): bool
|
||||
{
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check');
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -86,10 +89,10 @@ class Zones implements API
|
||||
$query['direction'] = $direction;
|
||||
}
|
||||
|
||||
$user = $this->adapter->get('zones', $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
$user = $this->adapter->get('zones', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function getZoneID(string $name = ''): string
|
||||
@@ -114,9 +117,11 @@ class Zones implements API
|
||||
*/
|
||||
public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', string $until = '0', bool $continuous = true): \stdClass
|
||||
{
|
||||
$response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)], []);
|
||||
$response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)]);
|
||||
|
||||
return json_decode($response->getBody())->result;
|
||||
$this->body = $response->getBody();
|
||||
|
||||
return json_decode($this->body)->result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,11 +133,11 @@ class Zones implements API
|
||||
*/
|
||||
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
|
||||
{
|
||||
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ['value' => $enable ? 'on' : 'off']);
|
||||
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', ['value' => $enable ? 'on' : 'off']);
|
||||
|
||||
$body = json_decode($response->getBody());
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
if ($this->body->success) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -147,33 +152,41 @@ class Zones implements API
|
||||
*/
|
||||
public function cachePurgeEverything(string $zoneID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ['purge_everything' => true]);
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', ['purge_everything' => true]);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function cachePurge(string $zoneID, array $files = null, array $tags = null): bool
|
||||
public function cachePurge(string $zoneID, array $files = null, array $tags = null, array $hosts = null): bool
|
||||
{
|
||||
if ($files === null && $tags === null) {
|
||||
throw new EndpointException('No files or tags to purge.');
|
||||
if ($files === null && $tags === null && $hosts === null) {
|
||||
throw new EndpointException('No files, tags or hosts to purge.');
|
||||
}
|
||||
|
||||
$options = [
|
||||
'files' => $files,
|
||||
'tags' => $tags
|
||||
];
|
||||
$options = [];
|
||||
if (!is_null($files)) {
|
||||
$options['files'] = $files;
|
||||
}
|
||||
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], $options);
|
||||
if (!is_null($tags)) {
|
||||
$options['tags'] = $tags;
|
||||
}
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
if (!is_null($hosts)) {
|
||||
$options['hosts'] = $hosts;
|
||||
}
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', $options);
|
||||
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
13
src/Traits/BodyAccessorTrait.php
Normal file
13
src/Traits/BodyAccessorTrait.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Traits;
|
||||
|
||||
trait BodyAccessorTrait
|
||||
{
|
||||
private $body;
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class GuzzleTest extends TestCase
|
||||
|
||||
public function testPost()
|
||||
{
|
||||
$response = $this->client->post('https://httpbin.org/post', [], ['X-Post-Test' => 'Testing a POST request.']);
|
||||
$response = $this->client->post('https://httpbin.org/post', ['X-Post-Test' => 'Testing a POST request.']);
|
||||
|
||||
$headers = $response->getHeaders();
|
||||
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||
@@ -52,7 +52,7 @@ class GuzzleTest extends TestCase
|
||||
|
||||
public function testPut()
|
||||
{
|
||||
$response = $this->client->put('https://httpbin.org/put', [], ['X-Put-Test' => 'Testing a PUT request.']);
|
||||
$response = $this->client->put('https://httpbin.org/put', ['X-Put-Test' => 'Testing a PUT request.']);
|
||||
|
||||
$headers = $response->getHeaders();
|
||||
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||
@@ -65,7 +65,6 @@ class GuzzleTest extends TestCase
|
||||
{
|
||||
$response = $this->client->patch(
|
||||
'https://httpbin.org/patch',
|
||||
[],
|
||||
['X-Patch-Test' => 'Testing a PATCH request.']
|
||||
);
|
||||
|
||||
@@ -80,7 +79,6 @@ class GuzzleTest extends TestCase
|
||||
{
|
||||
$response = $this->client->delete(
|
||||
'https://httpbin.org/delete',
|
||||
[],
|
||||
['X-Delete-Test' => 'Testing a DELETE request.']
|
||||
);
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ class ConfigurationsUARulesTest extends TestCase
|
||||
$array = $configuration->getArray();
|
||||
$this->assertCount(1, $array);
|
||||
|
||||
$this->assertObjectHasAttribute('target', $array[0]);
|
||||
$this->assertEquals('ua', $array[0]->target);
|
||||
$this->assertObjectHasAttribute('value', $array[0]);
|
||||
$this->assertArrayHasKey('target', $array[0]);
|
||||
$this->assertEquals('ua', $array[0]['target']);
|
||||
$this->assertArrayHasKey('value', $array[0]);
|
||||
$this->assertEquals(
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
|
||||
$array[0]->value
|
||||
$array[0]['value']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,19 @@ class ConfigurationsZoneLockdownTest extends TestCase
|
||||
$array = $configuration->getArray();
|
||||
$this->assertCount(1, $array);
|
||||
|
||||
$this->assertObjectHasAttribute('target', $array[0]);
|
||||
$this->assertEquals('ip', $array[0]->target);
|
||||
$this->assertObjectHasAttribute('value', $array[0]);
|
||||
$this->assertEquals('1.2.3.4', $array[0]->value);
|
||||
$this->assertArrayHasKey('target', $array[0]);
|
||||
$this->assertEquals('ip', $array[0]['target']);
|
||||
$this->assertArrayHasKey('value', $array[0]);
|
||||
$this->assertEquals('1.2.3.4', $array[0]['value']);
|
||||
|
||||
$configuration->addIPRange('1.2.3.4/24');
|
||||
|
||||
$array = $configuration->getArray();
|
||||
$this->assertCount(2, $array);
|
||||
|
||||
$this->assertObjectHasAttribute('target', $array[1]);
|
||||
$this->assertEquals('ip_range', $array[1]->target);
|
||||
$this->assertObjectHasAttribute('value', $array[1]);
|
||||
$this->assertEquals('1.2.3.4/24', $array[1]->value);
|
||||
$this->assertArrayHasKey('target', $array[1]);
|
||||
$this->assertEquals('ip_range', $array[1]['target']);
|
||||
$this->assertArrayHasKey('value', $array[1]);
|
||||
$this->assertEquals('1.2.3.4/24', $array[1]['value']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ class PageRulesActionTest extends TestCase
|
||||
$configuration = $actions->getArray();
|
||||
|
||||
$this->assertCount(1, $configuration);
|
||||
$this->assertEquals($identifier, $configuration[0]->id);
|
||||
$this->assertEquals($statusCode, $configuration[0]->value->status_code);
|
||||
$this->assertEquals($forwardingURL, $configuration[0]->value->url);
|
||||
$this->assertEquals($identifier, $configuration[0]['id']);
|
||||
$this->assertEquals($statusCode, $configuration[0]['value']['status_code']);
|
||||
$this->assertEquals($forwardingURL, $configuration[0]['value']['url']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class PageRulesTargetTest extends TestCase
|
||||
$array = $targets->getArray();
|
||||
|
||||
$this->assertCount(1, $array);
|
||||
$this->assertEquals('junade.com/*', $array[0]->constraint->value);
|
||||
$this->assertEquals('matches', $array[0]->constraint->operator);
|
||||
$this->assertEquals('junade.com/*', $array[0]['constraint']['value']);
|
||||
$this->assertEquals('matches', $array[0]['constraint']['operator']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ class AccessRulesTest extends TestCase
|
||||
'page' => 1,
|
||||
'per_page' => 50,
|
||||
'match' => 'all'
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||
@@ -29,6 +28,7 @@ class AccessRulesTest extends TestCase
|
||||
|
||||
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $zones->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testCreateRule()
|
||||
@@ -45,10 +45,9 @@ class AccessRulesTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'mode' => 'challenge',
|
||||
'configuration' => (object) $config->getArray(),
|
||||
'configuration' => $config->getArray(),
|
||||
'notes' => 'This rule is on because of an event that occured on date X',
|
||||
])
|
||||
);
|
||||
@@ -60,6 +59,7 @@ class AccessRulesTest extends TestCase
|
||||
$config,
|
||||
'This rule is on because of an event that occured on date X'
|
||||
);
|
||||
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testUpdateRule()
|
||||
@@ -73,7 +73,6 @@ class AccessRulesTest extends TestCase
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'mode' => 'challenge',
|
||||
'notes' => 'This rule is on because of an event that occured on date X',
|
||||
@@ -87,6 +86,7 @@ class AccessRulesTest extends TestCase
|
||||
'challenge',
|
||||
'This rule is on because of an event that occured on date X'
|
||||
);
|
||||
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testDeleteRule()
|
||||
@@ -100,7 +100,6 @@ class AccessRulesTest extends TestCase
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'cascade' => 'none'
|
||||
])
|
||||
@@ -108,5 +107,6 @@ class AccessRulesTest extends TestCase
|
||||
|
||||
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b');
|
||||
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,9 @@ class CustomHostnamesTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'hostname' => 'app.example.com',
|
||||
'ssl' => (object)[
|
||||
'ssl' => [
|
||||
'method' => 'http',
|
||||
'type' => 'dv'
|
||||
]
|
||||
@@ -33,6 +32,7 @@ class CustomHostnamesTest extends TestCase
|
||||
|
||||
$hostname = new CustomHostnames($mock);
|
||||
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv');
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testListHostnames()
|
||||
@@ -54,8 +54,7 @@ class CustomHostnamesTest extends TestCase
|
||||
'order' => 'ssl',
|
||||
'direction' => 'desc',
|
||||
'ssl' => 0
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||
@@ -66,6 +65,7 @@ class CustomHostnamesTest extends TestCase
|
||||
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testGetHostname()
|
||||
@@ -78,9 +78,7 @@ class CustomHostnamesTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||
@@ -88,6 +86,7 @@ class CustomHostnamesTest extends TestCase
|
||||
|
||||
$this->assertObjectHasAttribute('id', $result);
|
||||
$this->assertObjectHasAttribute('hostname', $result);
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testUpdateHostname()
|
||||
@@ -101,9 +100,8 @@ class CustomHostnamesTest extends TestCase
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'ssl' => (object)[
|
||||
'ssl' => [
|
||||
'method' => 'http',
|
||||
'type' => 'dv'
|
||||
]
|
||||
@@ -115,6 +113,7 @@ class CustomHostnamesTest extends TestCase
|
||||
|
||||
$this->assertObjectHasAttribute('id', $result);
|
||||
$this->assertObjectHasAttribute('hostname', $result);
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testDeleteHostname()
|
||||
@@ -127,14 +126,13 @@ class CustomHostnamesTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||
$result = $zones->deleteHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
|
||||
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id);
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ class DNSTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'type' => 'A',
|
||||
'name' => 'example.com',
|
||||
@@ -44,16 +43,16 @@ class DNSTest extends TestCase
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all',
|
||||
'type' => 'A',
|
||||
'name' => 'example.com',
|
||||
'content' => '127.0.0.1',
|
||||
'order' => 'type',
|
||||
'direction' => 'desc']),
|
||||
$this->equalTo([])
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all',
|
||||
'type' => 'A',
|
||||
'name' => 'example.com',
|
||||
'content' => '127.0.0.1',
|
||||
'order' => 'type',
|
||||
'direction' => 'desc',
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||
@@ -64,6 +63,7 @@ class DNSTest extends TestCase
|
||||
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testGetDNSRecordDetails()
|
||||
@@ -76,14 +76,14 @@ class DNSTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59')
|
||||
);
|
||||
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||
$result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testUpdateDNSRecord()
|
||||
@@ -105,7 +105,6 @@ class DNSTest extends TestCase
|
||||
->method('put')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo($details)
|
||||
);
|
||||
|
||||
@@ -113,6 +112,7 @@ class DNSTest extends TestCase
|
||||
$result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details);
|
||||
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
||||
|
||||
foreach ($details as $property => $value) {
|
||||
$this->assertEquals($result->result->{ $property }, $value);
|
||||
|
||||
@@ -18,13 +18,14 @@ class IPsTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('ips'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('ips')
|
||||
);
|
||||
|
||||
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||
$ips = $ips->listIPs();
|
||||
$ipsMock = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||
$ips = $ipsMock->listIPs();
|
||||
$this->assertObjectHasAttribute('ipv4_cidrs', $ips);
|
||||
$this->assertObjectHasAttribute('ipv6_cidrs', $ips);
|
||||
$this->assertObjectHasAttribute('ipv4_cidrs', $ipsMock->getBody()->result);
|
||||
$this->assertObjectHasAttribute('ipv6_cidrs', $ipsMock->getBody()->result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ class PageRulesTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'targets' => $target->getArray(),
|
||||
'actions' => $action->getArray(),
|
||||
@@ -36,6 +35,7 @@ class PageRulesTest extends TestCase
|
||||
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testListPageRules()
|
||||
@@ -54,12 +54,12 @@ class PageRulesTest extends TestCase
|
||||
'order' => 'status',
|
||||
'direction' => 'desc',
|
||||
'match' => 'all'
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testGetPageRuleDetails()
|
||||
@@ -72,12 +72,12 @@ class PageRulesTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
|
||||
);
|
||||
|
||||
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testUpdatePageRule()
|
||||
@@ -95,7 +95,6 @@ class PageRulesTest extends TestCase
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'targets' => $target->getArray(),
|
||||
'actions' => $action->getArray(),
|
||||
@@ -108,6 +107,7 @@ class PageRulesTest extends TestCase
|
||||
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testDeletePageRule()
|
||||
@@ -120,14 +120,13 @@ class PageRulesTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
|
||||
);
|
||||
|
||||
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ class RailgunTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('railguns'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo(['name' => $details['name']])
|
||||
);
|
||||
|
||||
@@ -35,6 +34,7 @@ class RailgunTest extends TestCase
|
||||
foreach ($details as $property => $value) {
|
||||
$this->assertEquals($result->result->{ $property }, $value);
|
||||
}
|
||||
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testlist()
|
||||
@@ -52,8 +52,7 @@ class RailgunTest extends TestCase
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'direction' => 'desc'
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||
@@ -61,6 +60,7 @@ class RailgunTest extends TestCase
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertObjectHasAttribute('result_info', $result);
|
||||
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testget()
|
||||
@@ -73,14 +73,14 @@ class RailgunTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
|
||||
);
|
||||
|
||||
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||
$result = $railgun->get('e928d310693a83094309acf9ead50448');
|
||||
|
||||
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testgetZones()
|
||||
@@ -93,9 +93,7 @@ class RailgunTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones')
|
||||
);
|
||||
|
||||
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||
@@ -103,6 +101,7 @@ class RailgunTest extends TestCase
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertObjectHasAttribute('result_info', $result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $railgun->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testupdate()
|
||||
@@ -120,7 +119,6 @@ class RailgunTest extends TestCase
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo($details)
|
||||
);
|
||||
|
||||
@@ -128,6 +126,7 @@ class RailgunTest extends TestCase
|
||||
$result = $waf->update('e928d310693a83094309acf9ead50448', true);
|
||||
|
||||
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testdelete()
|
||||
@@ -140,12 +139,11 @@ class RailgunTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
|
||||
);
|
||||
|
||||
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||
$waf->delete('e928d310693a83094309acf9ead50448');
|
||||
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
71
tests/Endpoints/TLSTest.php
Normal file
71
tests/Endpoints/TLSTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Jurgen Coetsiers
|
||||
* Date: 21/10/2018
|
||||
* Time: 09:09
|
||||
*/
|
||||
|
||||
class TLSTest extends TestCase
|
||||
{
|
||||
public function testEnableTLS13()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/enableTLS13.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('patch')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_1_3'),
|
||||
$this->equalTo(['value' => 'on'])
|
||||
);
|
||||
|
||||
$zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||
$result = $zoneTLSSettings->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testDisableTLS13()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/disableTLS13.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('patch')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_1_3'),
|
||||
$this->equalTo(['value' => 'off'])
|
||||
);
|
||||
|
||||
$zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||
$result = $zoneTLSSettings->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testChangeMinimimTLSVersion()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeMinimumTLSVersion.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('patch')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/min_tls_version'),
|
||||
$this->equalTo(['value' => '1.1'])
|
||||
);
|
||||
|
||||
$zoneTLSSettings = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||
$result = $zoneTLSSettings->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1');
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,7 @@ class UARulesTest extends TestCase
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||
@@ -34,6 +33,7 @@ class UARulesTest extends TestCase
|
||||
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testCreateRule()
|
||||
@@ -50,7 +50,6 @@ class UARulesTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'mode' => 'js_challenge',
|
||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||
@@ -67,6 +66,7 @@ class UARulesTest extends TestCase
|
||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
|
||||
);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function getRuleDetails()
|
||||
@@ -79,14 +79,14 @@ class UARulesTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
|
||||
);
|
||||
|
||||
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||
$result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testUpdateRule()
|
||||
@@ -103,7 +103,6 @@ class UARulesTest extends TestCase
|
||||
->method('put')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'mode' => 'js_challenge',
|
||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||
@@ -120,6 +119,7 @@ class UARulesTest extends TestCase
|
||||
$config,
|
||||
'Restrict access to these endpoints to requests from a known IP address'
|
||||
);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testDeleteRule()
|
||||
@@ -132,12 +132,11 @@ class UARulesTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
|
||||
);
|
||||
|
||||
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class UserTest extends TestCase
|
||||
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
|
||||
$this->assertObjectHasAttribute('email', $details);
|
||||
$this->assertEquals('user@example.com', $details->email);
|
||||
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testGetUserID()
|
||||
@@ -32,6 +33,7 @@ class UserTest extends TestCase
|
||||
|
||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
|
||||
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testGetUserEmail()
|
||||
@@ -45,6 +47,7 @@ class UserTest extends TestCase
|
||||
|
||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||
$this->assertEquals('user@example.com', $user->getUserEmail());
|
||||
$this->assertEquals('user@example.com', $user->getBody()->result->email);
|
||||
}
|
||||
|
||||
public function testUpdateUserDetails()
|
||||
@@ -56,9 +59,10 @@ class UserTest extends TestCase
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('patch')
|
||||
->with($this->equalTo('user'), $this->equalTo([]), $this->equalTo(['email' => 'user2@example.com']));
|
||||
->with($this->equalTo('user'), $this->equalTo(['email' => 'user2@example.com']));
|
||||
|
||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||
$user->updateUserDetails(['email' => 'user2@example.com']);
|
||||
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ class WAFTest extends TestCase
|
||||
'match' => 'all',
|
||||
'order' => 'status',
|
||||
'direction' => 'desc'
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||
@@ -37,6 +36,7 @@ class WAFTest extends TestCase
|
||||
|
||||
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testgetPackageInfo()
|
||||
@@ -49,14 +49,14 @@ class WAFTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b')
|
||||
);
|
||||
|
||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||
$result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b');
|
||||
|
||||
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id);
|
||||
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testgetRules()
|
||||
@@ -76,8 +76,7 @@ class WAFTest extends TestCase
|
||||
'match' => 'all',
|
||||
'order' => 'status',
|
||||
'direction' => 'desc'
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||
@@ -88,6 +87,7 @@ class WAFTest extends TestCase
|
||||
|
||||
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $waf->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testgetRuleInfo()
|
||||
@@ -100,14 +100,14 @@ class WAFTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023')
|
||||
);
|
||||
|
||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||
$result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023');
|
||||
|
||||
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
|
||||
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testupdateRule()
|
||||
@@ -125,7 +125,6 @@ class WAFTest extends TestCase
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo($details)
|
||||
);
|
||||
|
||||
@@ -137,6 +136,7 @@ class WAFTest extends TestCase
|
||||
foreach ($details as $property => $value) {
|
||||
$this->assertEquals($result->{ $property }, $value);
|
||||
}
|
||||
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function getGroups()
|
||||
@@ -156,8 +156,7 @@ class WAFTest extends TestCase
|
||||
'match' => 'all',
|
||||
'order' => 'status',
|
||||
'direction' => 'desc'
|
||||
]),
|
||||
$this->equalTo([])
|
||||
])
|
||||
);
|
||||
|
||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||
@@ -168,6 +167,7 @@ class WAFTest extends TestCase
|
||||
|
||||
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testgetGroupInfo()
|
||||
@@ -180,14 +180,14 @@ class WAFTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5')
|
||||
);
|
||||
|
||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||
$result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5');
|
||||
|
||||
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
|
||||
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testupdateGroup()
|
||||
@@ -205,7 +205,6 @@ class WAFTest extends TestCase
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo($details)
|
||||
);
|
||||
|
||||
@@ -217,5 +216,6 @@ class WAFTest extends TestCase
|
||||
foreach ($details as $property => $value) {
|
||||
$this->assertEquals($result->{ $property }, $value);
|
||||
}
|
||||
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,10 @@ class ZoneLockdownTest extends TestCase
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||
@@ -34,6 +33,7 @@ class ZoneLockdownTest extends TestCase
|
||||
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testAddLockdown()
|
||||
@@ -50,7 +50,6 @@ class ZoneLockdownTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'urls' => ['api.mysite.com/some/endpoint*'],
|
||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||
@@ -67,6 +66,7 @@ class ZoneLockdownTest extends TestCase
|
||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||
'Restrict access to these endpoints to requests from a known IP address'
|
||||
);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testGetRecordDetails()
|
||||
@@ -79,14 +79,14 @@ class ZoneLockdownTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
|
||||
);
|
||||
|
||||
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||
$result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testUpdateLockdown()
|
||||
@@ -103,7 +103,6 @@ class ZoneLockdownTest extends TestCase
|
||||
->method('put')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'urls' => ['api.mysite.com/some/endpoint*'],
|
||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||
@@ -120,6 +119,7 @@ class ZoneLockdownTest extends TestCase
|
||||
$config,
|
||||
'Restrict access to these endpoints to requests from a known IP address'
|
||||
);
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testDeleteLockdown()
|
||||
@@ -135,12 +135,11 @@ class ZoneLockdownTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
|
||||
);
|
||||
|
||||
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||
$zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ class ZonesTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo(['name' => 'example.com', 'jump_start' => false])
|
||||
);
|
||||
|
||||
@@ -38,16 +37,16 @@ class ZonesTest extends TestCase
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([
|
||||
'name' => 'example.com',
|
||||
'jump_start' => true,
|
||||
'organization' => (object)['id' => '01a7362d577a6c3019a474fd6f485823']
|
||||
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823');
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testActivationTest()
|
||||
@@ -60,15 +59,14 @@ class ZonesTest extends TestCase
|
||||
$mock->expects($this->once())
|
||||
->method('put')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check')
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testListZones()
|
||||
@@ -82,16 +80,15 @@ class ZonesTest extends TestCase
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all',
|
||||
'name' => 'example.com',
|
||||
'status' => 'active',
|
||||
'order' => 'status',
|
||||
'direction' => 'desc'
|
||||
]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all',
|
||||
'name' => 'example.com',
|
||||
'status' => 'active',
|
||||
'order' => 'status',
|
||||
'direction' => 'desc',
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
@@ -102,6 +99,7 @@ class ZonesTest extends TestCase
|
||||
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testGetZoneID()
|
||||
@@ -115,19 +113,19 @@ class ZonesTest extends TestCase
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all',
|
||||
'name' => 'example.com',
|
||||
]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'match' => 'all',
|
||||
'name' => 'example.com',
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->getZoneID('example.com');
|
||||
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testGetAnalyticsDashboard()
|
||||
@@ -141,8 +139,7 @@ class ZonesTest extends TestCase
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
|
||||
$this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)]),
|
||||
$this->equalTo([])
|
||||
$this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
@@ -151,7 +148,7 @@ class ZonesTest extends TestCase
|
||||
$this->assertObjectHasAttribute('since', $analytics->totals);
|
||||
$this->assertObjectHasAttribute('since', $analytics->timeseries[0]);
|
||||
}
|
||||
|
||||
|
||||
public function testChangeDevelopmentMode()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json');
|
||||
@@ -163,7 +160,6 @@ class ZonesTest extends TestCase
|
||||
->method('patch')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo(['value' => 'on'])
|
||||
);
|
||||
|
||||
@@ -171,6 +167,7 @@ class ZonesTest extends TestCase
|
||||
$result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('development_mode', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testCachePurgeEverything()
|
||||
@@ -184,7 +181,6 @@ class ZonesTest extends TestCase
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||
$this->equalTo([]),
|
||||
$this->equalTo(['purge_everything' => true])
|
||||
);
|
||||
|
||||
@@ -192,5 +188,59 @@ class ZonesTest extends TestCase
|
||||
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testCachePurgeHost()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||
$this->equalTo(
|
||||
[
|
||||
'files' => [],
|
||||
'tags' => [],
|
||||
'hosts' => ['dash.cloudflare.com']
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testCachePurge()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||
$this->equalTo(['files' => [
|
||||
'https://example.com/file.jpg',
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
|
||||
'https://example.com/file.jpg',
|
||||
]);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
8
tests/Fixtures/Endpoints/cachePurge.json
Normal file
8
tests/Fixtures/Endpoints/cachePurge.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
||||
}
|
||||
}
|
||||
8
tests/Fixtures/Endpoints/cachePurgeHost.json
Normal file
8
tests/Fixtures/Endpoints/cachePurgeHost.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353"
|
||||
}
|
||||
}
|
||||
6
tests/Fixtures/Endpoints/changeMinimumTLSVersion.json
Normal file
6
tests/Fixtures/Endpoints/changeMinimumTLSVersion.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": "1.1"
|
||||
}
|
||||
6
tests/Fixtures/Endpoints/disableTLS13.json
Normal file
6
tests/Fixtures/Endpoints/disableTLS13.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": "off"
|
||||
}
|
||||
6
tests/Fixtures/Endpoints/enableTLS13.json
Normal file
6
tests/Fixtures/Endpoints/enableTLS13.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": "on"
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
<?php
|
||||
use GuzzleHttp\Psr7;
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
|
||||
/**
|
||||
* Class TestCase
|
||||
* @SuppressWarnings(PHPMD.NumberOfChildren)
|
||||
*/
|
||||
abstract class TestCase extends PHPUnit_Framework_TestCase
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Returns a PSR7 Stream for a given fixture.
|
||||
|
||||
Reference in New Issue
Block a user