Compare commits
131 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b9738910d | ||
|
|
90a9f51fd6 | ||
|
|
b17ae6e7d0 | ||
|
|
b558622bb5 | ||
|
|
d913aa827f | ||
|
|
6a9a9f55b6 | ||
|
|
1724b66147 | ||
|
|
7343b7cc46 | ||
|
|
bd10d7f833 | ||
|
|
598ba5c1d1 | ||
|
|
ed06650390 | ||
|
|
246925dec2 | ||
|
|
7a7e6dc364 | ||
|
|
5f57b871aa | ||
|
|
31453d8184 | ||
|
|
21b3f20fb1 | ||
|
|
45834c0709 | ||
|
|
c44a26fa35 | ||
|
|
1764856f5b | ||
|
|
79ca15c066 | ||
|
|
63ded280d3 | ||
|
|
fb9d75d94a | ||
|
|
1cf5963445 | ||
|
|
ecb23ccc44 | ||
|
|
b81c67ddc5 | ||
|
|
b46a2f80f5 | ||
|
|
fab0bc7a12 | ||
|
|
6a29d75001 | ||
|
|
99c174bcb3 | ||
|
|
3cfeedbe4d | ||
|
|
7aa3a118af | ||
|
|
ae2c680e85 | ||
|
|
78eadb9a47 | ||
|
|
e1c2539d9a | ||
|
|
471a42d554 | ||
|
|
d9c0a27b7d | ||
|
|
8182aa8810 | ||
|
|
df12f7ba6f | ||
|
|
9d434a23b3 | ||
|
|
f105d38d85 | ||
|
|
910644f88d | ||
|
|
68b9fa3353 | ||
|
|
c394f5ac4d | ||
|
|
e94ab8ddbe | ||
|
|
2b25365988 | ||
|
|
bd92b2a4c0 | ||
|
|
6acf09ba82 | ||
|
|
6410f50f6d | ||
|
|
d6f0eada8c | ||
|
|
6f1ac605f5 | ||
|
|
9311583f43 | ||
|
|
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 | ||
|
|
35ce8eadf1 | ||
|
|
d95573976e | ||
|
|
3bfd5e17f1 | ||
|
|
19a4f481d3 | ||
|
|
9c56941516 | ||
|
|
e18a64e7e4 | ||
|
|
3585dde8ea | ||
|
|
730b0c97ee | ||
|
|
dc53414c2a | ||
|
|
a628cac283 | ||
|
|
0112425a61 | ||
|
|
fe854e1b21 | ||
|
|
45cb8ee539 | ||
|
|
cd2fd73cc3 | ||
|
|
bd83c6d48a | ||
|
|
4e3d307bdd | ||
|
|
99d89e7dc3 | ||
|
|
55e81fe02c | ||
|
|
d00a1d3f44 | ||
|
|
c8e85d2582 | ||
|
|
ff42f334a5 | ||
|
|
dfa299c895 | ||
|
|
e1864a6824 | ||
|
|
c9d21466aa | ||
|
|
b15b4ecc51 | ||
|
|
0aa9f6c05a | ||
|
|
a09478eb2f | ||
|
|
f6cb9a8e30 | ||
|
|
bc9e15a557 | ||
|
|
5caae74370 | ||
|
|
ee4a42ea06 | ||
|
|
90eaea7be2 | ||
|
|
dac1e15e2d | ||
|
|
a4224265d8 | ||
|
|
4f3f82b1ba | ||
|
|
7c9ea4874d | ||
|
|
0920fc48b2 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
|
/.idea
|
||||||
/vendor/
|
/vendor/
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
## Installation
|
## 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
|
## Cloudflare API version 4
|
||||||
|
|
||||||
@@ -18,12 +18,16 @@ Each API call is provided via a similarly named function within various classes
|
|||||||
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
|
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
|
||||||
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
||||||
- [ ] Virtual DNS Management
|
- [ ] Virtual DNS Management
|
||||||
- [ ] Custom hostnames
|
- [x] Custom hostnames
|
||||||
|
- [x] Manage TLS settings
|
||||||
- [x] Zone Lockdown and User-Agent Block rules
|
- [x] Zone Lockdown and User-Agent Block rules
|
||||||
- [ ] Organization Administration
|
- [ ] Organization Administration
|
||||||
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
|
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
|
||||||
- [ ] [Keyless SSL](https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/)
|
- [ ] [Keyless SSL](https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/)
|
||||||
- [ ] [Origin CA](https://blog.cloudflare.com/universal-ssl-encryption-all-the-way-to-the-origin-for-free/)
|
- [ ] [Origin CA](https://blog.cloudflare.com/universal-ssl-encryption-all-the-way-to-the-origin-for-free/)
|
||||||
|
- [x] Crypto
|
||||||
|
- [x] Load Balancers
|
||||||
|
- [x] Firewall Settings
|
||||||
|
|
||||||
Note that this repository is currently under development, additional classes and endpoints being actively added.
|
Note that this repository is currently under development, additional classes and endpoints being actively added.
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^6.2.2",
|
"guzzlehttp/guzzle": "^6.2.2",
|
||||||
"php": ">=7.0.0",
|
"php": ">=7.0.0",
|
||||||
"psr/http-message": "~1.0"
|
"psr/http-message": "~1.0",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "5.7.5",
|
"phpunit/phpunit": "5.7.5",
|
||||||
@@ -28,5 +29,10 @@
|
|||||||
"classmap": [
|
"classmap": [
|
||||||
"tests/"
|
"tests/"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"preferred-install": "dist",
|
||||||
|
"sort-packages": true,
|
||||||
|
"optimize-autoloader": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3002
composer.lock
generated
Normal file
3002
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
phpcbf.phar
Normal file
BIN
phpcbf.phar
Normal file
Binary file not shown.
BIN
phpcs.phar
Normal file
BIN
phpcs.phar
Normal file
Binary file not shown.
@@ -21,55 +21,56 @@ interface Adapter
|
|||||||
* Adapter constructor.
|
* Adapter constructor.
|
||||||
*
|
*
|
||||||
* @param Auth $auth
|
* @param Auth $auth
|
||||||
* @param String $baseURI
|
* @param string $baseURI
|
||||||
*/
|
*/
|
||||||
public function __construct(Auth $auth, String $baseURI);
|
public function __construct(Auth $auth, string $baseURI);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a GET request.
|
* Sends a GET request.
|
||||||
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
|
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
|
||||||
* RFCs, it is never useful).
|
* RFCs, it is never useful).
|
||||||
*
|
*
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @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 string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @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 string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @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 string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @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 string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function delete(String $uri, array $headers, array $body): ResponseInterface;
|
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function __construct(Auth $auth, String $baseURI = null)
|
public function __construct(Auth $auth, string $baseURI = null)
|
||||||
{
|
{
|
||||||
if ($baseURI === null) {
|
if ($baseURI === null) {
|
||||||
$baseURI = "https://api.cloudflare.com/client/v4/";
|
$baseURI = 'https://api.cloudflare.com/client/v4/';
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers = $auth->getHeaders();
|
$headers = $auth->getHeaders();
|
||||||
@@ -37,79 +37,56 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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]);
|
return $this->request('get', $uri, $data, $headers);
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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(
|
return $this->request('post', $uri, $data, $headers);
|
||||||
$uri,
|
|
||||||
[
|
|
||||||
'headers' => $headers,
|
|
||||||
'json' => $body
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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(
|
return $this->request('put', $uri, $data, $headers);
|
||||||
$uri,
|
|
||||||
[
|
|
||||||
'headers' => $headers,
|
|
||||||
'json' => $body
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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(
|
return $this->request('patch', $uri, $data, $headers);
|
||||||
$uri,
|
|
||||||
[
|
|
||||||
'headers' => $headers,
|
|
||||||
'json' => $body
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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(
|
return $this->request('delete', $uri, $data, $headers);
|
||||||
$uri,
|
}
|
||||||
[
|
|
||||||
'headers' => $headers,
|
public function request(string $method, string $uri, array $data = [], array $headers = [])
|
||||||
'json' => $body
|
{
|
||||||
]
|
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);
|
$this->checkError($response);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,14 +98,12 @@ class Guzzle implements Adapter
|
|||||||
throw new JSONException();
|
throw new JSONException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json->errors)) {
|
if (isset($json->errors) && count($json->errors) >= 1) {
|
||||||
foreach ($json->errors as $error) {
|
throw new ResponseException($json->errors[0]->message, $json->errors[0]->code);
|
||||||
throw new ResponseException($error->message, $error->code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json->success) && ($json->success === false)) {
|
if (isset($json->success) && !$json->success) {
|
||||||
throw new ResponseException("Request was unsuccessful.");
|
throw new ResponseException('Request was unsuccessful.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class APIKey implements Auth
|
|||||||
private $email;
|
private $email;
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
|
|
||||||
public function __construct(String $email, String $apiKey)
|
public function __construct(string $email, string $apiKey)
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
$this->apiKey = $apiKey;
|
$this->apiKey = $apiKey;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class UserServiceKey implements Auth
|
|||||||
{
|
{
|
||||||
private $userServiceKey;
|
private $userServiceKey;
|
||||||
|
|
||||||
public function __construct(String $userServiceKey)
|
public function __construct(string $userServiceKey)
|
||||||
{
|
{
|
||||||
$this->userServiceKey = $userServiceKey;
|
$this->userServiceKey = $userServiceKey;
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/Configurations/AccessRules.php
Normal file
33
src/Configurations/AccessRules.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class AccessRules implements Configurations
|
||||||
|
{
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
public function setIP(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'ip', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIPRange(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'ip_range', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCountry(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'country', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setASN(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'asn', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
|
}
|
||||||
178
src/Configurations/LoadBalancer.php
Normal file
178
src/Configurations/LoadBalancer.php
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class LoadBalancer implements Configurations
|
||||||
|
{
|
||||||
|
private $configs = [];
|
||||||
|
|
||||||
|
public function __construct(string $name, array $defaultPools, string $fallbackPool)
|
||||||
|
{
|
||||||
|
$this->setName($name);
|
||||||
|
$this->setDefaultPools($defaultPools);
|
||||||
|
$this->setFallbackPool($fallbackPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name)
|
||||||
|
{
|
||||||
|
$this->configs['name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName():string
|
||||||
|
{
|
||||||
|
return $this->configs['name'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDefaultPools(array $defaultPools)
|
||||||
|
{
|
||||||
|
$this->configs['default_pools'] = $defaultPools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaultPools():array
|
||||||
|
{
|
||||||
|
return $this->configs['default_pools'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFallbackPool(string $fallbackPool)
|
||||||
|
{
|
||||||
|
$this->configs['fallback_pools'] = $fallbackPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFallbackPool():string
|
||||||
|
{
|
||||||
|
return $this->configs['fallback_pools'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSteeringPolicy(string $steeringPolicy = '')
|
||||||
|
{
|
||||||
|
$allowedOptions = ['off', 'geo', 'random', 'dynamic_latency', ''];
|
||||||
|
if (!in_array($steeringPolicy, $allowedOptions)) {
|
||||||
|
throw new ConfigurationsException('Given steering policy value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->configs['steering_policy'] = $steeringPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSteeringPolicy():string
|
||||||
|
{
|
||||||
|
return $this->configs['steering_policy'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDisabled():bool
|
||||||
|
{
|
||||||
|
return !$this->configs['enabled'] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPopPools(array $popPools)
|
||||||
|
{
|
||||||
|
$this->configs['pop_pools'] = $popPools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPopPools():array
|
||||||
|
{
|
||||||
|
return $this->configs['pop_pools'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTtl(int $ttl)
|
||||||
|
{
|
||||||
|
$this->configs['ttl'] = $ttl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTtl():int
|
||||||
|
{
|
||||||
|
return $this->configs['ttl'] ?? 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRegionPools(array $regionPools)
|
||||||
|
{
|
||||||
|
$this->configs['region_pools'] = $regionPools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRegionPools():array
|
||||||
|
{
|
||||||
|
return $this->configs['region_pools'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSessionAffinity(string $sessionAffinity = '')
|
||||||
|
{
|
||||||
|
$allowedOptions = ['none', 'cookie', 'ip_cookie', ''];
|
||||||
|
if (!in_array($sessionAffinity, $allowedOptions)) {
|
||||||
|
throw new ConfigurationsException('Given session affinity value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
|
||||||
|
}
|
||||||
|
$this->configs['session_affinity'] = $sessionAffinity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSessionAffinity():string
|
||||||
|
{
|
||||||
|
return $this->configs['session_affinity'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(string $description = '')
|
||||||
|
{
|
||||||
|
$this->configs['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription():string
|
||||||
|
{
|
||||||
|
return $this->configs['description'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enableProxied()
|
||||||
|
{
|
||||||
|
$this->configs['proxied'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disableProxied()
|
||||||
|
{
|
||||||
|
$this->configs['proxied'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isProxied():bool
|
||||||
|
{
|
||||||
|
return $this->configs['proxied'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSessionAffinityTtl(int $sessionAffinityTtl = 82800)
|
||||||
|
{
|
||||||
|
if ($sessionAffinityTtl > 604800 || $sessionAffinityTtl < 1800) {
|
||||||
|
throw new ConfigurationsException('The value of session affinity ttl must be between 1800 and 604800');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->configs['session_affinity_ttl'] = $sessionAffinityTtl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSessionAffinityTtl():int
|
||||||
|
{
|
||||||
|
return $this->configs['session_affinity_ttl'] ?? 82800;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,28 +14,28 @@ class PageRulesActions implements Configurations
|
|||||||
|
|
||||||
public function setAlwaysOnline(bool $active)
|
public function setAlwaysOnline(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("always_online", [
|
$this->addConfigurationOption('always_online', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAlwaysUseHTTPS(bool $active)
|
public function setAlwaysUseHTTPS(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("always_use_https", [
|
$this->addConfigurationOption('always_use_https', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBrowserCacheTTL(int $ttl)
|
public function setBrowserCacheTTL(int $ttl)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("browser_cache_ttl", [
|
$this->addConfigurationOption('browser_cache_ttl', [
|
||||||
'value' => $ttl
|
'value' => $ttl
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBrowserIntegrityCheck(bool $active)
|
public function setBrowserIntegrityCheck(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("browser_check", [
|
$this->addConfigurationOption('browser_check', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -43,35 +43,35 @@ class PageRulesActions implements Configurations
|
|||||||
public function setBypassCacheOnCookie(string $value)
|
public function setBypassCacheOnCookie(string $value)
|
||||||
{
|
{
|
||||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||||
throw new ConfigurationsException("Invalid cookie string.");
|
throw new ConfigurationsException('Invalid cookie string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("bypass_cache_on_cookie", [
|
$this->addConfigurationOption('bypass_cache_on_cookie', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheByDeviceType(bool $active)
|
public function setCacheByDeviceType(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("cache_by_device_type", [
|
$this->addConfigurationOption('cache_by_device_type', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheKey(string $value)
|
public function setCacheKey(string $value)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("cache_key", [
|
$this->addConfigurationOption('cache_key', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheLevel(string $value)
|
public function setCacheLevel(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
|
if (!in_array($value, ['bypass', 'basic', 'simplified', 'aggressive', 'cache_everything'])) {
|
||||||
throw new ConfigurationsException("Invalid cache level");
|
throw new ConfigurationsException('Invalid cache level');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("cache_level", [
|
$this->addConfigurationOption('cache_level', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -79,31 +79,31 @@ class PageRulesActions implements Configurations
|
|||||||
public function setCacheOnCookie(string $value)
|
public function setCacheOnCookie(string $value)
|
||||||
{
|
{
|
||||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||||
throw new ConfigurationsException("Invalid cookie string.");
|
throw new ConfigurationsException('Invalid cookie string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("cache_on_cookie", [
|
$this->addConfigurationOption('cache_on_cookie', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableApps(bool $active)
|
public function setDisableApps(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("disable_apps", [
|
$this->addConfigurationOption('disable_apps', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisablePerformance(bool $active)
|
public function setDisablePerformance(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("disable_performance", [
|
$this->addConfigurationOption('disable_performance', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableSecurity(bool $active)
|
public function setDisableSecurity(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("disable_security", [
|
$this->addConfigurationOption('disable_security', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -111,17 +111,17 @@ class PageRulesActions implements Configurations
|
|||||||
public function setEdgeCacheTTL(int $value)
|
public function setEdgeCacheTTL(int $value)
|
||||||
{
|
{
|
||||||
if ($value > 2419200) {
|
if ($value > 2419200) {
|
||||||
throw new ConfigurationsException("Edge Cache TTL too high.");
|
throw new ConfigurationsException('Edge Cache TTL too high.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("edge_cache_ttl", [
|
$this->addConfigurationOption('edge_cache_ttl', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEmailObfuscation(bool $active)
|
public function setEmailObfuscation(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("disable_security", [
|
$this->addConfigurationOption('disable_security', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -133,35 +133,37 @@ class PageRulesActions implements Configurations
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("forwarding_url", [
|
$this->addConfigurationOption("forwarding_url", [
|
||||||
'status_code' => $statusCode,
|
'value' => [
|
||||||
'url' => $forwardingUrl,
|
'status_code' => $statusCode,
|
||||||
|
'url' => $forwardingUrl,
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHostHeaderOverride(bool $active)
|
public function setHostHeaderOverride(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("host_header_override", [
|
$this->addConfigurationOption('host_header_override', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHotlinkProtection(bool $active)
|
public function setHotlinkProtection(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("hotlink_protection", [
|
$this->addConfigurationOption('hotlink_protection', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIPGeoLocationHeader(bool $active)
|
public function setIPGeoLocationHeader(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("ip_geolocation", [
|
$this->addConfigurationOption('ip_geolocation', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMinification(bool $html, bool $css, bool $javascript)
|
public function setMinification(bool $html, bool $css, bool $javascript)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("minification", [
|
$this->addConfigurationOption('minification', [
|
||||||
'html' => $this->getBoolAsOnOrOff($html),
|
'html' => $this->getBoolAsOnOrOff($html),
|
||||||
'css' => $this->getBoolAsOnOrOff($css),
|
'css' => $this->getBoolAsOnOrOff($css),
|
||||||
'js' => $this->getBoolAsOnOrOff($javascript),
|
'js' => $this->getBoolAsOnOrOff($javascript),
|
||||||
@@ -170,124 +172,124 @@ class PageRulesActions implements Configurations
|
|||||||
|
|
||||||
public function setMirage(bool $active)
|
public function setMirage(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("mirage", [
|
$this->addConfigurationOption('mirage', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOriginErrorPagePassthru(bool $active)
|
public function setOriginErrorPagePassthru(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("origin_error_page_pass_thru", [
|
$this->addConfigurationOption('origin_error_page_pass_thru', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setQueryStringSort(bool $active)
|
public function setQueryStringSort(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("sort_query_string_for_cache", [
|
$this->addConfigurationOption('sort_query_string_for_cache', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableRailgun(bool $active)
|
public function setDisableRailgun(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("disable_railgun", [
|
$this->addConfigurationOption('disable_railgun', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResolveOverride(bool $value)
|
public function setResolveOverride(bool $value)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("resolve_override", [
|
$this->addConfigurationOption('resolve_override', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRespectStrongEtag(bool $active)
|
public function setRespectStrongEtag(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("respect_strong_etag", [
|
$this->addConfigurationOption('respect_strong_etag', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResponseBuffering(bool $active)
|
public function setResponseBuffering(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("response_buffering", [
|
$this->addConfigurationOption('response_buffering', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRocketLoader(string $value)
|
public function setRocketLoader(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "manual", "automatic"])) {
|
if (!in_array($value, ['off', 'manual', 'automatic'])) {
|
||||||
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
|
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("rocket_loader", [
|
$this->addConfigurationOption('rocket_loader', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSecurityLevel(string $value)
|
public function setSecurityLevel(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
|
if (!in_array($value, ['off', 'essentially_off', 'low', 'medium', 'high', 'under_attack'])) {
|
||||||
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
|
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("security_level", [
|
$this->addConfigurationOption('security_level', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setServerSideExcludes(bool $active)
|
public function setServerSideExcludes(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("server_side_exclude", [
|
$this->addConfigurationOption('server_side_exclude', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSmartErrors(bool $active)
|
public function setSmartErrors(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("smart_errors", [
|
$this->addConfigurationOption('smart_errors', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSSL(string $value)
|
public function setSSL(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
|
if (!in_array($value, ['off', 'flexible', 'full', 'strict', 'origin_pull'])) {
|
||||||
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("smart_errors", [
|
$this->addConfigurationOption('ssl', [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTrueClientIpHeader(bool $active)
|
public function setTrueClientIpHeader(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("true_client_ip_header", [
|
$this->addConfigurationOption('true_client_ip_header', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setWAF(bool $active)
|
public function setWAF(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("waf", [
|
$this->addConfigurationOption('waf', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAutomatedHTTPSRewrites(bool $active)
|
public function setAutomatedHTTPSRewrites(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("automatic_https_rewrites", [
|
$this->addConfigurationOption('automatic_https_rewrites', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOpportunisticEncryption(bool $active)
|
public function setOpportunisticEncryption(bool $active)
|
||||||
{
|
{
|
||||||
$this->addConfigurationOption("opportunistic_encryption", [
|
$this->addConfigurationOption('opportunistic_encryption', [
|
||||||
'value' => $this->getBoolAsOnOrOff($active)
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -301,7 +303,7 @@ class PageRulesActions implements Configurations
|
|||||||
{
|
{
|
||||||
$configuration['id'] = $setting;
|
$configuration['id'] = $setting;
|
||||||
|
|
||||||
array_push($this->configs, (object) $configuration);
|
array_push($this->configs, $configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBoolAsOnOrOff(bool $value): string
|
private function getBoolAsOnOrOff(bool $value): string
|
||||||
|
|||||||
@@ -14,13 +14,15 @@ class PageRulesTargets implements Configurations
|
|||||||
|
|
||||||
public function __construct(string $queryUrl)
|
public function __construct(string $queryUrl)
|
||||||
{
|
{
|
||||||
$target = new \stdClass();
|
$this->targets = [
|
||||||
$target->target = 'url';
|
[
|
||||||
$target->constraint = new \stdClass();
|
'target' => 'url',
|
||||||
$target->constraint->operator = "matches";
|
'constraint' => [
|
||||||
$target->constraint->value = $queryUrl;
|
'operator' => 'matches',
|
||||||
|
'value' => $queryUrl
|
||||||
$this->targets = [$target];
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
121
src/Configurations/Pool.php
Normal file
121
src/Configurations/Pool.php
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class Pool implements Configurations
|
||||||
|
{
|
||||||
|
private $configs = [];
|
||||||
|
|
||||||
|
public function __construct(string $name, array $origins)
|
||||||
|
{
|
||||||
|
$this->setName($name);
|
||||||
|
$this->setOrigins($origins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name)
|
||||||
|
{
|
||||||
|
$this->configs['name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName():string
|
||||||
|
{
|
||||||
|
return $this->configs['name'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOrigins(array $origins)
|
||||||
|
{
|
||||||
|
foreach ($origins as $origin) {
|
||||||
|
if (!isset($origin['name'])) {
|
||||||
|
throw new ConfigurationsException('name is required for origin');
|
||||||
|
}
|
||||||
|
if (!isset($origin['address'])) {
|
||||||
|
throw new ConfigurationsException('address is required for origin');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->configs['origins'] = $origins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrigins():array
|
||||||
|
{
|
||||||
|
return $this->configs['origins'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(string $description = '')
|
||||||
|
{
|
||||||
|
$this->configs['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription():string
|
||||||
|
{
|
||||||
|
return $this->configs['description'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDisabled():bool
|
||||||
|
{
|
||||||
|
return !$this->configs['enabled'] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMonitor(string $monitor)
|
||||||
|
{
|
||||||
|
$this->configs['monitor'] = $monitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMonitor():string
|
||||||
|
{
|
||||||
|
return $this->configs['monitor'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCheckRegions(array $checkRegions)
|
||||||
|
{
|
||||||
|
$this->configs['check_regions'] = $checkRegions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCheckRegions():array
|
||||||
|
{
|
||||||
|
return $this->configs['check_regions'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNotificationEmail(string $email)
|
||||||
|
{
|
||||||
|
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
||||||
|
throw new ConfigurationsException('Invalid notification email given');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->configs['notification_email'] = $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNotificationEmail():string
|
||||||
|
{
|
||||||
|
return $this->configs['notification_email'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,11 +14,7 @@ class UARules implements Configurations
|
|||||||
|
|
||||||
public function addUA(string $value)
|
public function addUA(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = ['target' => 'ua', 'value' => $value];
|
||||||
$object->target = "ua";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
@@ -14,20 +14,12 @@ class ZoneLockdown implements Configurations
|
|||||||
|
|
||||||
public function addIP(string $value)
|
public function addIP(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = ['target' => 'ip', 'value' => $value];
|
||||||
$object->target = "ip";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addIPRange(string $value)
|
public function addIPRange(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = ['target' => 'ip_range', 'value' => $value];
|
||||||
$object->target = "ip_range";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
156
src/Endpoints/AccessRules.php
Normal file
156
src/Endpoints/AccessRules.php
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $scopeType
|
||||||
|
* @param string $mode
|
||||||
|
* @param string $configurationTarget
|
||||||
|
* @param string $configurationValue
|
||||||
|
* @param int $page
|
||||||
|
* @param int $perPage
|
||||||
|
* @param string $order
|
||||||
|
* @param string $direction
|
||||||
|
* @param string $match
|
||||||
|
* @param string $notes
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function listRules(
|
||||||
|
string $zoneID,
|
||||||
|
string $scopeType = '',
|
||||||
|
string $mode = '',
|
||||||
|
string $configurationTarget = '',
|
||||||
|
string $configurationValue = '',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 50,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all',
|
||||||
|
string $notes = ''
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($scopeType)) {
|
||||||
|
$query['scope_type'] = $scopeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($mode)) {
|
||||||
|
$query['mode'] = $mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($configurationTarget)) {
|
||||||
|
$query['configuration_target'] = $configurationTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($configurationValue)) {
|
||||||
|
$query['configuration_value'] = $configurationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($notes)) {
|
||||||
|
$query['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query);
|
||||||
|
$this->body = json_decode($data->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $mode,
|
||||||
|
Configurations $configuration,
|
||||||
|
string $notes = null
|
||||||
|
): bool {
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode,
|
||||||
|
'configuration' => $configuration->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($notes !== null) {
|
||||||
|
$options['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
|
string $mode,
|
||||||
|
string $notes = null
|
||||||
|
): bool {
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($notes !== null) {
|
||||||
|
$options['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteRule(string $zoneID, string $ruleID, string $cascade = 'none'): bool
|
||||||
|
{
|
||||||
|
$options = [
|
||||||
|
'cascade' => $cascade
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($data->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
95
src/Endpoints/Crypto.php
Normal file
95
src/Endpoints/Crypto.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class Crypto implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Opportunistic Encryption feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getOpportunisticEncryptionSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_encryption'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Onion Routing feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getOnionRoutingSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_onion'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Oppurtunistic Encryption setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateOpportunisticEncryptionSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_encryption',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Onion Routing setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateOnionRoutingSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_onion',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
153
src/Endpoints/CustomHostnames.php
Normal file
153
src/Endpoints/CustomHostnames.php
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 18/03/2018
|
||||||
|
* Time: 21:46
|
||||||
|
*/
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostname
|
||||||
|
* @param string $sslMethod
|
||||||
|
* @param string $sslType
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv'): \stdClass
|
||||||
|
{
|
||||||
|
$options = [
|
||||||
|
'hostname' => $hostname,
|
||||||
|
'ssl' => [
|
||||||
|
'method' => $sslMethod,
|
||||||
|
'type' => $sslType
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
|
||||||
|
$this->body = json_decode($zone->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostname
|
||||||
|
* @param string $id
|
||||||
|
* @param int $page
|
||||||
|
* @param int $perPage
|
||||||
|
* @param string $order
|
||||||
|
* @param string $direction
|
||||||
|
* @param int $ssl
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function listHostnames(
|
||||||
|
string $zoneID,
|
||||||
|
string $hostname = '',
|
||||||
|
string $hostnameID = '',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
int $ssl = 0
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'ssl' => $ssl
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($hostname)) {
|
||||||
|
$query['hostname'] = $hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($hostnameID)) {
|
||||||
|
$query['id'] = $hostnameID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query);
|
||||||
|
$this->body = json_decode($zone->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostnameID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getHostname(string $zoneID, string $hostnameID)
|
||||||
|
{
|
||||||
|
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
|
||||||
|
$this->body = json_decode($zone->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostnameID
|
||||||
|
* @param string $sslMethod
|
||||||
|
* @param string $sslType
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = ''): \stdClass
|
||||||
|
{
|
||||||
|
$query = [];
|
||||||
|
|
||||||
|
if (!empty($sslMethod)) {
|
||||||
|
$query['method'] = $sslMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($sslType)) {
|
||||||
|
$query['type'] = $sslType;
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'ssl' => $query
|
||||||
|
];
|
||||||
|
|
||||||
|
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
|
||||||
|
$this->body = json_decode($zone->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostnameID
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
|
||||||
|
{
|
||||||
|
$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;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class DNS implements API
|
class DNS implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -28,6 +31,8 @@ class DNS implements API
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @param int $ttl
|
* @param int $ttl
|
||||||
* @param bool $proxied
|
* @param bool $proxied
|
||||||
|
* @param string $priority
|
||||||
|
* @param array $data
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function addRecord(
|
public function addRecord(
|
||||||
@@ -36,7 +41,9 @@ class DNS implements API
|
|||||||
string $name,
|
string $name,
|
||||||
string $content,
|
string $content,
|
||||||
int $ttl = 0,
|
int $ttl = 0,
|
||||||
bool $proxied = true
|
bool $proxied = true,
|
||||||
|
string $priority = '',
|
||||||
|
array $data = []
|
||||||
): bool {
|
): bool {
|
||||||
$options = [
|
$options = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
@@ -49,11 +56,19 @@ class DNS implements API
|
|||||||
$options['ttl'] = $ttl;
|
$options['ttl'] = $ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options);
|
if (!empty($priority)) {
|
||||||
|
$options['priority'] = (int)$priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data)) {
|
||||||
|
$options['data'] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +77,14 @@ class DNS implements API
|
|||||||
|
|
||||||
public function listRecords(
|
public function listRecords(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $type = "",
|
string $type = '',
|
||||||
string $name = "",
|
string $name = '',
|
||||||
string $content = "",
|
string $content = '',
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -97,36 +112,42 @@ class DNS implements API
|
|||||||
$query['direction'] = $direction;
|
$query['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
|
||||||
|
{
|
||||||
|
$records = $this->listRecords($zoneID, $type, $name);
|
||||||
|
if (isset($records->result{0}->id)) {
|
||||||
|
return $records->result{0}->id;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
||||||
{
|
{
|
||||||
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
|
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
|
||||||
return json_decode($response->getBody());
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteRecord(string $zoneID, string $recordID): bool
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
135
src/Endpoints/FirewallSettings.php
Normal file
135
src/Endpoints/FirewallSettings.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class FirewallSettings implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Security Level feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getSecurityLevelSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/security_level'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Challenge TTL feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return integer|false
|
||||||
|
*/
|
||||||
|
public function getChallengeTTLSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/challenge_ttl'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Browser Integrity Check feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getBrowserIntegrityCheckSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/browser_check'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Security Level setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateSecurityLevelSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/security_level',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Challenge TTL setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param int $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateChallengeTTLSetting(string $zoneID, int $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/challenge_ttl',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Browser Integrity Check setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateBrowserIntegrityCheckSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/browser_check',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class IPs implements API
|
class IPs implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -21,9 +24,9 @@ class IPs implements API
|
|||||||
|
|
||||||
public function listIPs(): \stdClass
|
public function listIPs(): \stdClass
|
||||||
{
|
{
|
||||||
$ips = $this->adapter->get('ips', [], []);
|
$ips = $this->adapter->get('ips');
|
||||||
$body = json_decode($ips->getBody());
|
$this->body = json_decode($ips->getBody());
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
157
src/Endpoints/LoadBalancers.php
Normal file
157
src/Endpoints/LoadBalancers.php
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\LoadBalancer;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class LoadBalancers implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function listLoadBalancers(string $zoneID)
|
||||||
|
{
|
||||||
|
$loadBalancers = $this->adapter->get('zones/' . $zoneID . '/load_balancers');
|
||||||
|
$this->body = json_decode($loadBalancers->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getLoadBalancerDetails(string $zoneID, string $loadBalancerID)
|
||||||
|
{
|
||||||
|
$loadBalancer = $this->adapter->get('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID);
|
||||||
|
$this->body = json_decode($loadBalancer->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @return LoadBalancer
|
||||||
|
* @throws ConfigurationsException
|
||||||
|
*/
|
||||||
|
public function getLoadBalancerConfiguration(string $zoneID, string $loadBalancerID)
|
||||||
|
{
|
||||||
|
$loadBalancer = $this->getLoadBalancerDetails($zoneID, $loadBalancerID);
|
||||||
|
|
||||||
|
$lbConfiguration = new LoadBalancer($loadBalancer->name, $loadBalancer->default_pools, $loadBalancer->fallback_pool);
|
||||||
|
$lbConfiguration->setSteeringPolicy($loadBalancer->steering_policy);
|
||||||
|
if ($loadBalancer->enabled === true) {
|
||||||
|
$lbConfiguration->enable();
|
||||||
|
} elseif ($loadBalancer->enabled === false) {
|
||||||
|
$lbConfiguration->disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($loadBalancer->pop_pools)) {
|
||||||
|
$lbConfiguration->setPopPools($loadBalancer->pop_pools);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($loadBalancer->ttl)) {
|
||||||
|
$lbConfiguration->setTtl($loadBalancer->ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($loadBalancer->region_pools)) {
|
||||||
|
$lbConfiguration->setRegionPools($loadBalancer->region_pools);
|
||||||
|
}
|
||||||
|
$lbConfiguration->setSessionAffinity($loadBalancer->session_affinity);
|
||||||
|
$lbConfiguration->setDescription($loadBalancer->description);
|
||||||
|
if ($loadBalancer->proxied === true) {
|
||||||
|
$lbConfiguration->enableProxied();
|
||||||
|
} elseif ($loadBalancer->proxied === false) {
|
||||||
|
$lbConfiguration->disableProxied();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($loadBalancer->session_affinity_ttl)) {
|
||||||
|
$lbConfiguration->setSessionAffinityTtl($loadBalancer->session_affinity_ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lbConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @param LoadBalancer $lbConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateLoadBalancer(
|
||||||
|
string $zoneID,
|
||||||
|
string $loadBalancerID,
|
||||||
|
LoadBalancer $lbConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $lbConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->put('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param LoadBalancer $lbConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function createLoadBalancer(
|
||||||
|
string $zoneID,
|
||||||
|
LoadBalancer $lbConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $lbConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->post('zones/' . $zoneID . '/load_balancers', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteLoadBalancer(string $zoneID, string $loadBalancerID): bool
|
||||||
|
{
|
||||||
|
$loadBalancer = $this->adapter->delete('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID);
|
||||||
|
|
||||||
|
$this->body = json_decode($loadBalancer->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/Endpoints/Membership.php
Normal file
83
src/Endpoints/Membership.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
/* A list of memberships of accounts this user can access */
|
||||||
|
|
||||||
|
class Membership implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function listMemberships(
|
||||||
|
string $name = '',
|
||||||
|
string $status = '',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = ''
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($name)) {
|
||||||
|
$query['account.name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($status) && in_array($status, ['accepted', 'pending', 'rejected'], true)) {
|
||||||
|
$query['status'] = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order) && in_array($order, ['id', 'account.name', 'status'], true)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction) && in_array($direction, ['asc', 'desc'], true)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$memberships = $this->adapter->get('memberships', $query);
|
||||||
|
$this->body = json_decode($memberships->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMembershipDetails(string $membershipId): \stdClass
|
||||||
|
{
|
||||||
|
$membership = $this->adapter->get(sprintf('memberships/%s', $membershipId));
|
||||||
|
$this->body = json_decode($membership->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateMembershipStatus(string $membershipId, string $status): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->put(sprintf('memberships/%s', $membershipId), ['status' => $status]);
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteMembership(string $membershipId): bool
|
||||||
|
{
|
||||||
|
$response = $this->adapter->delete(sprintf('memberships/%s', $membershipId));
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,9 +11,12 @@ namespace Cloudflare\API\Endpoints;
|
|||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
use Cloudflare\API\Configurations\PageRulesActions;
|
use Cloudflare\API\Configurations\PageRulesActions;
|
||||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class PageRules implements API
|
class PageRules implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,19 +73,19 @@ class PageRules implements API
|
|||||||
string $direction = null,
|
string $direction = null,
|
||||||
string $match = null
|
string $match = null
|
||||||
): array {
|
): array {
|
||||||
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
|
if ($status === null && !in_array($status, ['active', 'disabled'])) {
|
||||||
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
|
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($order) && !in_array($order, ['status', 'priority'])) {
|
if ($order === null && !in_array($order, ['status', 'priority'])) {
|
||||||
throw new EndpointException('Page Rules can only be ordered by status or priority.');
|
throw new EndpointException('Page Rules can only be ordered by status or priority.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) {
|
if ($direction === null && !in_array($direction, ['asc', 'desc'])) {
|
||||||
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
|
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($match) && !in_array($match, ['all', 'any'])) {
|
if ($match === null && !in_array($match, ['all', 'any'])) {
|
||||||
throw new EndpointException('Match can only be any or all.');
|
throw new EndpointException('Match can only be any or all.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,21 +96,22 @@ class PageRules implements API
|
|||||||
'match' => $match
|
'match' => $match
|
||||||
];
|
];
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
|
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatePageRule(
|
public function updatePageRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
PageRulesTargets $target = null,
|
PageRulesTargets $target = null,
|
||||||
PageRulesActions $actions = null,
|
PageRulesActions $actions = null,
|
||||||
bool $active = null,
|
bool $active = null,
|
||||||
@@ -115,7 +119,7 @@ class PageRules implements API
|
|||||||
): bool {
|
): bool {
|
||||||
$options = [];
|
$options = [];
|
||||||
|
|
||||||
if ($active !== null) {
|
if ($target !== null) {
|
||||||
$options['targets'] = $target->getArray();
|
$options['targets'] = $target->getArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,12 +135,11 @@ class PageRules implements API
|
|||||||
$options['priority'] = $priority;
|
$options['priority'] = $priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules/' . $ruleID, $options);
|
||||||
|
|
||||||
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', [], $options);
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
$body = json_decode($query->getBody());
|
if (isset($this->body->result->id)) {
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,11 +148,11 @@ class PageRules implements API
|
|||||||
|
|
||||||
public function deletePageRule(string $zoneID, string $ruleID): bool
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
156
src/Endpoints/Pools.php
Normal file
156
src/Endpoints/Pools.php
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\Pool;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class Pools implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function listPools(string $accountID)
|
||||||
|
{
|
||||||
|
$pools = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools');
|
||||||
|
$this->body = json_decode($pools->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getPoolDetails(string $accountID, string $poolID)
|
||||||
|
{
|
||||||
|
$pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID);
|
||||||
|
$this->body = json_decode($pool->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getPoolHealthDetails(string $accountID, string $poolID)
|
||||||
|
{
|
||||||
|
$pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID . '/health');
|
||||||
|
$this->body = json_decode($pool->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return Pool
|
||||||
|
* @throws ConfigurationsException
|
||||||
|
*/
|
||||||
|
public function getPoolConfiguration(string $accountID, string $poolID)
|
||||||
|
{
|
||||||
|
$pool = $this->getPoolDetails($accountID, $poolID);
|
||||||
|
|
||||||
|
$origins = [];
|
||||||
|
foreach ($pool->origins as $origin) {
|
||||||
|
$origins[] = (array)$origin;
|
||||||
|
}
|
||||||
|
$poolConfiguration = new Pool($pool->name, $origins);
|
||||||
|
$poolConfiguration->setDescription($pool->description);
|
||||||
|
if ($pool->enabled === true) {
|
||||||
|
$poolConfiguration->enable();
|
||||||
|
} elseif ($pool->enabled === false) {
|
||||||
|
$poolConfiguration->disable();
|
||||||
|
}
|
||||||
|
$poolConfiguration->setMonitor($pool->monitor);
|
||||||
|
$poolConfiguration->setNotificationEmail($pool->notification_email);
|
||||||
|
|
||||||
|
if (is_array($pool->check_regions)) {
|
||||||
|
$poolConfiguration->setCheckRegions($pool->check_regions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $poolConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @param Pool $poolConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updatePool(
|
||||||
|
string $accountID,
|
||||||
|
string $poolID,
|
||||||
|
Pool $poolConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $poolConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->put('accounts/' . $accountID . '/load_balancers/pools/' . $poolID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param Pool $poolConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function createPool(
|
||||||
|
string $accountID,
|
||||||
|
Pool $poolConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $poolConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->post('accounts/' . $accountID . '/load_balancers/pools', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deletePool(string $accountID, string $poolID): bool
|
||||||
|
{
|
||||||
|
$pool = $this->adapter->delete('accounts/' . $accountID . '/load_balancers/pools/' . $poolID);
|
||||||
|
|
||||||
|
$this->body = json_decode($pool->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class Railgun implements API
|
class Railgun implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -26,16 +29,16 @@ class Railgun implements API
|
|||||||
'name' => $name,
|
'name' => $name,
|
||||||
];
|
];
|
||||||
|
|
||||||
$user = $this->adapter->post('railguns', [], $query);
|
$user = $this->adapter->post('railguns', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
return $body;
|
return $this->body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function list(
|
public function list(
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $direction = ""
|
string $direction = ''
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -46,36 +49,28 @@ class Railgun implements API
|
|||||||
$query['direction'] = $direction;
|
$query['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->get('railguns', $query, []);
|
$user = $this->adapter->get('railguns', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(
|
public function get(
|
||||||
string $railgunID
|
string $railgunID
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$user = $this->adapter->get('railguns/' . $railgunID, [], []);
|
$user = $this->adapter->get('railguns/' . $railgunID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getZones(
|
public function getZones(
|
||||||
string $railgunID
|
string $railgunID
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$user = $this->adapter->get('railguns/' . $railgunID . '/zones', [], []);
|
$user = $this->adapter->get('railguns/' . $railgunID . '/zones');
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(
|
public function update(
|
||||||
@@ -86,19 +81,19 @@ class Railgun implements API
|
|||||||
'enabled' => $status
|
'enabled' => $status
|
||||||
];
|
];
|
||||||
|
|
||||||
$user = $this->adapter->patch('railguns/' . $railgunID, [], $query);
|
$user = $this->adapter->patch('railguns/' . $railgunID, $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(
|
public function delete(
|
||||||
string $railgunID
|
string $railgunID
|
||||||
): bool {
|
): bool {
|
||||||
$user = $this->adapter->delete('railguns/' . $railgunID, [], []);
|
$user = $this->adapter->delete('railguns/' . $railgunID);
|
||||||
$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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
153
src/Endpoints/SSL.php
Normal file
153
src/Endpoints/SSL.php
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class SSL implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SSL setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getSSLSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/ssl'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get SSL Verification Info for a Zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
|
public function getSSLVerificationStatus(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/ssl/verification'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the HTTPS Redirect setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getHTTPSRedirectSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/always_use_https'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the HTTPS Rewrite setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getHTTPSRewritesSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/automatic_https_rewrites'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the SSL setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateSSLSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/ssl',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the HTTPS Redirect setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateHTTPSRedirectSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/always_use_https',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the HTTPS Rewrite setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateHTTPSRewritesSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/automatic_https_rewrites',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
121
src/Endpoints/TLS.php
Normal file
121
src/Endpoints/TLS.php
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the TLS Client Auth setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getTLSClientAuth($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_client_auth'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable TLS 1.3 for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function enableTLS13($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_1_3',
|
||||||
|
['value' => 'on']
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable TLS 1.3 for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function disableTLS13($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_1_3',
|
||||||
|
['value' => 'off']
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the minimum TLS version setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $minimumVersion The version to update to
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function changeMinimumTLSVersion($zoneID, $minimumVersion)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/min_tls_version',
|
||||||
|
[
|
||||||
|
'value' => $minimumVersion,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the TLS Client Auth setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateTLSClientAuth($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_client_auth',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,10 +8,14 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\Configurations;
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class UARules implements API
|
class UARules implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -29,20 +33,16 @@ class UARules implements API
|
|||||||
'per_page' => $perPage
|
'per_page' => $perPage
|
||||||
];
|
];
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createRule(
|
public function createRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $mode,
|
string $mode,
|
||||||
\Cloudflare\API\Configurations\Configurations $configuration,
|
Configurations $configuration,
|
||||||
string $ruleID = null,
|
string $ruleID = null,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
@@ -59,11 +59,11 @@ class UARules implements API
|
|||||||
$options['description'] = $description;
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,9 +72,9 @@ class UARules implements API
|
|||||||
|
|
||||||
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateRule(
|
public function updateRule(
|
||||||
@@ -94,11 +94,11 @@ class UARules implements API
|
|||||||
$options['description'] = $description;
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,11 +107,11 @@ class UARules implements API
|
|||||||
|
|
||||||
public function deleteRule(string $zoneID, string $ruleID): bool
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class User implements API
|
class User implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -20,24 +23,25 @@ class User implements API
|
|||||||
|
|
||||||
public function getUserDetails(): \stdClass
|
public function getUserDetails(): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('user', [], []);
|
$user = $this->adapter->get('user');
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserID(): string
|
public function getUserID(): string
|
||||||
{
|
{
|
||||||
return ($this->getUserDetails())->id;
|
return $this->getUserDetails()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserEmail(): string
|
public function getUserEmail(): string
|
||||||
{
|
{
|
||||||
return ($this->getUserDetails())->email;
|
return $this->getUserDetails()->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateUserDetails(array $details): \stdClass
|
public function updateUserDetails(array $details): \stdClass
|
||||||
{
|
{
|
||||||
$response = $this->adapter->patch("user", [], $details);
|
$response = $this->adapter->patch('user', $details);
|
||||||
return json_decode($response->getBody());
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class WAF implements \Cloudflare\API\Endpoints\API
|
class WAF implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -23,9 +26,9 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
string $zoneID,
|
string $zoneID,
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -41,14 +44,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
$query['direction'] = $direction;
|
$query['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -56,10 +55,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $packageID
|
string $packageID
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID, [], []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRules(
|
public function getRules(
|
||||||
@@ -67,9 +66,9 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
string $packageID,
|
string $packageID,
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -84,14 +83,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
if (!empty($direction)) {
|
if (!empty($direction)) {
|
||||||
$query['direction'] = $direction;
|
$query['direction'] = $direction;
|
||||||
}
|
}
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRuleInfo(
|
public function getRuleInfo(
|
||||||
@@ -99,14 +94,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
string $packageID,
|
string $packageID,
|
||||||
string $ruleID
|
string $ruleID
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$user = $this->adapter->get(
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID);
|
||||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
$this->body = json_decode($user->getBody());
|
||||||
[],
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateRule(
|
public function updateRule(
|
||||||
@@ -121,12 +112,11 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
|
|
||||||
$user = $this->adapter->patch(
|
$user = $this->adapter->patch(
|
||||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
||||||
[],
|
|
||||||
$query
|
$query
|
||||||
);
|
);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroups(
|
public function getGroups(
|
||||||
@@ -134,9 +124,9 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
string $packageID,
|
string $packageID,
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -154,16 +144,11 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
|
|
||||||
$user = $this->adapter->get(
|
$user = $this->adapter->get(
|
||||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
|
||||||
$query,
|
$query
|
||||||
[]
|
|
||||||
);
|
);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroupInfo(
|
public function getGroupInfo(
|
||||||
@@ -171,14 +156,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
string $packageID,
|
string $packageID,
|
||||||
string $groupID
|
string $groupID
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$user = $this->adapter->get(
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID);
|
||||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
$this->body = json_decode($user->getBody());
|
||||||
[],
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateGroup(
|
public function updateGroup(
|
||||||
@@ -193,11 +174,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
|
|||||||
|
|
||||||
$user = $this->adapter->patch(
|
$user = $this->adapter->patch(
|
||||||
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
||||||
[],
|
|
||||||
$query
|
$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;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class ZoneLockdown implements API
|
class ZoneLockdown implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -29,14 +32,10 @@ class ZoneLockdown implements API
|
|||||||
'per_page' => $perPage
|
'per_page' => $perPage
|
||||||
];
|
];
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createLockdown(
|
public function createLockdown(
|
||||||
@@ -59,11 +58,11 @@ class ZoneLockdown implements API
|
|||||||
$options['description'] = $description;
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,9 +71,9 @@ class ZoneLockdown implements API
|
|||||||
|
|
||||||
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
|
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateLockdown(
|
public function updateLockdown(
|
||||||
@@ -94,11 +93,11 @@ class ZoneLockdown implements API
|
|||||||
$options['description'] = $description;
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,11 +106,11 @@ class ZoneLockdown implements API
|
|||||||
|
|
||||||
public function deleteLockdown(string $zoneID, string $lockdownID): bool
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
180
src/Endpoints/ZoneSettings.php
Normal file
180
src/Endpoints/ZoneSettings.php
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: paul.adams
|
||||||
|
* Date: 2019-02-22
|
||||||
|
* Time: 23:28
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class ZoneSettings implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinifySetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/minify'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRocketLoaderSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/rocket_loader'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAlwaysOnlineSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/always_online'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmailObfuscationSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/email_obfuscation'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHotlinkProtectionSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/hotlink_protection'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateMinifySetting($zoneID, $html, $css, $javascript)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/minify',
|
||||||
|
[
|
||||||
|
'value' => [
|
||||||
|
'html' => $html,
|
||||||
|
'css' => $css,
|
||||||
|
'js' => $javascript,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRocketLoaderSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/rocket_loader',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAlwaysOnlineSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/always_online',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateEmailObfuscationSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/email_obfuscation',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateHotlinkProtectionSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/hotlink_protection',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class Zones implements API
|
class Zones implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -23,48 +26,55 @@ class Zones implements API
|
|||||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param bool $jumpstart
|
* @param bool $jumpStart
|
||||||
* @param string $organizationID
|
* @param string $organizationID
|
||||||
* @return \stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
|
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
|
||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'jumpstart' => $jumpstart
|
'jump_start' => $jumpStart
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($organizationID)) {
|
if (!empty($organizationID)) {
|
||||||
$organization = new \stdClass();
|
$options['organization'] = ['id' => $organizationID];
|
||||||
$organization->id = $organizationID;
|
|
||||||
$options["organization"] = $organization;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones', [], $options);
|
$user = $this->adapter->post('zones', $options);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function activationCheck(string $zoneID): bool
|
public function activationCheck(string $zoneID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []);
|
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check');
|
||||||
$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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getZoneById(
|
||||||
|
string $zoneId
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneId);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result];
|
||||||
|
}
|
||||||
|
|
||||||
public function listZones(
|
public function listZones(
|
||||||
string $name = "",
|
string $name = '',
|
||||||
string $status = "",
|
string $status = '',
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$query = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
@@ -88,22 +98,18 @@ class Zones implements API
|
|||||||
$query['direction'] = $direction;
|
$query['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->get('zones', $query, []);
|
$user = $this->adapter->get('zones', $query);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$result = new \stdClass();
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getZoneID(string $name = ""): string
|
public function getZoneID(string $name = ''): string
|
||||||
{
|
{
|
||||||
$zones = $this->listZones($name);
|
$zones = $this->listZones($name);
|
||||||
|
|
||||||
if (sizeof($zones->result) < 1) {
|
if (count($zones->result) < 1) {
|
||||||
throw new EndpointException("Could not find zones with specified name.");
|
throw new EndpointException('Could not find zones with specified name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $zones->result[0]->id;
|
return $zones->result[0]->id;
|
||||||
@@ -118,11 +124,13 @@ class Zones implements API
|
|||||||
* @param bool $continuous
|
* @param bool $continuous
|
||||||
* @return \stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function getAnalyticsDashboard(string $zoneID, string $since = "-10080", string $until = "0", bool $continuous = true): \stdClass
|
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" => $continuous]);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,17 +142,49 @@ class Zones implements API
|
|||||||
*/
|
*/
|
||||||
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return caching level settings
|
||||||
|
* @param string $zoneID
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCachingLevel(string $zoneID): string
|
||||||
|
{
|
||||||
|
$response = $this->adapter->get('zones/' . $zoneID . '/settings/cache_level');
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
return $this->body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change caching level settings
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $level (aggressive | basic | simplified)
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setCachingLevel(string $zoneID, string $level = 'aggressive'): bool
|
||||||
|
{
|
||||||
|
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/cache_level', ['value' => $level]);
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
if ($this->body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge Everything
|
* Purge Everything
|
||||||
@@ -153,33 +193,41 @@ class Zones implements API
|
|||||||
*/
|
*/
|
||||||
public function cachePurgeEverything(string $zoneID): bool
|
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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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 (is_null($files) && is_null($tags)) {
|
if ($files === null && $tags === null && $hosts === null) {
|
||||||
throw new EndpointException("No files or tags to purge.");
|
throw new EndpointException('No files, tags or hosts to purge.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = [
|
$options = [];
|
||||||
'files' => $files,
|
if (!is_null($files)) {
|
||||||
'tags' => $tags
|
$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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,66 +29,64 @@ class GuzzleTest extends TestCase
|
|||||||
$response = $this->client->get('https://httpbin.org/get');
|
$response = $this->client->get('https://httpbin.org/get');
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Test", $body->headers->{"X-Testing"});
|
$this->assertEquals('Test', $body->headers->{'X-Testing'});
|
||||||
|
|
||||||
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
|
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
|
$this->assertEquals('Test2', $body->headers->{'X-Another-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPost()
|
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();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a POST request.", $body->json->{"X-Post-Test"});
|
$this->assertEquals('Testing a POST request.', $body->json->{'X-Post-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPut()
|
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();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a PUT request.", $body->json->{"X-Put-Test"});
|
$this->assertEquals('Testing a PUT request.', $body->json->{'X-Put-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPatch()
|
public function testPatch()
|
||||||
{
|
{
|
||||||
$response = $this->client->patch(
|
$response = $this->client->patch(
|
||||||
'https://httpbin.org/patch',
|
'https://httpbin.org/patch',
|
||||||
[],
|
|
||||||
['X-Patch-Test' => 'Testing a PATCH request.']
|
['X-Patch-Test' => 'Testing a PATCH request.']
|
||||||
);
|
);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a PATCH request.", $body->json->{"X-Patch-Test"});
|
$this->assertEquals('Testing a PATCH request.', $body->json->{'X-Patch-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
$response = $this->client->delete(
|
$response = $this->client->delete(
|
||||||
'https://httpbin.org/delete',
|
'https://httpbin.org/delete',
|
||||||
[],
|
|
||||||
['X-Delete-Test' => 'Testing a DELETE request.']
|
['X-Delete-Test' => 'Testing a DELETE request.']
|
||||||
);
|
);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a DELETE request.", $body->json->{"X-Delete-Test"});
|
$this->assertEquals('Testing a DELETE request.', $body->json->{'X-Delete-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testErrors()
|
public function testErrors()
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ class APIKeyTest extends TestCase
|
|||||||
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
|
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
|
||||||
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
|
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
|
||||||
|
|
||||||
$this->assertEquals(2, sizeof($headers));
|
$this->assertCount(2, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
* Time: 20:08
|
* Time: 20:08
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Auth\None;
|
|
||||||
|
|
||||||
class NoneTest extends TestCase
|
class NoneTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class UserServiceKeyTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
$auth = new \Cloudflare\API\Auth\UserServiceKey("v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a");
|
$auth = new \Cloudflare\API\Auth\UserServiceKey('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a');
|
||||||
$headers = $auth->getHeaders();
|
$headers = $auth->getHeaders();
|
||||||
|
|
||||||
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
|
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
|
||||||
@@ -19,6 +19,6 @@ class UserServiceKeyTest extends TestCase
|
|||||||
$headers['X-Auth-User-Service-Key']
|
$headers['X-Auth-User-Service-Key']
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(1, sizeof($headers));
|
$this->assertCount(1, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ class ConfigurationsUARulesTest extends TestCase
|
|||||||
$configuration->addUA('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');
|
$configuration->addUA('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 = $configuration->getArray();
|
$array = $configuration->getArray();
|
||||||
$this->assertEquals(1, sizeof($array));
|
$this->assertCount(1, $array);
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('target', $array[0]);
|
$this->assertArrayHasKey('target', $array[0]);
|
||||||
$this->assertEquals('ua', $array[0]->target);
|
$this->assertEquals('ua', $array[0]['target']);
|
||||||
$this->assertObjectHasAttribute('value', $array[0]);
|
$this->assertArrayHasKey('value', $array[0]);
|
||||||
$this->assertEquals(
|
$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',
|
'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']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
tests/Configurations/ConfigurationsZoneLockdownTest.php
Normal file
34
tests/Configurations/ConfigurationsZoneLockdownTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 05/09/2017
|
||||||
|
* Time: 13:50
|
||||||
|
*/
|
||||||
|
class ConfigurationsZoneLockdownTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetArray()
|
||||||
|
{
|
||||||
|
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
|
$configuration->addIP('1.2.3.4');
|
||||||
|
|
||||||
|
$array = $configuration->getArray();
|
||||||
|
$this->assertCount(1, $array);
|
||||||
|
|
||||||
|
$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->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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
56
tests/Configurations/LoadBalancerTest.php
Normal file
56
tests/Configurations/LoadBalancerTest.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\LoadBalancer;
|
||||||
|
|
||||||
|
class LoadBalancerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider testArgumentsDataProvider
|
||||||
|
*/
|
||||||
|
public function testArguments($setFunction, $arguments, $getFunction, $invalid)
|
||||||
|
{
|
||||||
|
$loadBalancer = new LoadBalancer('bogus', [], 'bogus');
|
||||||
|
foreach ($arguments as $argument) {
|
||||||
|
if ($invalid === true) {
|
||||||
|
try {
|
||||||
|
$loadBalancer->{$setFunction}($argument);
|
||||||
|
} catch (ConfigurationsException $e) {
|
||||||
|
$this->assertNotEquals($argument, $loadBalancer->{$getFunction}());
|
||||||
|
}
|
||||||
|
} elseif ($invalid === false) {
|
||||||
|
$loadBalancer->{$setFunction}($argument);
|
||||||
|
$this->assertEquals($argument, $loadBalancer->{$getFunction}());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArgumentsDataProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'steeringPolicy arguments valid' => [
|
||||||
|
'setSteeringPolicy', ['off', 'geo', 'random', 'dynamic_latency', ''], 'getSteeringPolicy', false
|
||||||
|
],
|
||||||
|
'sessionAffinity arguments valid' => [
|
||||||
|
'setSessionAffinity', ['none', 'cookie', 'ip_cookie', ''], 'getSessionAffinity', false
|
||||||
|
],
|
||||||
|
'sessionAffinityTtl arguments valid' => [
|
||||||
|
'setSessionAffinityTtl', [3600], 'getSessionAffinityTtl', false
|
||||||
|
],
|
||||||
|
'steeringPolicy arguments invalid' => [
|
||||||
|
'setSteeringPolicy', ['invalid'], 'getSteeringPolicy', true
|
||||||
|
],
|
||||||
|
'sessionAffinity arguments invalid' => [
|
||||||
|
'setSessionAffinity', ['invalid'], 'getSessionAffinity', true
|
||||||
|
],
|
||||||
|
'sessionAffinityTtl arguments invalid' => [
|
||||||
|
'setSessionAffinityTtl', [1337], 'getSessionAffinityTtl', true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
21
tests/Configurations/PageRulesActionTest.php
Normal file
21
tests/Configurations/PageRulesActionTest.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
use Cloudflare\API\Configurations\PageRulesActions;
|
||||||
|
|
||||||
|
class PageRulesActionTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testForwardingURLConfigurationIsApplied()
|
||||||
|
{
|
||||||
|
$identifier = 'forwarding_url';
|
||||||
|
$statusCode = 301;
|
||||||
|
$forwardingURL = 'https://www.example.org/';
|
||||||
|
|
||||||
|
$actions = new PageRulesActions();
|
||||||
|
$actions->setForwardingURL($statusCode, $forwardingURL);
|
||||||
|
$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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,8 +15,8 @@ class PageRulesTargetTest extends TestCase
|
|||||||
$targets = new PageRulesTargets('junade.com/*');
|
$targets = new PageRulesTargets('junade.com/*');
|
||||||
$array = $targets->getArray();
|
$array = $targets->getArray();
|
||||||
|
|
||||||
$this->assertEquals(1, sizeof($array));
|
$this->assertCount(1, $array);
|
||||||
$this->assertEquals("junade.com/*", $array[0]->constraint->value);
|
$this->assertEquals('junade.com/*', $array[0]['constraint']['value']);
|
||||||
$this->assertEquals("matches", $array[0]->constraint->operator);
|
$this->assertEquals('matches', $array[0]['constraint']['operator']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
53
tests/Configurations/PoolTest.php
Normal file
53
tests/Configurations/PoolTest.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\Pool;
|
||||||
|
|
||||||
|
class PoolTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider testArgumentsDataProvider
|
||||||
|
*/
|
||||||
|
public function testArguments($setFunction, $arguments, $getFunction, $invalid)
|
||||||
|
{
|
||||||
|
$pool = new Pool('bogus', []);
|
||||||
|
foreach ($arguments as $argument) {
|
||||||
|
if ($invalid) {
|
||||||
|
try {
|
||||||
|
$pool->{$setFunction}($argument);
|
||||||
|
} catch (ConfigurationsException $e) {
|
||||||
|
$this->assertNotEquals($argument, $pool->{$getFunction}());
|
||||||
|
}
|
||||||
|
} elseif ($invalid === false) {
|
||||||
|
$pool->{$setFunction}($argument);
|
||||||
|
$this->assertEquals($argument, $pool->{$getFunction}());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArgumentsDataProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'origins arguments valid' => [
|
||||||
|
'setOrigins', [[['name' => 'test', 'address' => 'server1.example.com']]], 'getOrigins', false
|
||||||
|
],
|
||||||
|
'setNotificationEmail arguments valid' => [
|
||||||
|
'setNotificationEmail', ['user@example.com'], 'getNotificationEmail', false
|
||||||
|
],
|
||||||
|
'origins arguments invalid no address' => [
|
||||||
|
'setOrigins', [['name' => 'test']], 'getOrigins', true
|
||||||
|
],
|
||||||
|
'origins arguments invalid no name' => [
|
||||||
|
'setOrigins', [['address' => 'server1.example.com']], 'getOrigins', true
|
||||||
|
],
|
||||||
|
'setNotificationEmail arguments invalid' => [
|
||||||
|
'setNotificationEmail', ['userexample.com'], 'getNotificationEmail', true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: junade
|
|
||||||
* Date: 05/09/2017
|
|
||||||
* Time: 13:50
|
|
||||||
*/
|
|
||||||
class ConfigurationZoneLockdownTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testGetArray()
|
|
||||||
{
|
|
||||||
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
|
|
||||||
$configuration->addIP('1.2.3.4');
|
|
||||||
|
|
||||||
$array = $configuration->getArray();
|
|
||||||
$this->assertEquals(1, sizeof($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);
|
|
||||||
|
|
||||||
$configuration->addIPRange('1.2.3.4/24');
|
|
||||||
|
|
||||||
$array = $configuration->getArray();
|
|
||||||
$this->assertEquals(2, sizeof($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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
112
tests/Endpoints/AccessRulesTest.php
Normal file
112
tests/Endpoints/AccessRulesTest.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class AccessRulesTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListRules()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccessRules.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 50,
|
||||||
|
'match' => 'all'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$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()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\AccessRules();
|
||||||
|
$config->setIP('1.2.3.4');
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccessRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'challenge',
|
||||||
|
'configuration' => $config->getArray(),
|
||||||
|
'notes' => 'This rule is on because of an event that occured on date X',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->createRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'challenge',
|
||||||
|
$config,
|
||||||
|
'This rule is on because of an event that occured on date X'
|
||||||
|
);
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateAccessRule.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/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'challenge',
|
||||||
|
'notes' => 'This rule is on because of an event that occured on date X',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->updateRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'92f17202ed8bd63d69a66b86a49a8f6b',
|
||||||
|
'challenge',
|
||||||
|
'This rule is on because of an event that occured on date X'
|
||||||
|
);
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteAccessRule.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/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||||
|
$this->equalTo([
|
||||||
|
'cascade' => 'none'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b');
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
tests/Endpoints/CryptoTest.php
Normal file
82
tests/Endpoints/CryptoTest.php
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class CryptoTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetOpportunisticEncryptionSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOpportunisticEncryptionSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption')
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->getOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetOnionRoutingSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOnionRoutingSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion')
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->getOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateOpportunisticEncryptionSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.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/opportunistic_encryption'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->updateOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateOnionRoutingSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOnionRoutingSetting.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/opportunistic_onion'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->updateOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
138
tests/Endpoints/CustomHostnamesTest.php
Normal file
138
tests/Endpoints/CustomHostnamesTest.php
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 18/03/2018
|
||||||
|
* Time: 22:23
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Endpoints\CustomHostnames;
|
||||||
|
|
||||||
|
class CustomHostnamesTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testAddHostname()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
||||||
|
$this->equalTo([
|
||||||
|
'hostname' => 'app.example.com',
|
||||||
|
'ssl' => [
|
||||||
|
'method' => 'http',
|
||||||
|
'type' => 'dv'
|
||||||
|
]
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$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()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listHostnames.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
||||||
|
$this->equalTo([
|
||||||
|
'hostname' => 'app.example.com',
|
||||||
|
'id' => '0d89c70d-ad9f-4843-b99f-6cc0252067e9',
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'order' => 'ssl',
|
||||||
|
'direction' => 'desc',
|
||||||
|
'ssl' => 0
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||||
|
$result = $zones->listHostnames('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 1, 20, 'ssl', 'desc', 0);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$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()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHostname.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||||
|
$result = $zones->getHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('id', $result);
|
||||||
|
$this->assertObjectHasAttribute('hostname', $result);
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateHostname()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.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/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
||||||
|
$this->equalTo([
|
||||||
|
'ssl' => [
|
||||||
|
'method' => 'http',
|
||||||
|
'type' => 'dv'
|
||||||
|
]
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||||
|
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('id', $result);
|
||||||
|
$this->assertObjectHasAttribute('hostname', $result);
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteHostname()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteHostname.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/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')
|
->method('post')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'type' => 'A',
|
'type' => 'A',
|
||||||
'name' => 'example.com',
|
'name' => 'example.com',
|
||||||
@@ -44,26 +43,27 @@ class DNSTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
'match' => 'all',
|
'match' => 'all',
|
||||||
'type' => 'A',
|
'type' => 'A',
|
||||||
'name' => 'example.com',
|
'name' => 'example.com',
|
||||||
'content' => '127.0.0.1',
|
'content' => '127.0.0.1',
|
||||||
'order' => 'type',
|
'order' => 'type',
|
||||||
'direction' => 'desc']),
|
'direction' => 'desc',
|
||||||
$this->equalTo([])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
$result = $zones->listRecords("023e105f4ecef8ad9ca31a8372d0c353", "A", "example.com", "127.0.0.1", 1, 20, "type", "desc", "all");
|
$result = $zones->listRecords('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', 1, 20, 'type', 'desc');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetDNSRecordDetails()
|
public function testGetDNSRecordDetails()
|
||||||
@@ -76,14 +76,33 @@ class DNSTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
$result = $dns->getRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetRecordID()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordId.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records')
|
||||||
|
);
|
||||||
|
|
||||||
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
|
$result = $dns->getRecordID('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com');
|
||||||
|
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateDNSRecord()
|
public function testUpdateDNSRecord()
|
||||||
@@ -95,8 +114,8 @@ class DNSTest extends TestCase
|
|||||||
|
|
||||||
$details = [
|
$details = [
|
||||||
'type' => 'A',
|
'type' => 'A',
|
||||||
'name' => "example.com",
|
'name' => 'example.com',
|
||||||
'content' => "1.2.3.4",
|
'content' => '1.2.3.4',
|
||||||
'ttl' => 120,
|
'ttl' => 120,
|
||||||
'proxied' => false,
|
'proxied' => false,
|
||||||
];
|
];
|
||||||
@@ -105,14 +124,14 @@ class DNSTest extends TestCase
|
|||||||
->method('put')
|
->method('put')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo($details)
|
$this->equalTo($details)
|
||||||
);
|
);
|
||||||
|
|
||||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
$result = $dns->updateRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59", $details);
|
$result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
||||||
|
|
||||||
foreach ($details as $property => $value) {
|
foreach ($details as $property => $value) {
|
||||||
$this->assertEquals($result->result->{ $property }, $value);
|
$this->assertEquals($result->result->{ $property }, $value);
|
||||||
|
|||||||
121
tests/Endpoints/FirewallSettingsTest.php
Normal file
121
tests/Endpoints/FirewallSettingsTest.php
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class FirewallSettingsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetSecurityLevelSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSecurityLevelSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/security_level')
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->getSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('medium', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetChallengeTTLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getChallengeTTLSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/challenge_ttl')
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->getChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals(1800, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetBrowserIntegrityCheckSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserIntegrityCheckSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/browser_check')
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->getBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('on', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateSecurityLevelSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSecurityLevelSetting.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/security_level'),
|
||||||
|
$this->equalTo(['value' => 'medium'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->updateSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'medium');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateChallengeTTLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateChallengeTTLSetting.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/challenge_ttl'),
|
||||||
|
$this->equalTo(['value' => 1800])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->updateChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 1800);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateBrowserIntegrityCheckSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserIntegrityCheckSetting.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/browser_check'),
|
||||||
|
$this->equalTo(['value' => 'on'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->updateBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'on');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,8 +6,6 @@
|
|||||||
* Time: 20:16
|
* Time: 20:16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\IPs;
|
|
||||||
|
|
||||||
class IPsTest extends TestCase
|
class IPsTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testListIPs()
|
public function testListIPs()
|
||||||
@@ -20,13 +18,14 @@ class IPsTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('ips'),
|
$this->equalTo('ips')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
$ipsMock = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||||
$ips = $ips->listIPs();
|
$ips = $ipsMock->listIPs();
|
||||||
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
|
$this->assertObjectHasAttribute('ipv4_cidrs', $ips);
|
||||||
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
|
$this->assertObjectHasAttribute('ipv6_cidrs', $ips);
|
||||||
|
$this->assertObjectHasAttribute('ipv4_cidrs', $ipsMock->getBody()->result);
|
||||||
|
$this->assertObjectHasAttribute('ipv6_cidrs', $ipsMock->getBody()->result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
128
tests/Endpoints/LoadBalancersTest.php
Normal file
128
tests/Endpoints/LoadBalancersTest.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\LoadBalancer;
|
||||||
|
use Cloudflare\API\Endpoints\LoadBalancers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
class LoadBalancersTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreateLoadBalancer()
|
||||||
|
{
|
||||||
|
$pools = [
|
||||||
|
'17b5962d775c646f3f9725cbc7a53df4',
|
||||||
|
'9290f38c5d07c2e2f4df57b1f61d4196',
|
||||||
|
'00920f38ce07c2e2f4df50b1f61d4194'
|
||||||
|
];
|
||||||
|
|
||||||
|
$lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createLoadBalancer.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers'),
|
||||||
|
$lbConfiguration->getArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$result = $loadBalancers->createLoadBalancer('699d98642c564d2e855e9661899b7252', $lbConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListLoadBalancer()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listLoadBalancers.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers')
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$loadBalancers->listLoadBalancers('699d98642c564d2e855e9661899b7252');
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetLoadBalancerDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getLoadBalancerDetails.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252')
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$loadBalancers->getLoadBalancerDetails('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252');
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateLoadBalancer()
|
||||||
|
{
|
||||||
|
$pools = [
|
||||||
|
'17b5962d775c646f3f9725cbc7a53df4',
|
||||||
|
'9290f38c5d07c2e2f4df57b1f61d4196',
|
||||||
|
'00920f38ce07c2e2f4df50b1f61d4194'
|
||||||
|
];
|
||||||
|
|
||||||
|
$lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateLoadBalancer.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252'),
|
||||||
|
$this->equalTo($lbConfiguration->getArray())
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$result = $loadBalancers->updateLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252', $lbConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteLoadBalancer()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteLoadBalancer.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252')
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$result = $loadBalancers->deleteLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
93
tests/Endpoints/MembershipTest.php
Normal file
93
tests/Endpoints/MembershipTest.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
class MembershipTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListMemberships()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listMemberships.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('memberships'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'account.name' => 'Demo Account',
|
||||||
|
'status' => 'accepted',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
$result = $zones->listMemberships('Demo Account', 'accepted', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $zones->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMembershipDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getMembershipDetails.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
$details = $membership->getMembershipDetails('4536bcfad5faccb111b47003c79917fa');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('id', $details);
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $details->id);
|
||||||
|
$this->assertObjectHasAttribute('code', $details);
|
||||||
|
$this->assertEquals('05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0', $details->code);
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateMembershipDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateMembershipStatus.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'),
|
||||||
|
$this->equalTo([
|
||||||
|
'status' => 'accepted'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
$membership->updateMembershipStatus('4536bcfad5faccb111b47003c79917fa', 'accepted');
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteMembership()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteMembership.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with($this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'));
|
||||||
|
|
||||||
|
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
|
||||||
|
$membership->deleteMembership('4536bcfad5faccb111b47003c79917fa');
|
||||||
|
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,8 +6,6 @@
|
|||||||
* Time: 19:25
|
* Time: 19:25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\PageRules;
|
|
||||||
|
|
||||||
class PageRulesTest extends TestCase
|
class PageRulesTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testCreatePageRule()
|
public function testCreatePageRule()
|
||||||
@@ -25,7 +23,6 @@ class PageRulesTest extends TestCase
|
|||||||
->method('post')
|
->method('post')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'targets' => $target->getArray(),
|
'targets' => $target->getArray(),
|
||||||
'actions' => $action->getArray(),
|
'actions' => $action->getArray(),
|
||||||
@@ -38,6 +35,7 @@ class PageRulesTest extends TestCase
|
|||||||
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListPageRules()
|
public function testListPageRules()
|
||||||
@@ -51,17 +49,17 @@ class PageRulesTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'status' => 'active',
|
'status' => 'active',
|
||||||
'order' => 'status',
|
'order' => 'status',
|
||||||
'direction' => 'desc',
|
'direction' => 'desc',
|
||||||
'match' => 'all'
|
'match' => 'all'
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPageRuleDetails()
|
public function testGetPageRuleDetails()
|
||||||
@@ -74,12 +72,12 @@ class PageRulesTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdatePageRule()
|
public function testUpdatePageRule()
|
||||||
@@ -96,8 +94,7 @@ class PageRulesTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('patch')
|
->method('patch')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'targets' => $target->getArray(),
|
'targets' => $target->getArray(),
|
||||||
'actions' => $action->getArray(),
|
'actions' => $action->getArray(),
|
||||||
@@ -107,9 +104,10 @@ class PageRulesTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac', $target, $action, true, 1);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeletePageRule()
|
public function testDeletePageRule()
|
||||||
@@ -122,14 +120,13 @@ class PageRulesTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
133
tests/Endpoints/PoolsTest.php
Normal file
133
tests/Endpoints/PoolsTest.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Endpoints\Pools;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PoolsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreatePool()
|
||||||
|
{
|
||||||
|
$origins = [
|
||||||
|
[
|
||||||
|
'name' => 'app-server-1',
|
||||||
|
'address' => '0.0.0.0',
|
||||||
|
'enabled' => true,
|
||||||
|
'weight' => 0.56
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins);
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPool.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools'),
|
||||||
|
$poolConfiguration->getArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$result = $pools->createPool('01a7362d577a6c3019a474fd6f485823', $poolConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListPools()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPools.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$pools->listPools('01a7362d577a6c3019a474fd6f485823');
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPoolDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPoolDetails.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$pools->getPoolDetails('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdatePool()
|
||||||
|
{
|
||||||
|
$origins = [
|
||||||
|
[
|
||||||
|
'name' => 'app-server-1',
|
||||||
|
'address' => '0.0.0.0',
|
||||||
|
'enabled' => true,
|
||||||
|
'weight' => 0.56
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins);
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePool.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4'),
|
||||||
|
$this->equalTo($poolConfiguration->getArray())
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$result = $pools->updatePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4', $poolConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeletePool()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePool.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$result = $pools->deletePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,14 +6,12 @@
|
|||||||
* Time: 11:20
|
* Time: 11:20
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\Railgun;
|
|
||||||
|
|
||||||
class RailgunTest extends TestCase
|
class RailgunTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testcreate()
|
public function testcreate()
|
||||||
{
|
{
|
||||||
$details = [
|
$details = [
|
||||||
'name' => "My Railgun",
|
'name' => 'My Railgun',
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRailgun.json');
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRailgun.json');
|
||||||
@@ -25,7 +23,6 @@ class RailgunTest extends TestCase
|
|||||||
->method('post')
|
->method('post')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('railguns'),
|
$this->equalTo('railguns'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo(['name' => $details['name']])
|
$this->equalTo(['name' => $details['name']])
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -37,6 +34,7 @@ class RailgunTest extends TestCase
|
|||||||
foreach ($details as $property => $value) {
|
foreach ($details as $property => $value) {
|
||||||
$this->assertEquals($result->result->{ $property }, $value);
|
$this->assertEquals($result->result->{ $property }, $value);
|
||||||
}
|
}
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testlist()
|
public function testlist()
|
||||||
@@ -54,15 +52,15 @@ class RailgunTest extends TestCase
|
|||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
'direction' => 'desc'
|
'direction' => 'desc'
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
$result = $railgun->list(1, 20, "desc");
|
$result = $railgun->list(1, 20, 'desc');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testget()
|
public function testget()
|
||||||
@@ -75,14 +73,14 @@ class RailgunTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
$result = $railgun->get("e928d310693a83094309acf9ead50448");
|
$result = $railgun->get('e928d310693a83094309acf9ead50448');
|
||||||
|
|
||||||
$this->assertEquals("e928d310693a83094309acf9ead50448", $result->id);
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testgetZones()
|
public function testgetZones()
|
||||||
@@ -95,16 +93,15 @@ class RailgunTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones'),
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones')
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
$result = $railgun->getZones("e928d310693a83094309acf9ead50448");
|
$result = $railgun->getZones('e928d310693a83094309acf9ead50448');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $railgun->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testupdate()
|
public function testupdate()
|
||||||
@@ -122,14 +119,14 @@ class RailgunTest extends TestCase
|
|||||||
->method('patch')
|
->method('patch')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo($details)
|
$this->equalTo($details)
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
$result = $waf->update("e928d310693a83094309acf9ead50448", true);
|
$result = $waf->update('e928d310693a83094309acf9ead50448', true);
|
||||||
|
|
||||||
$this->assertEquals("e928d310693a83094309acf9ead50448", $result->id);
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testdelete()
|
public function testdelete()
|
||||||
@@ -142,12 +139,11 @@ class RailgunTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
$waf->delete("e928d310693a83094309acf9ead50448");
|
$waf->delete('e928d310693a83094309acf9ead50448');
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
141
tests/Endpoints/SSLTest.php
Normal file
141
tests/Endpoints/SSLTest.php
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class SSLTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetSSLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSSLVerificationStatus()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertEquals('active', $result->result{0}->certificate_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetHTTPSRedirectSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRedirectSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetHTTPSRewritesSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRewritesSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateSSLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.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/ssl'),
|
||||||
|
$this->equalTo(['value' => 'full'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateHTTPSRedirectSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRedirectSetting.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/always_use_https'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->updateHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateHTTPSRewritesSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRewritesSetting.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/automatic_https_rewrites'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
110
tests/Endpoints/TLSTest.php
Normal file
110
tests/Endpoints/TLSTest.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Jurgen Coetsiers
|
||||||
|
* Date: 21/10/2018
|
||||||
|
* Time: 09:09
|
||||||
|
*/
|
||||||
|
|
||||||
|
class TLSTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetTLSClientAuth()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getTLSClientAuth.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_client_auth')
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->getTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
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'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->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'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->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'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateTLSClientAuth()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateTLSClientAuth.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_client_auth'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->updateTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,21 +19,21 @@ class UARulesTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20
|
'per_page' => 20
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
|
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateRule()
|
public function testCreateRule()
|
||||||
@@ -50,7 +50,6 @@ class UARulesTest extends TestCase
|
|||||||
->method('post')
|
->method('post')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'mode' => 'js_challenge',
|
'mode' => 'js_challenge',
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
@@ -67,6 +66,7 @@ class UARulesTest extends TestCase
|
|||||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
|
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRuleDetails()
|
public function getRuleDetails()
|
||||||
@@ -79,14 +79,14 @@ class UARulesTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateRule()
|
public function testUpdateRule()
|
||||||
@@ -103,7 +103,6 @@ class UARulesTest extends TestCase
|
|||||||
->method('put')
|
->method('put')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'mode' => 'js_challenge',
|
'mode' => 'js_challenge',
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
@@ -120,6 +119,7 @@ class UARulesTest extends TestCase
|
|||||||
$config,
|
$config,
|
||||||
'Restrict access to these endpoints to requests from a known IP address'
|
'Restrict access to these endpoints to requests from a known IP address'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteRule()
|
public function testDeleteRule()
|
||||||
@@ -132,12 +132,11 @@ class UARulesTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ class UserTest extends TestCase
|
|||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$details = $user->getUserDetails();
|
$details = $user->getUserDetails();
|
||||||
|
|
||||||
$this->assertObjectHasAttribute("id", $details);
|
$this->assertObjectHasAttribute('id', $details);
|
||||||
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $details->id);
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
|
||||||
$this->assertObjectHasAttribute("email", $details);
|
$this->assertObjectHasAttribute('email', $details);
|
||||||
$this->assertEquals("user@example.com", $details->email);
|
$this->assertEquals('user@example.com', $details->email);
|
||||||
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUserID()
|
public function testGetUserID()
|
||||||
@@ -31,7 +32,8 @@ class UserTest extends TestCase
|
|||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $user->getUserID());
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
|
||||||
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUserEmail()
|
public function testGetUserEmail()
|
||||||
@@ -44,7 +46,8 @@ class UserTest extends TestCase
|
|||||||
$mock->expects($this->once())->method('get');
|
$mock->expects($this->once())->method('get');
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$this->assertEquals("user@example.com", $user->getUserEmail());
|
$this->assertEquals('user@example.com', $user->getUserEmail());
|
||||||
|
$this->assertEquals('user@example.com', $user->getBody()->result->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateUserDetails()
|
public function testUpdateUserDetails()
|
||||||
@@ -56,9 +59,10 @@ class UserTest extends TestCase
|
|||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('patch')
|
->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 = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$user->updateUserDetails(['email' => "user2@example.com"]);
|
$user->updateUserDetails(['email' => 'user2@example.com']);
|
||||||
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
* Time: 13:34
|
* Time: 13:34
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\WAF;
|
|
||||||
|
|
||||||
class WAFTest extends TestCase
|
class WAFTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testgetPackages()
|
public function testgetPackages()
|
||||||
@@ -27,18 +25,18 @@ class WAFTest extends TestCase
|
|||||||
'match' => 'all',
|
'match' => 'all',
|
||||||
'order' => 'status',
|
'order' => 'status',
|
||||||
'direction' => 'desc'
|
'direction' => 'desc'
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->getPackages("023e105f4ecef8ad9ca31a8372d0c353", 1, 20, "status", "desc", "all");
|
$result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("a25a9a7e9c00afc1fb2e0245519d725b", $result->result[0]->id);
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testgetPackageInfo()
|
public function testgetPackageInfo()
|
||||||
@@ -51,14 +49,14 @@ class WAFTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->getPackageInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b");
|
$result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b');
|
||||||
|
|
||||||
$this->assertEquals("a25a9a7e9c00afc1fb2e0245519d725b", $result->id);
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id);
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testgetRules()
|
public function testgetRules()
|
||||||
@@ -78,18 +76,18 @@ class WAFTest extends TestCase
|
|||||||
'match' => 'all',
|
'match' => 'all',
|
||||||
'order' => 'status',
|
'order' => 'status',
|
||||||
'direction' => 'desc'
|
'direction' => 'desc'
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->getRules("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", 1, 20, "status", "desc", "all");
|
$result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("92f17202ed8bd63d69a66b86a49a8f6b", $result->result[0]->id);
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $waf->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testgetRuleInfo()
|
public function testgetRuleInfo()
|
||||||
@@ -102,14 +100,14 @@ class WAFTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->getRuleInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "f939de3be84e66e757adcdcb87908023");
|
$result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023');
|
||||||
|
|
||||||
$this->assertEquals("f939de3be84e66e757adcdcb87908023", $result->id);
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testupdateRule()
|
public function testupdateRule()
|
||||||
@@ -120,25 +118,25 @@ class WAFTest extends TestCase
|
|||||||
$mock->method('patch')->willReturn($response);
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
$details = [
|
$details = [
|
||||||
'mode' => "on",
|
'mode' => 'on',
|
||||||
];
|
];
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('patch')
|
->method('patch')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo($details)
|
$this->equalTo($details)
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->updateRule("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "f939de3be84e66e757adcdcb87908023", "on");
|
$result = $waf->updateRule('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023', 'on');
|
||||||
|
|
||||||
$this->assertEquals("f939de3be84e66e757adcdcb87908023", $result->id);
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
|
||||||
|
|
||||||
foreach ($details as $property => $value) {
|
foreach ($details as $property => $value) {
|
||||||
$this->assertEquals($result->{ $property }, $value);
|
$this->assertEquals($result->{ $property }, $value);
|
||||||
}
|
}
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroups()
|
public function getGroups()
|
||||||
@@ -158,18 +156,18 @@ class WAFTest extends TestCase
|
|||||||
'match' => 'all',
|
'match' => 'all',
|
||||||
'order' => 'status',
|
'order' => 'status',
|
||||||
'direction' => 'desc'
|
'direction' => 'desc'
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->getGroups("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", 1, 20, "status", "desc", "all");
|
$result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->result[0]->id);
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testgetGroupInfo()
|
public function testgetGroupInfo()
|
||||||
@@ -182,14 +180,14 @@ class WAFTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->getGroupInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "de677e5818985db1285d0e80225f06e5");
|
$result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5');
|
||||||
|
|
||||||
$this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->id);
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testupdateGroup()
|
public function testupdateGroup()
|
||||||
@@ -200,24 +198,24 @@ class WAFTest extends TestCase
|
|||||||
$mock->method('patch')->willReturn($response);
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
$details = [
|
$details = [
|
||||||
'mode' => "off",
|
'mode' => 'off',
|
||||||
];
|
];
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('patch')
|
->method('patch')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo($details)
|
$this->equalTo($details)
|
||||||
);
|
);
|
||||||
|
|
||||||
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
$result = $waf->updateGroup("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "de677e5818985db1285d0e80225f06e5", "off");
|
$result = $waf->updateGroup('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5', 'off');
|
||||||
|
|
||||||
$this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->id);
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
|
||||||
|
|
||||||
foreach ($details as $property => $value) {
|
foreach ($details as $property => $value) {
|
||||||
$this->assertEquals($result->{ $property }, $value);
|
$this->assertEquals($result->{ $property }, $value);
|
||||||
}
|
}
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,21 +19,21 @@ class ZoneLockdownTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$result = $zones->listLockdowns("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
|
$result = $zones->listLockdowns('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddLockdown()
|
public function testAddLockdown()
|
||||||
@@ -50,9 +50,8 @@ class ZoneLockdownTest extends TestCase
|
|||||||
->method('post')
|
->method('post')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'urls' => ["api.mysite.com/some/endpoint*"],
|
'urls' => ['api.mysite.com/some/endpoint*'],
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
||||||
'configurations' => $config->getArray(),
|
'configurations' => $config->getArray(),
|
||||||
@@ -62,11 +61,12 @@ class ZoneLockdownTest extends TestCase
|
|||||||
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$zoneLockdown->createLockdown(
|
$zoneLockdown->createLockdown(
|
||||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
["api.mysite.com/some/endpoint*"],
|
['api.mysite.com/some/endpoint*'],
|
||||||
$config,
|
$config,
|
||||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
'Restrict access to these endpoints to requests from a known IP address'
|
'Restrict access to these endpoints to requests from a known IP address'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRecordDetails()
|
public function testGetRecordDetails()
|
||||||
@@ -79,14 +79,14 @@ class ZoneLockdownTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$result = $lockdown->getLockdownDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateLockdown()
|
public function testUpdateLockdown()
|
||||||
@@ -103,9 +103,8 @@ class ZoneLockdownTest extends TestCase
|
|||||||
->method('put')
|
->method('put')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'urls' => ["api.mysite.com/some/endpoint*"],
|
'urls' => ['api.mysite.com/some/endpoint*'],
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
'description' => 'Restrict access to these endpoints to requests from a known IP address',
|
||||||
'configurations' => $config->getArray(),
|
'configurations' => $config->getArray(),
|
||||||
@@ -116,10 +115,11 @@ class ZoneLockdownTest extends TestCase
|
|||||||
$zoneLockdown->updateLockdown(
|
$zoneLockdown->updateLockdown(
|
||||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
["api.mysite.com/some/endpoint*"],
|
['api.mysite.com/some/endpoint*'],
|
||||||
$config,
|
$config,
|
||||||
'Restrict access to these endpoints to requests from a known IP address'
|
'Restrict access to these endpoints to requests from a known IP address'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteLockdown()
|
public function testDeleteLockdown()
|
||||||
@@ -135,12 +135,11 @@ class ZoneLockdownTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
|
||||||
$zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
$zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,34 +19,34 @@ class ZonesTest extends TestCase
|
|||||||
->method('post')
|
->method('post')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones'),
|
$this->equalTo('zones'),
|
||||||
$this->equalTo([]),
|
$this->equalTo(['name' => 'example.com', 'jump_start' => false])
|
||||||
$this->equalTo(['name' => 'example.com', 'jumpstart' => false])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->addZone("example.com");
|
$result = $zones->addZone('example.com');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute("id", $result);
|
$this->assertObjectHasAttribute('id', $result);
|
||||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->id);
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->id);
|
||||||
|
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$org = new stdClass();
|
|
||||||
$org->id = "01a7362d577a6c3019a474fd6f485823";
|
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones'),
|
$this->equalTo('zones'),
|
||||||
$this->equalTo([]),
|
$this->equalTo([
|
||||||
$this->equalTo(['name' => 'example.com', 'jumpstart' => true, 'organization' => $org])
|
'name' => 'example.com',
|
||||||
|
'jump_start' => true,
|
||||||
|
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
|
||||||
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$zones->addZone("example.com", true, "01a7362d577a6c3019a474fd6f485823");
|
$zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823');
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testActivationTest()
|
public function testActivationTest()
|
||||||
@@ -59,15 +59,14 @@ class ZonesTest extends TestCase
|
|||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('put')
|
->method('put')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check')
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->activationCheck("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
$result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListZones()
|
public function testListZones()
|
||||||
@@ -81,26 +80,45 @@ class ZonesTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones'),
|
$this->equalTo('zones'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
'match' => 'all',
|
'match' => 'all',
|
||||||
'name' => 'example.com',
|
'name' => 'example.com',
|
||||||
'status' => 'active',
|
'status' => 'active',
|
||||||
'order' => 'status',
|
'order' => 'status',
|
||||||
'direction' => 'desc'
|
'direction' => 'desc',
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
|
$result = $zones->listZones('example.com', 'active', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->result[0]->id);
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetZoneByID()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getZoneById.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353'));
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$result = $zones->getZoneById('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\stdClass::class, $result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||||
|
$this->assertEquals('example.com', $zones->getBody()->result->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetZoneID()
|
public function testGetZoneID()
|
||||||
@@ -114,19 +132,19 @@ class ZonesTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones'),
|
$this->equalTo('zones'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'page' => 1,
|
'page' => 1,
|
||||||
'per_page' => 20,
|
'per_page' => 20,
|
||||||
'match' => 'all',
|
'match' => 'all',
|
||||||
'name' => 'example.com',
|
'name' => 'example.com',
|
||||||
]),
|
])
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->getZoneID("example.com");
|
$result = $zones->getZoneID('example.com');
|
||||||
|
|
||||||
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetAnalyticsDashboard()
|
public function testGetAnalyticsDashboard()
|
||||||
@@ -140,17 +158,16 @@ class ZonesTest extends TestCase
|
|||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
|
||||||
$this->equalTo([]),
|
$this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)])
|
||||||
$this->equalTo(["since" => "-10080", "until" => "0", "continuous" => true])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$analytics = $zones->getAnalyticsDashboard("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
$analytics = $zones->getAnalyticsDashboard('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute("since", $analytics->totals);
|
$this->assertObjectHasAttribute('since', $analytics->totals);
|
||||||
$this->assertObjectHasAttribute("since", $analytics->timeseries[0]);
|
$this->assertObjectHasAttribute('since', $analytics->timeseries[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChangeDevelopmentMode()
|
public function testChangeDevelopmentMode()
|
||||||
{
|
{
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json');
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json');
|
||||||
@@ -162,14 +179,14 @@ class ZonesTest extends TestCase
|
|||||||
->method('patch')
|
->method('patch')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
|
||||||
$this->equalTo([]),
|
$this->equalTo(['value' => 'on'])
|
||||||
$this->equalTo(["value" => "on"])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->changeDevelopmentMode("c2547eb745079dac9320b638f5e225cf483cc5cfdda41", true);
|
$result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('development_mode', $zones->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCachePurgeEverything()
|
public function testCachePurgeEverything()
|
||||||
@@ -183,13 +200,66 @@ class ZonesTest extends TestCase
|
|||||||
->method('delete')
|
->method('delete')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||||
$this->equalTo([]),
|
$this->equalTo(['purge_everything' => true])
|
||||||
$this->equalTo(["purge_everything" => true])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
$result = $zones->cachePurgeEverything("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
|
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$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"
|
||||||
|
}
|
||||||
30
tests/Fixtures/Endpoints/createAccessRule.json
Normal file
30
tests/Fixtures/Endpoints/createAccessRule.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
|
||||||
|
"notes": "This rule is on because of an event that occured on date X",
|
||||||
|
"allowed_modes": [
|
||||||
|
"whitelist",
|
||||||
|
"block",
|
||||||
|
"challenge"
|
||||||
|
],
|
||||||
|
"mode": "challenge",
|
||||||
|
"configuration": {
|
||||||
|
"target": "ip",
|
||||||
|
"value": "1.2.3.4"
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"type": "user"
|
||||||
|
},
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
20
tests/Fixtures/Endpoints/createCustomHostname.json
Normal file
20
tests/Fixtures/Endpoints/createCustomHostname.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
|
||||||
|
"hostname": "app.example.com",
|
||||||
|
"ssl": {
|
||||||
|
"status": "pending_validation",
|
||||||
|
"method": "http",
|
||||||
|
"type": "dv",
|
||||||
|
"cname_target": "dcv.digicert.com",
|
||||||
|
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
tests/Fixtures/Endpoints/createLoadBalancer.json
Normal file
46
tests/Fixtures/Endpoints/createLoadBalancer.json
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "699d98642c564d2e855e9661899b7252",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"description": "Load Balancer for www.example.com",
|
||||||
|
"name": "www.example.com",
|
||||||
|
"enabled": true,
|
||||||
|
"ttl": 30,
|
||||||
|
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"default_pools": [
|
||||||
|
"17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196",
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
],
|
||||||
|
"region_pools": {
|
||||||
|
"WNAM": [
|
||||||
|
"de90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"ENAM": [
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"pop_pools": {
|
||||||
|
"LAX": [
|
||||||
|
"de90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"LHR": [
|
||||||
|
"abd90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"f9138c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"SJC": [
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"proxied": true,
|
||||||
|
"steering_policy": "dynamic_latency",
|
||||||
|
"session_affinity": "cookie",
|
||||||
|
"session_affinity_ttl": 5000
|
||||||
|
}
|
||||||
|
}
|
||||||
28
tests/Fixtures/Endpoints/createPool.json
Normal file
28
tests/Fixtures/Endpoints/createPool.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"description": "Primary data center - Provider XYZ",
|
||||||
|
"name": "primary-dc-1",
|
||||||
|
"enabled": true,
|
||||||
|
"minimum_origins": 2,
|
||||||
|
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
|
||||||
|
"check_regions": [
|
||||||
|
"WEU",
|
||||||
|
"ENAM"
|
||||||
|
],
|
||||||
|
"origins": [
|
||||||
|
{
|
||||||
|
"name": "app-server-1",
|
||||||
|
"address": "0.0.0.0",
|
||||||
|
"enabled": true,
|
||||||
|
"weight": 0.56
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"notification_email": "someone@example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
tests/Fixtures/Endpoints/deleteAccessRule.json
Normal file
12
tests/Fixtures/Endpoints/deleteAccessRule.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b"
|
||||||
|
}
|
||||||
|
}
|
||||||
3
tests/Fixtures/Endpoints/deleteHostname.json
Normal file
3
tests/Fixtures/Endpoints/deleteHostname.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9"
|
||||||
|
}
|
||||||
8
tests/Fixtures/Endpoints/deleteLoadBalancer.json
Normal file
8
tests/Fixtures/Endpoints/deleteLoadBalancer.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "699d98642c564d2e855e9661899b7252"
|
||||||
|
}
|
||||||
|
}
|
||||||
8
tests/Fixtures/Endpoints/deleteMembership.json
Normal file
8
tests/Fixtures/Endpoints/deleteMembership.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "4536bcfad5faccb111b47003c79917fa"
|
||||||
|
}
|
||||||
|
}
|
||||||
8
tests/Fixtures/Endpoints/deletePool.json
Normal file
8
tests/Fixtures/Endpoints/deletePool.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "17b5962d775c646f3f9725cbc7a53df4"
|
||||||
|
}
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "browser_check",
|
||||||
|
"value": "on",
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
tests/Fixtures/Endpoints/getChallengeTTLSetting.json
Normal file
11
tests/Fixtures/Endpoints/getChallengeTTLSetting.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "challenge_ttl",
|
||||||
|
"value": 1800,
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json
Normal file
6
tests/Fixtures/Endpoints/getHTTPSRedirectSetting.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": "off"
|
||||||
|
}
|
||||||
6
tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json
Normal file
6
tests/Fixtures/Endpoints/getHTTPSRewritesSetting.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": "off"
|
||||||
|
}
|
||||||
20
tests/Fixtures/Endpoints/getHostname.json
Normal file
20
tests/Fixtures/Endpoints/getHostname.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
|
||||||
|
"hostname": "app.example.com",
|
||||||
|
"ssl": {
|
||||||
|
"status": "pending_validation",
|
||||||
|
"method": "http",
|
||||||
|
"type": "dv",
|
||||||
|
"cname_target": "dcv.digicert.com",
|
||||||
|
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
tests/Fixtures/Endpoints/getLoadBalancerDetails.json
Normal file
46
tests/Fixtures/Endpoints/getLoadBalancerDetails.json
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "699d98642c564d2e855e9661899b7252",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"description": "Load Balancer for www.example.com",
|
||||||
|
"name": "www.example.com",
|
||||||
|
"enabled": true,
|
||||||
|
"ttl": 30,
|
||||||
|
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"default_pools": [
|
||||||
|
"17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196",
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
],
|
||||||
|
"region_pools": {
|
||||||
|
"WNAM": [
|
||||||
|
"de90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"ENAM": [
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"pop_pools": {
|
||||||
|
"LAX": [
|
||||||
|
"de90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"LHR": [
|
||||||
|
"abd90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"f9138c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"SJC": [
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"proxied": true,
|
||||||
|
"steering_policy": "dynamic_latency",
|
||||||
|
"session_affinity": "cookie",
|
||||||
|
"session_affinity_ttl": 5000
|
||||||
|
}
|
||||||
|
}
|
||||||
70
tests/Fixtures/Endpoints/getMembershipDetails.json
Normal file
70
tests/Fixtures/Endpoints/getMembershipDetails.json
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "4536bcfad5faccb111b47003c79917fa",
|
||||||
|
"code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0",
|
||||||
|
"status": "accepted",
|
||||||
|
"account": {
|
||||||
|
"id": "01a7362d577a6c3019a474fd6f485823",
|
||||||
|
"name": "Demo Account",
|
||||||
|
"settings": {
|
||||||
|
"enforce_twofactor": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"roles": [
|
||||||
|
"Account Administrator"
|
||||||
|
],
|
||||||
|
"permissions": {
|
||||||
|
"analytics": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"billing": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"cache_purge": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"dns": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"dns_records": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"lb": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"logs": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"organization": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"waf": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"zones": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"zone_settings": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
tests/Fixtures/Endpoints/getOnionRoutingSetting.json
Normal file
6
tests/Fixtures/Endpoints/getOnionRoutingSetting.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": "off"
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "opportunistic_encryption",
|
||||||
|
"value": "off",
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
28
tests/Fixtures/Endpoints/getPoolDetails.json
Normal file
28
tests/Fixtures/Endpoints/getPoolDetails.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"description": "Primary data center - Provider XYZ",
|
||||||
|
"name": "primary-dc-1",
|
||||||
|
"enabled": true,
|
||||||
|
"minimum_origins": 2,
|
||||||
|
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
|
||||||
|
"check_regions": [
|
||||||
|
"WEU",
|
||||||
|
"ENAM"
|
||||||
|
],
|
||||||
|
"origins": [
|
||||||
|
{
|
||||||
|
"name": "app-server-1",
|
||||||
|
"address": "0.0.0.0",
|
||||||
|
"enabled": true,
|
||||||
|
"weight": 0.56
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"notification_email": "someone@example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
29
tests/Fixtures/Endpoints/getRecordId.json
Normal file
29
tests/Fixtures/Endpoints/getRecordId.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
||||||
|
"type": "A",
|
||||||
|
"name": "example.com",
|
||||||
|
"content": "198.51.100.4",
|
||||||
|
"proxiable": true,
|
||||||
|
"proxied": false,
|
||||||
|
"ttl": {},
|
||||||
|
"locked": false,
|
||||||
|
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||||
|
"zone_name": "example.com",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"total_pages": 1,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
11
tests/Fixtures/Endpoints/getSSLSetting.json
Normal file
11
tests/Fixtures/Endpoints/getSSLSetting.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "ssl",
|
||||||
|
"value": "off",
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
16
tests/Fixtures/Endpoints/getSSLVerificationStatus.json
Normal file
16
tests/Fixtures/Endpoints/getSSLVerificationStatus.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"certificate_status": "active",
|
||||||
|
"verification_type": "cname",
|
||||||
|
"verification_status": true,
|
||||||
|
"verification_info": {
|
||||||
|
"record_name": "b3b90cfedd89a3e487d3e383c56c4267.example.com",
|
||||||
|
"record_target": "6979be7e4cfc9e5c603e31df7efac9cc60fee82d.comodoca.com"
|
||||||
|
},
|
||||||
|
"brand_check": false,
|
||||||
|
"validation_method": "txt",
|
||||||
|
"cert_pack_uuid": "a77f8bd7-3b47-46b4-a6f1-75cf98109948"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
11
tests/Fixtures/Endpoints/getSecurityLevelSetting.json
Normal file
11
tests/Fixtures/Endpoints/getSecurityLevelSetting.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "security_level",
|
||||||
|
"value": "medium",
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
tests/Fixtures/Endpoints/getTLSClientAuth.json
Normal file
11
tests/Fixtures/Endpoints/getTLSClientAuth.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "tls_client_auth",
|
||||||
|
"value": "off",
|
||||||
|
"editable": true,
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
59
tests/Fixtures/Endpoints/getZoneById.json
Normal file
59
tests/Fixtures/Endpoints/getZoneById.json
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": {
|
||||||
|
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||||
|
"name": "example.com",
|
||||||
|
"development_mode": 7200,
|
||||||
|
"original_name_servers": [
|
||||||
|
"ns1.originaldnshost.com",
|
||||||
|
"ns2.originaldnshost.com"
|
||||||
|
],
|
||||||
|
"original_registrar": "GoDaddy",
|
||||||
|
"original_dnshost": "NameCheap",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"activated_on": "2014-01-02T00:01:00.12345Z",
|
||||||
|
"owner": {
|
||||||
|
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"type": "user"
|
||||||
|
},
|
||||||
|
"account": {
|
||||||
|
"id": "01a7362d577a6c3019a474fd6f485823",
|
||||||
|
"name": "Demo Account"
|
||||||
|
},
|
||||||
|
"permissions": [
|
||||||
|
"#zone:read",
|
||||||
|
"#zone:edit"
|
||||||
|
],
|
||||||
|
"plan": {
|
||||||
|
"id": "e592fd9519420ba7405e1307bff33214",
|
||||||
|
"name": "Pro Plan",
|
||||||
|
"price": 20,
|
||||||
|
"currency": "USD",
|
||||||
|
"frequency": "monthly",
|
||||||
|
"legacy_id": "pro",
|
||||||
|
"is_subscribed": true,
|
||||||
|
"can_subscribe": true
|
||||||
|
},
|
||||||
|
"plan_pending": {
|
||||||
|
"id": "e592fd9519420ba7405e1307bff33214",
|
||||||
|
"name": "Pro Plan",
|
||||||
|
"price": 20,
|
||||||
|
"currency": "USD",
|
||||||
|
"frequency": "monthly",
|
||||||
|
"legacy_id": "pro",
|
||||||
|
"is_subscribed": true,
|
||||||
|
"can_subscribe": true
|
||||||
|
},
|
||||||
|
"status": "active",
|
||||||
|
"paused": false,
|
||||||
|
"type": "full",
|
||||||
|
"name_servers": [
|
||||||
|
"tony.ns.cloudflare.com",
|
||||||
|
"woz.ns.cloudflare.com"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
38
tests/Fixtures/Endpoints/listAccessRules.json
Normal file
38
tests/Fixtures/Endpoints/listAccessRules.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
|
||||||
|
"notes": "This rule is on because of an event that occured on date X",
|
||||||
|
"allowed_modes": [
|
||||||
|
"whitelist",
|
||||||
|
"block",
|
||||||
|
"challenge"
|
||||||
|
],
|
||||||
|
"mode": "challenge",
|
||||||
|
"configuration": {
|
||||||
|
"target": "ip",
|
||||||
|
"value": "1.2.3.4"
|
||||||
|
},
|
||||||
|
"scope": {
|
||||||
|
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"type": "user"
|
||||||
|
},
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
28
tests/Fixtures/Endpoints/listHostnames.json
Normal file
28
tests/Fixtures/Endpoints/listHostnames.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"messages": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
|
||||||
|
"hostname": "app.example.com",
|
||||||
|
"ssl": {
|
||||||
|
"status": "pending_validation",
|
||||||
|
"method": "http",
|
||||||
|
"type": "dv",
|
||||||
|
"cname_target": "dcv.digicert.com",
|
||||||
|
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
54
tests/Fixtures/Endpoints/listLoadBalancers.json
Normal file
54
tests/Fixtures/Endpoints/listLoadBalancers.json
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "699d98642c564d2e855e9661899b7252",
|
||||||
|
"created_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"modified_on": "2014-01-01T05:20:00.12345Z",
|
||||||
|
"description": "Load Balancer for www.example.com",
|
||||||
|
"name": "www.example.com",
|
||||||
|
"enabled": true,
|
||||||
|
"ttl": 30,
|
||||||
|
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"default_pools": [
|
||||||
|
"17b5962d775c646f3f9725cbc7a53df4",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196",
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
],
|
||||||
|
"region_pools": {
|
||||||
|
"WNAM": [
|
||||||
|
"de90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"ENAM": [
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"pop_pools": {
|
||||||
|
"LAX": [
|
||||||
|
"de90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"9290f38c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"LHR": [
|
||||||
|
"abd90f38ced07c2e2f4df50b1f61d4194",
|
||||||
|
"f9138c5d07c2e2f4df57b1f61d4196"
|
||||||
|
],
|
||||||
|
"SJC": [
|
||||||
|
"00920f38ce07c2e2f4df50b1f61d4194"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"proxied": true,
|
||||||
|
"steering_policy": "dynamic_latency",
|
||||||
|
"session_affinity": "cookie",
|
||||||
|
"session_affinity_ttl": 5000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
78
tests/Fixtures/Endpoints/listMemberships.json
Normal file
78
tests/Fixtures/Endpoints/listMemberships.json
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"errors": [],
|
||||||
|
"messages": [],
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"id": "4536bcfad5faccb111b47003c79917fa",
|
||||||
|
"code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0",
|
||||||
|
"status": "accepted",
|
||||||
|
"account": {
|
||||||
|
"id": "01a7362d577a6c3019a474fd6f485823",
|
||||||
|
"name": "Demo Account",
|
||||||
|
"settings": {
|
||||||
|
"enforce_twofactor": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"roles": [
|
||||||
|
"Account Administrator"
|
||||||
|
],
|
||||||
|
"permissions": {
|
||||||
|
"analytics": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"billing": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"cache_purge": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"dns": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"dns_records": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"lb": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"logs": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"organization": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"ssl": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"waf": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"zones": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"zone_settings": {
|
||||||
|
"read": true,
|
||||||
|
"write": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result_info": {
|
||||||
|
"page": 1,
|
||||||
|
"per_page": 20,
|
||||||
|
"count": 1,
|
||||||
|
"total_count": 2000
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user