Compare commits
141 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f4b9092175 | |||
|
|
7e89626b59 | ||
|
|
b2187e7b52 | ||
|
|
04e2032e9f | ||
|
|
7a839dfc2a | ||
|
|
10e3e120e4 | ||
|
|
369160682d | ||
|
|
66e2ba45ca | ||
|
|
9a5995970b | ||
|
|
c289ef2ef7 | ||
|
|
1c97befdd8 | ||
|
|
0f602b563b | ||
|
|
aa10bcba3c | ||
|
|
6ea062af19 | ||
|
|
4df937f767 | ||
|
|
fdfc656aa8 | ||
|
|
5024c2ab53 | ||
|
|
12ac2bbd76 | ||
|
|
99d8cfb71c | ||
|
|
bf796b9ec8 | ||
|
|
7f72427fa1 | ||
|
|
30f7fc050e | ||
|
|
9f6be70d92 | ||
|
|
250bf77605 | ||
|
|
d97cf24ee2 | ||
|
|
ba875c32ca | ||
|
|
1b80a3bae7 | ||
|
|
f88a145785 | ||
|
|
e7cc9e067f | ||
|
|
fd55a526b3 | ||
|
|
bfb24200d5 | ||
|
|
3b167bab04 | ||
|
|
c66022e7bf | ||
|
|
a73da76e73 | ||
|
|
aa43a1ea36 | ||
|
|
63b11374f2 | ||
|
|
410b8bebff | ||
|
|
60cdacdfcf | ||
|
|
dfbc5a10d2 | ||
|
|
969fc8cb59 | ||
|
|
a281dd11e7 | ||
|
|
ed822d19ff | ||
|
|
3e605dfa53 | ||
|
|
d9958973e0 | ||
|
|
fd34eaf813 | ||
|
|
be886c36cb | ||
|
|
1a2d2ae708 | ||
|
|
2030e29593 | ||
|
|
5394ec3cc8 | ||
|
|
aea57e4994 | ||
|
|
f8124e76cb | ||
|
|
da3d10c4ee | ||
|
|
135b9a6813 | ||
|
|
f473e5f73c | ||
|
|
9955166ae8 | ||
|
|
c639f20cea | ||
|
|
1e58a65888 | ||
|
|
658ab3fe47 | ||
|
|
d2c4d225e0 | ||
|
|
c58f340633 | ||
|
|
6fbf95f480 | ||
|
|
af14a5f003 | ||
|
|
7db3d6e62c | ||
|
|
6d9b4ddffe | ||
|
|
fab493d2d3 | ||
|
|
afd332a747 | ||
|
|
ffc3989607 | ||
|
|
06de5b0c04 | ||
|
|
8879ba4c0a | ||
|
|
d1b6dd577f | ||
|
|
c575b3bc9b | ||
|
|
251ab5247d | ||
|
|
eaa390497e | ||
|
|
59e8506a45 | ||
|
|
66a2c6ebd7 | ||
|
|
544ef73299 | ||
|
|
694342f718 | ||
|
|
ca426abc32 | ||
|
|
2a83d24954 | ||
|
|
445bc30be7 | ||
|
|
2dc59ddcca | ||
|
|
54545a371e | ||
|
|
27ae3718d4 | ||
|
|
f2e0d6cbe3 | ||
|
|
ed91e639be | ||
|
|
adfb6d28d2 | ||
|
|
9d0df44838 | ||
|
|
6e6a850d62 | ||
|
|
b9051fc1f2 | ||
|
|
b54c3481a3 | ||
|
|
8310111b11 | ||
|
|
f0892ac64f | ||
|
|
d918f7b99e | ||
|
|
f4c2f546b0 | ||
|
|
1be0e794d9 | ||
|
|
9b9984d5fd | ||
|
|
c0198f352a | ||
|
|
39ec310026 | ||
|
|
7276b61e20 | ||
|
|
4e1a12bdea | ||
|
|
61e80bd25f | ||
|
|
ffefe1480a | ||
|
|
f7d9f511ab | ||
|
|
639be12f7a | ||
|
|
2ba05a3ba5 | ||
|
|
1211b644e0 | ||
|
|
58ba140930 | ||
|
|
56b760bb06 | ||
|
|
469d66e92a | ||
|
|
171c6689af | ||
|
|
fd17c57b62 | ||
|
|
647705b852 | ||
|
|
28e1378506 | ||
|
|
39b2f2fd2a | ||
|
|
c49409b978 | ||
|
|
d895b50e47 | ||
|
|
efae17f29d | ||
|
|
ecbe2fe552 | ||
|
|
6a80cb69e2 | ||
|
|
8e279f2217 | ||
|
|
274517553c | ||
|
|
4cb9eb228e | ||
|
|
c525cef45c | ||
|
|
818e6e4505 | ||
|
|
440492e41c | ||
|
|
cb24d2c77f | ||
|
|
9561740484 | ||
|
|
1e2b630964 | ||
|
|
8364249fbb | ||
|
|
22a87e1b91 | ||
|
|
68d862f7da | ||
|
|
66ec1b318f | ||
|
|
29ab101130 | ||
|
|
48404cd0ac | ||
|
|
c5b6bceecb | ||
|
|
89986cfb02 | ||
|
|
b7dfc9e0f1 | ||
|
|
b04abe73bc | ||
|
|
44eb77f9ca | ||
|
|
fb45932677 | ||
|
|
dde2de4495 |
40
.github/workflows/lint.yml
vendored
Normal file
40
.github/workflows/lint.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: Lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ '*' ]
|
||||
pull_request:
|
||||
branches: [ '*' ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
|
||||
- name: Cache Composer dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: /tmp/composer-cache
|
||||
key: ${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
|
||||
|
||||
- name: Install dependencies
|
||||
uses: php-actions/composer@v5
|
||||
with:
|
||||
command: install
|
||||
args: --prefer-dist --no-progress --no-suggest --verbose
|
||||
php_version: ${{ matrix.php-versions }}
|
||||
version: 1
|
||||
|
||||
- name: Run lint
|
||||
run: make lint
|
||||
40
.github/workflows/test.yml
vendored
Normal file
40
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ '*' ]
|
||||
pull_request:
|
||||
branches: [ '*' ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
|
||||
- name: Cache Composer dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: /tmp/composer-cache
|
||||
key: ${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
|
||||
|
||||
- name: Install dependencies
|
||||
uses: php-actions/composer@v5
|
||||
with:
|
||||
command: install
|
||||
args: --prefer-dist --no-progress --no-suggest --verbose
|
||||
php_version: ${{ matrix.php-versions }}
|
||||
version: 1
|
||||
|
||||
- name: Run tests
|
||||
run: make test
|
||||
1
.gitignore
vendored
Normal file → Executable file
1
.gitignore
vendored
Normal file → Executable file
@@ -1,2 +1,3 @@
|
||||
/.idea
|
||||
/vendor/
|
||||
/nbproject/
|
||||
|
||||
15
.travis.yml
15
.travis.yml
@@ -1,15 +0,0 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
before_install:
|
||||
- composer self-update
|
||||
|
||||
install:
|
||||
- travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
script:
|
||||
- make lint
|
||||
- make test
|
||||
13
Makefile
13
Makefile
@@ -1,17 +1,14 @@
|
||||
THIS := $(realpath $(lastword $(MAKEFILE_LIST)))
|
||||
HERE := $(shell dirname $(THIS))
|
||||
|
||||
.PHONY: all fix lint test
|
||||
|
||||
all: lint test
|
||||
|
||||
fix:
|
||||
php $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs
|
||||
php vendor/bin/php-cs-fixer fix --config=.php_cs
|
||||
|
||||
lint:
|
||||
php $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs --dry-run
|
||||
php $(HERE)/vendor/bin/phpmd src/ text cleancode,codesize,controversial,design,naming,unusedcode
|
||||
php $(HERE)/vendor/bin/phpmd tests/ text cleancode,codesize,controversial,design,naming,unusedcode
|
||||
php vendor/bin/php-cs-fixer fix --config=.php_cs --dry-run
|
||||
php vendor/bin/phpmd src/ text cleancode,codesize,controversial,design,naming,unusedcode
|
||||
php vendor/bin/phpmd tests/ text cleancode,codesize,controversial,design,naming,unusedcode
|
||||
|
||||
test:
|
||||
php $(HERE)/vendor/bin/phpunit --configuration $(HERE)/phpunit.xml
|
||||
php vendor/bin/phpunit --configuration phpunit.xml
|
||||
|
||||
77
README.md
Normal file → Executable file
77
README.md
Normal file → Executable file
@@ -2,49 +2,48 @@
|
||||
|
||||
[](https://travis-ci.org/cloudflare/cloudflare-php)
|
||||
|
||||
## Installation
|
||||
See: [cloudflare/cloudflare-php](https://github.com/cloudflare/cloudflare-php)
|
||||
|
||||
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 SDK: added by Shellrent
|
||||
|
||||
## Cloudflare API version 4
|
||||
- DNS Record is returned on creation:
|
||||
|
||||
The Cloudflare API can be found [here](https://api.cloudflare.com/).
|
||||
Each API call is provided via a similarly named function within various classes in the **Cloudflare\API\Endpoints** namespace:
|
||||
|
||||
- [x] [DNS Records](https://www.cloudflare.com/dns/)
|
||||
- [x] Zones
|
||||
- [x] User Administration (partial)
|
||||
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
|
||||
- [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/)
|
||||
- [ ] Virtual DNS Management
|
||||
- [x] Custom hostnames
|
||||
- [x] Manage TLS settings
|
||||
- [x] Zone Lockdown and User-Agent Block rules
|
||||
- [ ] Organization Administration
|
||||
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
|
||||
- [ ] [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/)
|
||||
- [x] Crypto
|
||||
- [x] Load Balancers
|
||||
- [x] Firewall Settings
|
||||
|
||||
Note that this repository is currently under development, additional classes and endpoints being actively added.
|
||||
|
||||
## Getting Started
|
||||
`Class: Cloudflare\API\Endpoints\DNS`
|
||||
|
||||
```php
|
||||
$key = new Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey');
|
||||
$adapter = new Cloudflare\API\Adapter\Guzzle($key);
|
||||
$user = new Cloudflare\API\Endpoints\User($adapter);
|
||||
public function addRecord(
|
||||
string $zoneID,
|
||||
string $type,
|
||||
string $name,
|
||||
string $content,
|
||||
int $ttl = 0,
|
||||
bool $proxied = true,
|
||||
string $priority = '',
|
||||
array $data = []
|
||||
): \stdClass {
|
||||
$options = [
|
||||
'type' => $type,
|
||||
'name' => $name,
|
||||
'content' => $content,
|
||||
'proxied' => $proxied
|
||||
];
|
||||
|
||||
echo $user->getUserID();
|
||||
if ($ttl > 0) {
|
||||
$options['ttl'] = $ttl;
|
||||
}
|
||||
|
||||
if (!empty($priority)) {
|
||||
$options['priority'] = (int)$priority;
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
$options['data'] = $data;
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
|
||||
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
We welcome community contribution to this repository. [CONTRIBUTING.md](CONTRIBUTING.md) will help you start contributing.
|
||||
|
||||
## Licensing
|
||||
|
||||
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "cloudflare/sdk",
|
||||
"name": "yuemi/cloudflare-php",
|
||||
"description": "PHP binding for v4 of the Cloudflare Client API.",
|
||||
"type": "library",
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^6.2.2",
|
||||
"php": ">=7.0.0",
|
||||
"psr/http-message": "~1.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"php": ">=7.2.5",
|
||||
"psr/http-message": "^1.0 || ^2.0",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "5.7.5",
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"phpmd/phpmd" : "@stable",
|
||||
"friendsofphp/php-cs-fixer": "^2.6"
|
||||
},
|
||||
|
||||
534
composer.lock
generated
534
composer.lock
generated
File diff suppressed because it is too large
Load Diff
BIN
phpcbf.phar
BIN
phpcbf.phar
Binary file not shown.
BIN
phpcs.phar
BIN
phpcs.phar
Binary file not shown.
@@ -1,14 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 18:26
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Adapter;
|
||||
|
||||
use Cloudflare\API\Auth\Auth;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Guzzle implements Adapter
|
||||
@@ -74,36 +70,52 @@ class Guzzle implements Adapter
|
||||
return $this->request('delete', $uri, $data, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||
*/
|
||||
public function request(string $method, string $uri, array $data = [], array $headers = [])
|
||||
{
|
||||
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
|
||||
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->client->$method($uri, [
|
||||
'headers' => $headers,
|
||||
($method === 'get' ? 'query' : 'json') => $data,
|
||||
]);
|
||||
|
||||
$this->checkError($response);
|
||||
} catch (RequestException $err) {
|
||||
throw ResponseException::fromRequestException($err);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function checkError(ResponseInterface $response)
|
||||
{
|
||||
$json = json_decode($response->getBody());
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new JSONException();
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||
*/
|
||||
public function requestMultiPart(string $method, string $uri, array $data = [], array $headers = []) {
|
||||
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
|
||||
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
|
||||
}
|
||||
|
||||
if (isset($json->errors) && count($json->errors) >= 1) {
|
||||
throw new ResponseException($json->errors[0]->message, $json->errors[0]->code);
|
||||
$multipart = [];
|
||||
foreach( $data as $key => $value ) {
|
||||
$multipart[] = [
|
||||
'name' => $key,
|
||||
'contents' => $value
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($json->success) && !$json->success) {
|
||||
throw new ResponseException('Request was unsuccessful.');
|
||||
}
|
||||
try {
|
||||
$response = $this->client->$method($uri, [
|
||||
'headers' => $headers,
|
||||
'multipart' => $multipart
|
||||
]);
|
||||
} catch (RequestException $err) {
|
||||
throw ResponseException::fromRequestException($err);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,37 @@
|
||||
|
||||
namespace Cloudflare\API\Adapter;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
class ResponseException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Generates a ResponseException from a Guzzle RequestException.
|
||||
*
|
||||
* @param RequestException $err The client request exception (typicall 4xx or 5xx response).
|
||||
* @return ResponseException
|
||||
*/
|
||||
public static function fromRequestException(RequestException $err): self
|
||||
{
|
||||
if (!$err->hasResponse()) {
|
||||
return new ResponseException($err->getMessage(), 0, $err);
|
||||
}
|
||||
|
||||
$response = $err->getResponse();
|
||||
$contentType = $response->getHeaderLine('Content-Type');
|
||||
|
||||
// Attempt to derive detailed error from standard JSON response.
|
||||
if (strpos($contentType, 'application/json') !== false) {
|
||||
$json = json_decode($response->getBody());
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return new ResponseException($err->getMessage(), 0, new JSONException(json_last_error_msg(), 0, $err));
|
||||
}
|
||||
|
||||
if (isset($json->errors) && count($json->errors) >= 1) {
|
||||
return new ResponseException($json->errors[0]->message, $json->errors[0]->code, $err);
|
||||
}
|
||||
}
|
||||
|
||||
return new ResponseException($err->getMessage(), 0, $err);
|
||||
}
|
||||
}
|
||||
|
||||
25
src/Auth/APIToken.php
Normal file
25
src/Auth/APIToken.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* User: czPechy
|
||||
* Date: 30/07/2018
|
||||
* Time: 22:42
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Auth;
|
||||
|
||||
class APIToken implements Auth
|
||||
{
|
||||
private $apiToken;
|
||||
|
||||
public function __construct(string $apiToken)
|
||||
{
|
||||
$this->apiToken = $apiToken;
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [
|
||||
'Authorization' => 'Bearer ' . $this->apiToken
|
||||
];
|
||||
}
|
||||
}
|
||||
58
src/Configurations/Certificate.php
Normal file
58
src/Configurations/Certificate.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
class Certificate implements Configurations
|
||||
{
|
||||
const ORIGIN_RSA = 'origin-rsa';
|
||||
const ORIGIN_ECC = 'origin-ecc';
|
||||
const KEYLESS_CERTIFICATE = 'keyless-certificate';
|
||||
|
||||
private $config = [];
|
||||
|
||||
public function getArray(): array
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of hostnames or wildcard names (e.g., *.example.com) bound to the certificate
|
||||
* Example: $hostnames = ["example.com", "foo.example.com"]
|
||||
* @param array $hostnames
|
||||
*/
|
||||
public function setHostnames(array $hostnames)
|
||||
{
|
||||
$this->config['hostnames'] = $hostnames;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of days for which the certificate should be valid
|
||||
* Default value: 5475
|
||||
* Valid values: 7, 30, 90, 365, 730, 1095, 5475
|
||||
* @param int $validity
|
||||
*/
|
||||
public function setRequestedValidity(int $validity)
|
||||
{
|
||||
$this->config['requested_validity'] = $validity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signature type desired on certificate ("origin-rsa" (rsa), "origin-ecc" (ecdsa), or "keyless-certificate" (for Keyless SSL servers)
|
||||
* Valid values: origin-rsa, origin-ecc, keyless-certificate
|
||||
* @param string $type
|
||||
*/
|
||||
public function setRequestType(string $type)
|
||||
{
|
||||
$this->config['request_type'] = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Certificate Signing Request (CSR). Must be newline-encoded.
|
||||
*
|
||||
* @param string $csr
|
||||
*/
|
||||
public function setCsr(string $csr)
|
||||
{
|
||||
$this->config['csr'] = $csr;
|
||||
}
|
||||
}
|
||||
69
src/Configurations/DNSAnalytics.php
Normal file
69
src/Configurations/DNSAnalytics.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
class DNSAnalytics implements Configurations
|
||||
{
|
||||
protected $configs = [];
|
||||
|
||||
public function getArray(): array
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
|
||||
public function setDimensions(array $dimensions)
|
||||
{
|
||||
if (count($dimensions) !== 0) {
|
||||
$this->configs['dimensions'] = implode(',', $dimensions);
|
||||
}
|
||||
}
|
||||
|
||||
public function setMetrics(array $metrics)
|
||||
{
|
||||
if (count($metrics) !== 0) {
|
||||
$this->configs['metrics'] = implode(',', $metrics);
|
||||
}
|
||||
}
|
||||
|
||||
public function setSince(string $since)
|
||||
{
|
||||
if ($since) {
|
||||
$this->configs['since'] = $since;
|
||||
}
|
||||
}
|
||||
|
||||
public function setUntil(string $until)
|
||||
{
|
||||
if ($until) {
|
||||
$this->configs['until'] = $until;
|
||||
}
|
||||
}
|
||||
|
||||
public function setSorting(array $sorting)
|
||||
{
|
||||
if (count($sorting) !== 0) {
|
||||
$this->configs['sort'] = implode(',', $sorting);
|
||||
}
|
||||
}
|
||||
|
||||
public function setFilters(string $filters)
|
||||
{
|
||||
if ($filters) {
|
||||
$this->configs['filters'] = $filters;
|
||||
}
|
||||
}
|
||||
|
||||
public function setLimit(int $limit)
|
||||
{
|
||||
if ($limit) {
|
||||
$this->configs['limit'] = $limit;
|
||||
}
|
||||
}
|
||||
|
||||
public function setTimeDelta(string $timeDelta)
|
||||
{
|
||||
if ($timeDelta) {
|
||||
$this->configs['time_delta'] = $timeDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
src/Configurations/FirewallRuleOptions.php
Normal file
46
src/Configurations/FirewallRuleOptions.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
class FirewallRuleOptions implements Configurations
|
||||
{
|
||||
protected $configs = [
|
||||
'paused' => false,
|
||||
'action' => 'block'
|
||||
];
|
||||
|
||||
public function getArray(): array
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
|
||||
public function setPaused(bool $paused)
|
||||
{
|
||||
$this->configs['paused'] = $paused;
|
||||
}
|
||||
|
||||
public function setActionBlock()
|
||||
{
|
||||
$this->configs['action'] = 'block';
|
||||
}
|
||||
|
||||
public function setActionAllow()
|
||||
{
|
||||
$this->configs['action'] = 'allow';
|
||||
}
|
||||
|
||||
public function setActionChallenge()
|
||||
{
|
||||
$this->configs['action'] = 'challenge';
|
||||
}
|
||||
|
||||
public function setActionJsChallenge()
|
||||
{
|
||||
$this->configs['action'] = 'js_challenge';
|
||||
}
|
||||
|
||||
public function setActionLog()
|
||||
{
|
||||
$this->configs['action'] = 'log';
|
||||
}
|
||||
}
|
||||
15
src/Configurations/PageRulesActions.php
Normal file → Executable file
15
src/Configurations/PageRulesActions.php
Normal file → Executable file
@@ -33,6 +33,13 @@ class PageRulesActions implements Configurations
|
||||
]);
|
||||
}
|
||||
|
||||
public function setOriginCacheControl(bool $active)
|
||||
{
|
||||
$this->addConfigurationOption('explicit_cache_control', [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
]);
|
||||
}
|
||||
|
||||
public function setBrowserIntegrityCheck(bool $active)
|
||||
{
|
||||
$this->addConfigurationOption('browser_check', [
|
||||
@@ -110,7 +117,7 @@ class PageRulesActions implements Configurations
|
||||
|
||||
public function setEdgeCacheTTL(int $value)
|
||||
{
|
||||
if ($value > 2419200) {
|
||||
if ($value > 2678400) {
|
||||
throw new ConfigurationsException('Edge Cache TTL too high.');
|
||||
}
|
||||
|
||||
@@ -140,10 +147,10 @@ class PageRulesActions implements Configurations
|
||||
]);
|
||||
}
|
||||
|
||||
public function setHostHeaderOverride(bool $active)
|
||||
public function setHostHeaderOverride(string $value)
|
||||
{
|
||||
$this->addConfigurationOption('host_header_override', [
|
||||
'value' => $this->getBoolAsOnOrOff($active)
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -198,7 +205,7 @@ class PageRulesActions implements Configurations
|
||||
]);
|
||||
}
|
||||
|
||||
public function setResolveOverride(bool $value)
|
||||
public function setResolveOverride(string $value)
|
||||
{
|
||||
$this->addConfigurationOption('resolve_override', [
|
||||
'value' => $value
|
||||
|
||||
50
src/Endpoints/AccountMembers.php
Normal file
50
src/Endpoints/AccountMembers.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class AccountMembers implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
/**
|
||||
* @var Adapter
|
||||
*/
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function addAccountMember(string $accountId, string $email, array $roles): \stdClass
|
||||
{
|
||||
$options = [
|
||||
'email' => $email,
|
||||
'roles' => $roles,
|
||||
];
|
||||
|
||||
$account = $this->adapter->post('accounts/' . $accountId . '/members', $options);
|
||||
$this->body = json_decode($account->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function listAccountMembers(string $accountId, int $page = 1, int $perPage = 20): \stdClass
|
||||
{
|
||||
$query = [
|
||||
'page' => $page,
|
||||
'per_page' => $perPage,
|
||||
];
|
||||
|
||||
$zone = $this->adapter->get('accounts/' . $accountId . '/members', $query);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
|
||||
return (object)[
|
||||
'result' => $this->body->result,
|
||||
'result_info' => $this->body->result_info,
|
||||
];
|
||||
}
|
||||
}
|
||||
33
src/Endpoints/AccountRoles.php
Normal file
33
src/Endpoints/AccountRoles.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
use stdClass;
|
||||
|
||||
class AccountRoles implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
/**
|
||||
* @var Adapter
|
||||
*/
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function listAccountRoles(string $accountId): stdClass
|
||||
{
|
||||
$roles = $this->adapter->get('accounts/' . $accountId . '/roles');
|
||||
$this->body = json_decode($roles->getBody());
|
||||
|
||||
return (object)[
|
||||
'result' => $this->body->result,
|
||||
'result_info' => $this->body->result_info,
|
||||
];
|
||||
}
|
||||
}
|
||||
88
src/Endpoints/Accounts.php
Normal file
88
src/Endpoints/Accounts.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* User: kanasite
|
||||
* Date: 01/28/2019
|
||||
* Time: 10:00
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class Accounts implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function addAccount(string $name, string $type = 'standard'): \stdClass
|
||||
{
|
||||
$options = [
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
$account = $this->adapter->post('accounts', $options);
|
||||
$this->body = json_decode($account->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function listAccounts(
|
||||
int $page = 1,
|
||||
int $perPage = 20,
|
||||
string $direction = ''
|
||||
): \stdClass {
|
||||
$query = [
|
||||
'page' => $page,
|
||||
'per_page' => $perPage
|
||||
];
|
||||
|
||||
if (!empty($direction)) {
|
||||
$query['direction'] = $direction;
|
||||
}
|
||||
|
||||
$user = $this->adapter->get('accounts', $query);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||
}
|
||||
|
||||
public function getDomains(string $accountID): array
|
||||
{
|
||||
$response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains');
|
||||
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getDomainDetails(string $accountID, string $domainName): \stdClass
|
||||
{
|
||||
$response = $this->adapter->get('accounts/' . $accountID . '/registrar/domains/' . $domainName);
|
||||
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function lockDomain(string $accountID, string $domainName): \stdClass
|
||||
{
|
||||
$response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => true]);
|
||||
$this->body = json_decode($response->getBody());
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function unlockDomain(string $accountID, string $domainName): \stdClass
|
||||
{
|
||||
$response = $this->adapter->put('accounts/' . $accountID . '/registrar/domains/' . $domainName, ['locked' => false]);
|
||||
$this->body = json_decode($response->getBody());
|
||||
return $this->body;
|
||||
}
|
||||
}
|
||||
86
src/Endpoints/Certificates.php
Normal file
86
src/Endpoints/Certificates.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Configurations\Certificate as CertificateConfig;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class Certificates implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* List all existing Origin CA certificates for a given zone
|
||||
*
|
||||
* @param string $zoneID
|
||||
* @return array
|
||||
*/
|
||||
public function listCertificates(string $zoneID): \stdClass
|
||||
{
|
||||
$certificates = $this->adapter->get('certificates', ['zone_id' => $zoneID]);
|
||||
$this->body = json_decode($certificates->getBody());
|
||||
|
||||
return (object)['result' => $this->body->result];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an existing Origin CA certificate by its serial number
|
||||
*
|
||||
* @param string $certificateID
|
||||
* @param string $zoneID
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCertificate(string $certificateID, string $zoneID)
|
||||
{
|
||||
$certificates = $this->adapter->get('certificates/'.$certificateID, ['zone_id' => $zoneID]);
|
||||
$this->body = json_decode($certificates->getBody());
|
||||
|
||||
return (object)['result' => $this->body->result];
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke an existing Origin CA certificate by its serial number
|
||||
*
|
||||
* @param string $certificateID
|
||||
* @param string $zoneID
|
||||
* @return bool
|
||||
*/
|
||||
public function revokeCertificate(string $certificateID, string $zoneID): bool
|
||||
{
|
||||
$certificates = $this->adapter->delete('certificates/'.$certificateID, ['zone_id' => $zoneID]);
|
||||
$this->body = json_decode($certificates->getBody());
|
||||
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an Origin CA certificate
|
||||
*
|
||||
* @param CertificateConfig $config
|
||||
* @return bool
|
||||
*/
|
||||
public function createCertificate(CertificateConfig $config): bool
|
||||
{
|
||||
$certificate = $this->adapter->post('certificates', $config->getArray());
|
||||
|
||||
$this->body = json_decode($certificate->getBody());
|
||||
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,50 @@ class CustomHostnames implements API
|
||||
* @param string $hostname
|
||||
* @param string $sslMethod
|
||||
* @param string $sslType
|
||||
* @param array $sslSettings
|
||||
* @param string $customOriginServer
|
||||
* @param bool $wildcard
|
||||
* @param string $bundleMethod
|
||||
* @param array $customSsl
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv'): \stdClass
|
||||
{
|
||||
public function addHostname(
|
||||
string $zoneID,
|
||||
string $hostname,
|
||||
string $sslMethod = 'http',
|
||||
string $sslType = 'dv',
|
||||
array $sslSettings = [],
|
||||
string $customOriginServer = '',
|
||||
bool $wildcard = false,
|
||||
string $bundleMethod = '',
|
||||
array $customSsl = []
|
||||
): \stdClass {
|
||||
$options = [
|
||||
'hostname' => $hostname,
|
||||
'ssl' => [
|
||||
'method' => $sslMethod,
|
||||
'type' => $sslType
|
||||
]
|
||||
'type' => $sslType,
|
||||
'settings' => $sslSettings,
|
||||
'wildcard' => $wildcard,
|
||||
],
|
||||
];
|
||||
|
||||
if (!empty($customOriginServer)) {
|
||||
$options['custom_origin_server'] = $customOriginServer;
|
||||
}
|
||||
|
||||
if (!empty($bundleMethod)) {
|
||||
$options['ssl']['bundle_method'] = $bundleMethod;
|
||||
}
|
||||
|
||||
if (!empty($customSsl['key'])) {
|
||||
$options['ssl']['custom_key'] = $customSsl['key'];
|
||||
}
|
||||
|
||||
if (!empty($customSsl['certificate'])) {
|
||||
$options['ssl']['custom_certificate'] = $customSsl['certificate'];
|
||||
}
|
||||
|
||||
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
return $this->body->result;
|
||||
@@ -111,16 +143,33 @@ class CustomHostnames implements API
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
*
|
||||
* @param string $zoneID
|
||||
* @param string $hostnameID
|
||||
* @param string $sslMethod
|
||||
* @param string $sslType
|
||||
* @param array $sslSettings
|
||||
* @param string $customOriginServer
|
||||
* @param bool|null $wildcard
|
||||
* @param string $bundleMethod
|
||||
* @param array $customSsl
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = ''): \stdClass
|
||||
{
|
||||
public function updateHostname(
|
||||
string $zoneID,
|
||||
string $hostnameID,
|
||||
string $sslMethod = '',
|
||||
string $sslType = '',
|
||||
array $sslSettings = [],
|
||||
string $customOriginServer = '',
|
||||
bool $wildcard = null,
|
||||
string $bundleMethod = '',
|
||||
array $customSsl = []
|
||||
): \stdClass {
|
||||
$query = [];
|
||||
$options = [];
|
||||
|
||||
if (!empty($sslMethod)) {
|
||||
$query['method'] = $sslMethod;
|
||||
@@ -130,9 +179,35 @@ class CustomHostnames implements API
|
||||
$query['type'] = $sslType;
|
||||
}
|
||||
|
||||
if (!empty($sslSettings)) {
|
||||
$query['settings'] = $sslSettings;
|
||||
}
|
||||
|
||||
if (!is_null($wildcard)) {
|
||||
$query['wildcard'] = $wildcard;
|
||||
}
|
||||
|
||||
if (!empty($bundleMethod)) {
|
||||
$query['bundle_method'] = $bundleMethod;
|
||||
}
|
||||
|
||||
if (!empty($customSsl['key'])) {
|
||||
$query['custom_key'] = $customSsl['key'];
|
||||
}
|
||||
|
||||
if (!empty($customSsl['certificate'])) {
|
||||
$query['custom_certificate'] = $customSsl['certificate'];
|
||||
}
|
||||
|
||||
if (!empty($query)) {
|
||||
$options = [
|
||||
'ssl' => $query
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($customOriginServer)) {
|
||||
$options['custom_origin_server'] = $customOriginServer;
|
||||
}
|
||||
|
||||
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
|
||||
$this->body = json_decode($zone->getBody());
|
||||
@@ -150,4 +225,16 @@ class CustomHostnames implements API
|
||||
$this->body = json_decode($zone->getBody());
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $zoneID
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function getFallbackOrigin(string $zoneID): \stdClass
|
||||
{
|
||||
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/fallback_origin');
|
||||
$this->body = json_decode($zone->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class DNS implements API
|
||||
* @param bool $proxied
|
||||
* @param string $priority
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function addRecord(
|
||||
string $zoneID,
|
||||
@@ -44,7 +44,7 @@ class DNS implements API
|
||||
bool $proxied = true,
|
||||
string $priority = '',
|
||||
array $data = []
|
||||
): bool {
|
||||
): \stdClass {
|
||||
$options = [
|
||||
'type' => $type,
|
||||
'name' => $name,
|
||||
@@ -56,7 +56,7 @@ class DNS implements API
|
||||
$options['ttl'] = $ttl;
|
||||
}
|
||||
|
||||
if (!empty($priority)) {
|
||||
if (is_numeric($priority)) {
|
||||
$options['priority'] = (int)$priority;
|
||||
}
|
||||
|
||||
@@ -68,11 +68,22 @@ class DNS implements API
|
||||
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
$result = $this->body->result;
|
||||
|
||||
if( !( $result instanceof \stdClass ) ) {
|
||||
$errorMessage = '';
|
||||
|
||||
if( is_array( $result ) ) {
|
||||
$errorMessage.= implode( $result );
|
||||
|
||||
} elseif( is_string( $result ) ) {
|
||||
$errorMessage.= $result;
|
||||
}
|
||||
|
||||
return false;
|
||||
throw new EndpointException( sprintf( 'Unexpected add record result. %s', $errorMessage ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function listRecords(
|
||||
@@ -128,8 +139,8 @@ class DNS implements API
|
||||
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;
|
||||
if (isset($records->result[0]->id)) {
|
||||
return $records->result[0]->id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
144
src/Endpoints/DNSAnalytics.php
Normal file
144
src/Endpoints/DNSAnalytics.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Visual Studio Code.
|
||||
* User: elliot.alderson
|
||||
* Date: 2020-02-06
|
||||
* Time: 03:40 AM
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
use Cloudflare\API\Configurations\DNSAnalytics as Configs;
|
||||
|
||||
class DNSAnalytics implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of summarised aggregate metrics over a given time period.
|
||||
*
|
||||
* @param string $zoneID ID of zone to get report for
|
||||
* @param string $dimensions Comma separated names of dimensions
|
||||
* @param string $metrics Comma separated names of dimension to get metrics for
|
||||
* @param string $sort Comma separated names of dimension to sort by prefixed by order - (descending) or + (ascending)
|
||||
* @param string $filters Segmentation filter in 'attribute operator value' format
|
||||
* @param string $since Start date and time of requesting data period in the ISO8601 format
|
||||
* @param string $until End date and time of requesting data period in the ISO8601 format
|
||||
* @param string $limit Limit number of returned metrics
|
||||
* @return array
|
||||
*/
|
||||
public function getReportTable(
|
||||
string $zoneID,
|
||||
array $dimensions = [],
|
||||
array $metrics = [],
|
||||
array $sort = [],
|
||||
string $filters = '',
|
||||
string $since = '',
|
||||
string $until = '',
|
||||
int $limit = 100
|
||||
): \stdClass {
|
||||
if (count($dimensions) === 0) {
|
||||
throw new EndpointException(
|
||||
'At least one dimension is required for getting a report.'
|
||||
);
|
||||
}
|
||||
|
||||
if (count($metrics) === 0) {
|
||||
throw new EndpointException(
|
||||
'At least one metric is required for getting a report.'
|
||||
);
|
||||
}
|
||||
|
||||
if (!$since) {
|
||||
throw new EndpointException(
|
||||
'Start date is required for getting a report.'
|
||||
);
|
||||
}
|
||||
|
||||
if (!$until) {
|
||||
throw new EndpointException(
|
||||
'End date is required for getting a report.'
|
||||
);
|
||||
}
|
||||
|
||||
$options = [
|
||||
'dimensions' => implode(',', $dimensions),
|
||||
'metrics' => implode(',', $metrics),
|
||||
'since' => $since,
|
||||
'until' => $until
|
||||
];
|
||||
|
||||
if (count($sort) !== 0) {
|
||||
$options['sort'] = implode(',', $sort);
|
||||
}
|
||||
|
||||
if ($filters) {
|
||||
$options['filters'] = $filters;
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$options['limit'] = $limit;
|
||||
}
|
||||
|
||||
$endpoint = 'zones/' . $zoneID . '/dns_analytics/report';
|
||||
|
||||
$report = $this->adapter->get($endpoint, $options);
|
||||
|
||||
$this->body = json_decode($report->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of aggregate metrics grouped by time interval.
|
||||
*
|
||||
* @param string $zoneID ID of zone to get report for
|
||||
* @param string $dimensions Comma separated names of dimensions
|
||||
* @param string $metrics Comma separated names of dimension to get metrics for
|
||||
* @param string $sort Comma separated names of dimension to sort by prefixed by order - (descending) or + (ascending)
|
||||
* @param string $filters Segmentation filter in 'attribute operator value' format
|
||||
* @param string $since Start date and time of requesting data period in the ISO8601 format
|
||||
* @param string $until End date and time of requesting data period in the ISO8601 format
|
||||
* @param string $limit Limit number of returned metrics
|
||||
* @param string $timeDelta Unit of time to group data by
|
||||
* @return array
|
||||
*/
|
||||
public function getReportByTime(
|
||||
string $zoneID,
|
||||
array $dimensions = [],
|
||||
array $metrics = [],
|
||||
array $sort = [],
|
||||
string $filters = '',
|
||||
string $since = '',
|
||||
string $until = '',
|
||||
int $limit = 100,
|
||||
string $timeDelta = ''
|
||||
): \stdClass {
|
||||
$options = new Configs();
|
||||
$options->setDimensions($dimensions);
|
||||
$options->setMetrics($metrics);
|
||||
$options->setSince($since);
|
||||
$options->setUntil($until);
|
||||
$options->setSorting($sort);
|
||||
$options->setFilters($filters);
|
||||
$options->setLimit($limit);
|
||||
$options->setTimeDelta($timeDelta);
|
||||
|
||||
$endpoint = 'zones/' . $zoneID . '/dns_analytics/report/bytime';
|
||||
|
||||
$report = $this->adapter->get($endpoint, $options->getArray());
|
||||
|
||||
$this->body = json_decode($report->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
}
|
||||
120
src/Endpoints/Firewall.php
Normal file
120
src/Endpoints/Firewall.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Configurations\FirewallRuleOptions;
|
||||
|
||||
class Firewall implements API
|
||||
{
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function createFirewallRules(
|
||||
string $zoneID,
|
||||
array $rules
|
||||
): bool {
|
||||
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/rules', $rules);
|
||||
$body = json_decode($query->getBody());
|
||||
|
||||
foreach ($body->result as $result) {
|
||||
if (!isset($result->id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function createFirewallRule(
|
||||
string $zoneID,
|
||||
string $expression,
|
||||
FirewallRuleOptions $options,
|
||||
string $description = null,
|
||||
int $priority = null
|
||||
): bool {
|
||||
$rule = array_merge([
|
||||
'filter' => [
|
||||
'expression' => $expression,
|
||||
'paused' => false
|
||||
]
|
||||
], $options->getArray());
|
||||
|
||||
if ($description !== null) {
|
||||
$rule['description'] = $description;
|
||||
}
|
||||
|
||||
if ($priority !== null) {
|
||||
$rule['priority'] = $priority;
|
||||
}
|
||||
|
||||
return $this->createFirewallRules($zoneID, [$rule]);
|
||||
}
|
||||
|
||||
public function listFirewallRules(
|
||||
string $zoneID,
|
||||
int $page = 1,
|
||||
int $perPage = 50
|
||||
): \stdClass {
|
||||
$query = [
|
||||
'page' => $page,
|
||||
'per_page' => $perPage,
|
||||
];
|
||||
|
||||
$rules = $this->adapter->get('zones/' . $zoneID . '/firewall/rules', $query);
|
||||
$body = json_decode($rules->getBody());
|
||||
|
||||
return (object)['result' => $body->result, 'result_info' => $body->result_info];
|
||||
}
|
||||
|
||||
public function deleteFirewallRule(
|
||||
string $zoneID,
|
||||
string $ruleID
|
||||
): bool {
|
||||
$rule = $this->adapter->delete('zones/' . $zoneID . '/firewall/rules/' . $ruleID);
|
||||
|
||||
$body = json_decode($rule->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateFirewallRule(
|
||||
string $zoneID,
|
||||
string $ruleID,
|
||||
string $filterID,
|
||||
string $expression,
|
||||
FirewallRuleOptions $options,
|
||||
string $description = null,
|
||||
int $priority = null
|
||||
): \stdClass {
|
||||
$rule = array_merge([
|
||||
'id' => $ruleID,
|
||||
'filter' => [
|
||||
'id' => $filterID,
|
||||
'expression' => $expression,
|
||||
'paused' => false
|
||||
]
|
||||
], $options->getArray());
|
||||
|
||||
if ($description !== null) {
|
||||
$rule['description'] = $description;
|
||||
}
|
||||
|
||||
if ($priority !== null) {
|
||||
$rule['priority'] = $priority;
|
||||
}
|
||||
|
||||
$rule = $this->adapter->put('zones/' . $zoneID . '/firewall/rules/' . $ruleID, $rule);
|
||||
$body = json_decode($rule->getBody());
|
||||
|
||||
return $body->result;
|
||||
}
|
||||
}
|
||||
@@ -73,19 +73,19 @@ class PageRules implements API
|
||||
string $direction = null,
|
||||
string $match = null
|
||||
): array {
|
||||
if ($status === null && !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.');
|
||||
}
|
||||
|
||||
if ($order === null && !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.');
|
||||
}
|
||||
|
||||
if ($direction === null && !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.');
|
||||
}
|
||||
|
||||
if ($match === null && !in_array($match, ['all', 'any'])) {
|
||||
if ($match != null && !in_array($match, ['all', 'any'])) {
|
||||
throw new EndpointException('Match can only be any or all.');
|
||||
}
|
||||
|
||||
@@ -109,6 +109,37 @@ class PageRules implements API
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function editPageRule(
|
||||
string $zoneID,
|
||||
string $ruleID,
|
||||
PageRulesTargets $target,
|
||||
PageRulesActions $actions,
|
||||
bool $active = null,
|
||||
int $priority = null
|
||||
): bool {
|
||||
$options = [];
|
||||
$options['targets'] = $target->getArray();
|
||||
$options['actions'] = $actions->getArray();
|
||||
|
||||
if ($active !== null) {
|
||||
$options['status'] = $active == true ? 'active' : 'disabled';
|
||||
}
|
||||
|
||||
if ($priority !== null) {
|
||||
$options['priority'] = $priority;
|
||||
}
|
||||
|
||||
$query = $this->adapter->put('zones/' . $zoneID . '/pagerules/' . $ruleID, $options);
|
||||
|
||||
$this->body = json_decode($query->getBody());
|
||||
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updatePageRule(
|
||||
string $zoneID,
|
||||
string $ruleID,
|
||||
|
||||
117
src/Endpoints/RulesLists.php
Executable file
117
src/Endpoints/RulesLists.php
Executable file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class RulesLists implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function getLists(string $accountId)
|
||||
{
|
||||
$response = $this->adapter->get('accounts/' . $accountId . '/rules/lists');
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getListDetails(string $accountId, string $listId)
|
||||
{
|
||||
$response = $this->adapter->get('accounts/' . $accountId . '/rules/lists/' . $listId);
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getListItems(string $accountId, string $listId, string $search = '', int $itemsPerPage = 20, string $cursor = '')
|
||||
{
|
||||
|
||||
$options = [
|
||||
'per_page' => $itemsPerPage,
|
||||
];
|
||||
|
||||
if ($search) {
|
||||
$options['search'] = $search;
|
||||
}
|
||||
|
||||
if ($cursor) {
|
||||
$options['cursor'] = $cursor;
|
||||
}
|
||||
|
||||
$response = $this->adapter->get('accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options);
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info ?? null];
|
||||
}
|
||||
|
||||
public function createList(string $accountId, string $kind, string $name, string $description = '')
|
||||
{
|
||||
$options = [
|
||||
'kind' => $kind,
|
||||
'name' => $name,
|
||||
];
|
||||
|
||||
if ($description) {
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$response = $this->adapter->post('accounts/' . $accountId . '/rules/lists', $options);
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function deleteList(string $accountId, string $listId)
|
||||
{
|
||||
|
||||
$response = $this->adapter->delete('accounts/' . $accountId . '/rules/lists/' . $listId);
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function createListItem(string $accountId, string $listId, array $ip)
|
||||
{
|
||||
$options = [];
|
||||
foreach ($ip as $ipAddress) {
|
||||
$options[] = ['ip' => $ipAddress];
|
||||
}
|
||||
|
||||
$response = $this->adapter->post('accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options);
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function deleteListItem(string $accountId, string $listId, array $itemIds)
|
||||
{
|
||||
|
||||
$options = ['items' => []];
|
||||
foreach ($itemIds as $itemId) {
|
||||
$options['items'][] = ['id' => $itemId];
|
||||
}
|
||||
|
||||
$response = $this->adapter->delete('accounts/' . $accountId . '/rules/lists/' . $listId . '/items', $options);
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
public function getOperationStatus(string $accountId, string $operationId)
|
||||
{
|
||||
$response = $this->adapter->get('accounts/' . $accountId . '/rules/lists/bulk_operations/' . $operationId);
|
||||
$this->body = json_decode($response->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,16 +32,23 @@ class SSL implements API
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||
*
|
||||
* Get SSL Verification Info for a Zone
|
||||
*
|
||||
* @param string $zoneID The ID of the zone
|
||||
* @param bool $retry Immediately retry SSL Verification
|
||||
* @return array|false
|
||||
*/
|
||||
public function getSSLVerificationStatus(string $zoneID)
|
||||
public function getSSLVerificationStatus(string $zoneID, bool $retry = false)
|
||||
{
|
||||
$return = $this->adapter->get(
|
||||
'zones/' . $zoneID . '/ssl/verification'
|
||||
'zones/' . $zoneID . '/ssl/verification',
|
||||
[
|
||||
'retry' => $retry
|
||||
]
|
||||
);
|
||||
|
||||
$body = json_decode($return->getBody());
|
||||
if (isset($body->result)) {
|
||||
return $body;
|
||||
@@ -150,4 +157,27 @@ class SSL implements API
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the SSL certificate pack validation method
|
||||
*
|
||||
* @param string $zoneID The ID of the zone
|
||||
* @param string $certPackUUID The certificate pack UUID
|
||||
* @param string $validationMethod The verification method
|
||||
* @return bool
|
||||
*/
|
||||
public function updateSSLCertificatePackValidationMethod(string $zoneID, string $certPackUUID, string $validationMethod)
|
||||
{
|
||||
$return = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/ssl/verification/' . $certPackUUID,
|
||||
[
|
||||
'validation_method' => $validationMethod,
|
||||
]
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
if (isset($body->success) && $body->success == true) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
|
||||
class ZoneSettings implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
@@ -75,6 +78,20 @@ class ZoneSettings implements API
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getServerSideExcludeSetting($zoneID)
|
||||
{
|
||||
$return = $this->adapter->get(
|
||||
'zones/' . $zoneID . '/settings/server_side_exclude'
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
return $body->result->value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getHotlinkProtectionSetting($zoneID)
|
||||
{
|
||||
$return = $this->adapter->get(
|
||||
@@ -89,6 +106,37 @@ class ZoneSettings implements API
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getBrowserCacheTtlSetting($zoneID)
|
||||
{
|
||||
$return = $this->adapter->get(
|
||||
'zones/' . $zoneID . '/settings/browser_cache_ttl'
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
return $body->result->value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateBrowserCacheTtlSetting($zoneID, $value)
|
||||
{
|
||||
$return = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/settings/browser_cache_ttl',
|
||||
[
|
||||
'value' => $value
|
||||
]
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateMinifySetting($zoneID, $html, $css, $javascript)
|
||||
{
|
||||
$return = $this->adapter->patch(
|
||||
@@ -177,4 +225,21 @@ class ZoneSettings implements API
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateServerSideExcludeSetting($zoneID, $value)
|
||||
{
|
||||
$return = $this->adapter->patch(
|
||||
'zones/' . $zoneID . '/settings/server_side_exclude',
|
||||
[
|
||||
'value' => $value
|
||||
]
|
||||
);
|
||||
$body = json_decode($return->getBody());
|
||||
|
||||
if ($body->success) {
|
||||
return $body->result->value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
51
src/Endpoints/ZoneSubscriptions.php
Normal file
51
src/Endpoints/ZoneSubscriptions.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||
use stdClass;
|
||||
|
||||
class ZoneSubscriptions implements API
|
||||
{
|
||||
use BodyAccessorTrait;
|
||||
|
||||
/**
|
||||
* @var Adapter
|
||||
*/
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function listZoneSubscriptions(string $zoneId): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('zones/' . $zoneId . '/subscriptions');
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
return (object)[
|
||||
'result' => $this->body->result,
|
||||
];
|
||||
}
|
||||
|
||||
public function addZoneSubscription(string $zoneId, string $ratePlanId = ''): stdClass
|
||||
{
|
||||
$options = [];
|
||||
|
||||
if (empty($ratePlanId) === false) {
|
||||
$options['rate_plan'] = [
|
||||
'id' => $ratePlanId,
|
||||
];
|
||||
}
|
||||
|
||||
$existingSubscription = $this->listZoneSubscriptions($zoneId);
|
||||
$method = empty($existingSubscription->result) ? 'post' : 'put';
|
||||
|
||||
$subscription = $this->adapter->{$method}('zones/' . $zoneId . '/subscription', $options);
|
||||
$this->body = json_decode($subscription->getBody());
|
||||
|
||||
return $this->body->result;
|
||||
}
|
||||
}
|
||||
@@ -27,18 +27,20 @@ class Zones implements API
|
||||
*
|
||||
* @param string $name
|
||||
* @param bool $jumpStart
|
||||
* @param string $organizationID
|
||||
* @param string $accountId
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
|
||||
public function addZone(string $name, bool $jumpStart = false, string $accountId = ''): \stdClass
|
||||
{
|
||||
$options = [
|
||||
'name' => $name,
|
||||
'jump_start' => $jumpStart
|
||||
];
|
||||
|
||||
if (!empty($organizationID)) {
|
||||
$options['organization'] = ['id' => $organizationID];
|
||||
if (!empty($accountId)) {
|
||||
$options['account'] = [
|
||||
'id' => $accountId,
|
||||
];
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones', $options);
|
||||
@@ -58,6 +60,30 @@ class Zones implements API
|
||||
return false;
|
||||
}
|
||||
|
||||
public function pause(string $zoneID): bool
|
||||
{
|
||||
$user = $this->adapter->patch('zones/' . $zoneID, ['paused' => true]);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function unpause(string $zoneID): bool
|
||||
{
|
||||
$user = $this->adapter->patch('zones/' . $zoneID, ['paused' => false]);
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getZoneById(
|
||||
string $zoneId
|
||||
): \stdClass {
|
||||
@@ -193,7 +219,7 @@ class Zones implements API
|
||||
*/
|
||||
public function cachePurgeEverything(string $zoneID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', ['purge_everything' => true]);
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/purge_cache', ['purge_everything' => true]);
|
||||
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
@@ -223,7 +249,7 @@ class Zones implements API
|
||||
$options['hosts'] = $hosts;
|
||||
}
|
||||
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', $options);
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/purge_cache', $options);
|
||||
|
||||
$this->body = json_decode($user->getBody());
|
||||
|
||||
@@ -233,4 +259,18 @@ class Zones implements API
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Zone
|
||||
*/
|
||||
public function deleteZone(string $identifier): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $identifier);
|
||||
$this->body = json_decode($user->getBody());
|
||||
if (isset($this->body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 23:35
|
||||
*/
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Cloudflare\API\Adapter\ResponseException;
|
||||
|
||||
class GuzzleTest extends TestCase
|
||||
{
|
||||
@@ -89,48 +83,15 @@ class GuzzleTest extends TestCase
|
||||
$this->assertEquals('Testing a DELETE request.', $body->json->{'X-Delete-Test'});
|
||||
}
|
||||
|
||||
public function testErrors()
|
||||
{
|
||||
$class = new ReflectionClass(\Cloudflare\API\Adapter\Guzzle::class);
|
||||
$method = $class->getMethod('checkError');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$body =
|
||||
'{
|
||||
"result": null,
|
||||
"success": false,
|
||||
"errors": [{"code":1003,"message":"Invalid or missing zone id."}],
|
||||
"messages": []
|
||||
}'
|
||||
;
|
||||
$response = new Response(200, [], $body);
|
||||
|
||||
$this->expectException(\Cloudflare\API\Adapter\ResponseException::class);
|
||||
$method->invokeArgs($this->client, [$response]);
|
||||
|
||||
$body =
|
||||
'{
|
||||
"result": null,
|
||||
"success": false,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}'
|
||||
;
|
||||
$response = new Response(200, [], $body);
|
||||
|
||||
$this->expectException(\Cloudflare\API\Adapter\ResponseException::class);
|
||||
$method->invokeArgs($this->client, [$response]);
|
||||
|
||||
$body = 'this isnt json.';
|
||||
$response = new Response(200, [], $body);
|
||||
|
||||
$this->expectException(\Cloudflare\API\Adapter\JSONException::class);
|
||||
$method->invokeArgs($this->client, [$response]);
|
||||
}
|
||||
|
||||
public function testNotFound()
|
||||
{
|
||||
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
|
||||
$this->expectException(ResponseException::class);
|
||||
$this->client->get('https://httpbin.org/status/404');
|
||||
}
|
||||
|
||||
public function testServerError()
|
||||
{
|
||||
$this->expectException(ResponseException::class);
|
||||
$this->client->get('https://httpbin.org/status/500');
|
||||
}
|
||||
}
|
||||
|
||||
81
tests/Adapter/ResponseExceptionTest.php
Normal file
81
tests/Adapter/ResponseExceptionTest.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
use Cloudflare\API\Adapter\ResponseException;
|
||||
use Cloudflare\API\Adapter\JSONException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||
*/
|
||||
class ResponseExceptionTest extends TestCase
|
||||
{
|
||||
public function testFromRequestExceptionNoResponse()
|
||||
{
|
||||
$reqErr = new RequestException('foo', new Request('GET', '/test'));
|
||||
$respErr = ResponseException::fromRequestException($reqErr);
|
||||
|
||||
$this->assertInstanceOf(ResponseException::class, $respErr);
|
||||
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
|
||||
$this->assertEquals(0, $respErr->getCode());
|
||||
$this->assertEquals($reqErr, $respErr->getPrevious());
|
||||
}
|
||||
|
||||
public function testFromRequestExceptionEmptyContentType()
|
||||
{
|
||||
$resp = new Response(404);
|
||||
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
|
||||
$respErr = ResponseException::fromRequestException($reqErr);
|
||||
|
||||
$this->assertInstanceOf(ResponseException::class, $respErr);
|
||||
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
|
||||
$this->assertEquals(0, $respErr->getCode());
|
||||
$this->assertEquals($reqErr, $respErr->getPrevious());
|
||||
}
|
||||
|
||||
|
||||
public function testFromRequestExceptionUnknownContentType()
|
||||
{
|
||||
$resp = new Response(404, ['Content-Type' => ['application/octet-stream']]);
|
||||
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
|
||||
$respErr = ResponseException::fromRequestException($reqErr);
|
||||
|
||||
$this->assertInstanceOf(ResponseException::class, $respErr);
|
||||
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
|
||||
$this->assertEquals(0, $respErr->getCode());
|
||||
$this->assertEquals($reqErr, $respErr->getPrevious());
|
||||
}
|
||||
|
||||
public function testFromRequestExceptionJSONDecodeError()
|
||||
{
|
||||
$resp = new Response(404, ['Content-Type' => ['application/json; charset=utf-8']], '[what]');
|
||||
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
|
||||
$respErr = ResponseException::fromRequestException($reqErr);
|
||||
|
||||
$this->assertInstanceOf(ResponseException::class, $respErr);
|
||||
$this->assertEquals($reqErr->getMessage(), $respErr->getMessage());
|
||||
$this->assertEquals(0, $respErr->getCode());
|
||||
$this->assertInstanceOf(JSONException::class, $respErr->getPrevious());
|
||||
$this->assertEquals($reqErr, $respErr->getPrevious()->getPrevious());
|
||||
}
|
||||
|
||||
public function testFromRequestExceptionJSONWithErrors()
|
||||
{
|
||||
$body = '{
|
||||
"result": null,
|
||||
"success": false,
|
||||
"errors": [{"code":1003, "message":"This is an error"}],
|
||||
"messages": []
|
||||
}';
|
||||
|
||||
$resp = new Response(404, ['Content-Type' => ['application/json; charset=utf-8']], $body);
|
||||
$reqErr = new RequestException('foo', new Request('GET', '/test'), $resp);
|
||||
$respErr = ResponseException::fromRequestException($reqErr);
|
||||
|
||||
$this->assertInstanceOf(ResponseException::class, $respErr);
|
||||
$this->assertEquals('This is an error', $respErr->getMessage());
|
||||
$this->assertEquals(1003, $respErr->getCode());
|
||||
$this->assertEquals($reqErr, $respErr->getPrevious());
|
||||
}
|
||||
}
|
||||
21
tests/Auth/APITokenTest.php
Normal file
21
tests/Auth/APITokenTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* User: czPechy
|
||||
* Date: 30/07/2018
|
||||
* Time: 23:25
|
||||
*/
|
||||
class APITokenTest extends TestCase
|
||||
{
|
||||
public function testGetHeaders()
|
||||
{
|
||||
$auth = new \Cloudflare\API\Auth\APIToken('zKq9RDO6PbCjs6PRUXF3BoqFi3QdwY36C2VfOaRy');
|
||||
$headers = $auth->getHeaders();
|
||||
|
||||
$this->assertArrayHasKey('Authorization', $headers);
|
||||
|
||||
$this->assertEquals('Bearer zKq9RDO6PbCjs6PRUXF3BoqFi3QdwY36C2VfOaRy', $headers['Authorization']);
|
||||
|
||||
$this->assertCount(1, $headers);
|
||||
}
|
||||
}
|
||||
22
tests/Configurations/CertificateTest.php
Normal file
22
tests/Configurations/CertificateTest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Cloudflare\API\Configurations\Certificate;
|
||||
|
||||
class CertificateTest extends TestCase
|
||||
{
|
||||
public function testGetArray()
|
||||
{
|
||||
$certificate = new Certificate();
|
||||
$certificate->setHostnames(['foo.com', '*.bar.com']);
|
||||
$certificate->setRequestType(Certificate::ORIGIN_ECC);
|
||||
$certificate->setRequestedValidity(365);
|
||||
$certificate->setCsr('some-csr-encoded-text');
|
||||
|
||||
$array = $certificate->getArray();
|
||||
$this->assertEquals(['foo.com', '*.bar.com'], $array['hostnames']);
|
||||
$this->assertEquals('origin-ecc', $array['request_type']);
|
||||
$this->assertEquals(365, $array['requested_validity']);
|
||||
$this->assertEquals('some-csr-encoded-text', $array['csr']);
|
||||
}
|
||||
}
|
||||
59
tests/Endpoints/AccountMembersTest.php
Normal file
59
tests/Endpoints/AccountMembersTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Endpoints\AccountMembers;
|
||||
|
||||
class AccountMembersTest extends TestCase
|
||||
{
|
||||
public function testAddAccountMember()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccountMember.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/members'),
|
||||
$this->equalTo([
|
||||
'email' => 'user@example.com',
|
||||
'roles' => [
|
||||
'3536bcfad5faccb999b47003c79917fb',
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$accountMembers = new AccountMembers($mock);
|
||||
$accountMembers->addAccountMember('01a7362d577a6c3019a474fd6f485823', 'user@example.com', ['3536bcfad5faccb999b47003c79917fb']);
|
||||
|
||||
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $accountMembers->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testListAccountMembers()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccountMembers.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('accounts/023e105f4ecef8ad9ca31a8372d0c353/members'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
])
|
||||
);
|
||||
|
||||
$accountMembers = new AccountMembers($mock);
|
||||
$result = $accountMembers->listAccountMembers('023e105f4ecef8ad9ca31a8372d0c353', 1, 20);
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
|
||||
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->count);
|
||||
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $accountMembers->getBody()->result[0]->id);
|
||||
}
|
||||
}
|
||||
32
tests/Endpoints/AccountRolesTest.php
Normal file
32
tests/Endpoints/AccountRolesTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Endpoints\AccountRoles;
|
||||
use TestCase;
|
||||
|
||||
class AccountRolesTest extends TestCase
|
||||
{
|
||||
public function testListAccountRoles()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccountRoles.json');
|
||||
|
||||
$adapter = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$adapter->method('get')->willReturn($response);
|
||||
|
||||
$adapter->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('accounts/023e105f4ecef8ad9ca31a8372d0c353/roles'));
|
||||
|
||||
$roles = new AccountRoles($adapter);
|
||||
$result = $roles->listAccountRoles('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertObjectHasAttribute('result_info', $result);
|
||||
|
||||
$this->assertEquals('3536bcfad5faccb999b47003c79917fb', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('3536bcfad5faccb999b47003c79917fb', $roles->getBody()->result[0]->id);
|
||||
}
|
||||
}
|
||||
86
tests/Endpoints/AccountsTest.php
Normal file
86
tests/Endpoints/AccountsTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
use Cloudflare\API\Endpoints\Accounts;
|
||||
|
||||
/**
|
||||
* User: kanasite
|
||||
* Date: 01/28/2019
|
||||
* Time: 10:00
|
||||
*/
|
||||
class AccountsTest extends TestCase
|
||||
{
|
||||
public function testListZones()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccounts.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('accounts'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 20,
|
||||
'direction' => 'desc',
|
||||
])
|
||||
);
|
||||
|
||||
$accounts = new Accounts($mock);
|
||||
$result = $accounts->listAccounts(1, 20, 'desc');
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertObjectHasAttribute('result_info', $result);
|
||||
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
|
||||
$this->assertEquals(1, $result->result_info->page);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $accounts->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testAddAccountWithDefaultType()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createStandardAccount.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('accounts'),
|
||||
$this->equalTo([
|
||||
'name' => 'Foo Bar',
|
||||
'type' => 'standard',
|
||||
])
|
||||
);
|
||||
|
||||
$accounts = new Accounts($mock);
|
||||
|
||||
$accounts->addAccount('Foo Bar');
|
||||
$this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testAddAccountWithCustomType()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createEnterpriseAccount.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('accounts'),
|
||||
$this->equalTo([
|
||||
'name' => 'Foo Bar',
|
||||
'type' => 'enterprise',
|
||||
])
|
||||
);
|
||||
|
||||
$accounts = new Accounts($mock);
|
||||
|
||||
$accounts->addAccount('Foo Bar', 'enterprise');
|
||||
$this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
120
tests/Endpoints/CertificatesTest.php
Normal file
120
tests/Endpoints/CertificatesTest.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
use Cloudflare\API\Endpoints\Certificates;
|
||||
|
||||
class CertificatesTest extends TestCase
|
||||
{
|
||||
public function testListCertificates()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listCertificates.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('certificates'),
|
||||
$this->equalTo(
|
||||
[
|
||||
'zone_id' => '023e105f4ecef8ad9ca31a8372d0c353',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$certEndpoint = new Certificates($mock);
|
||||
$result = $certEndpoint->listCertificates('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
|
||||
$cert = $result->result[0];
|
||||
$this->assertEquals('328578533902268680212849205732770752308931942346', $cert->id);
|
||||
$this->assertEquals('origin-rsa', $cert->request_type);
|
||||
$this->assertEquals(5475, $cert->requested_validity);
|
||||
$this->assertEquals(['example.com', '*.example.com'], $cert->hostnames);
|
||||
$this->assertEquals('some-cert-data', $cert->certificate);
|
||||
$this->assertEquals('some-csr-data', $cert->csr);
|
||||
}
|
||||
|
||||
public function testGetCertificate()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCertificate.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('certificates/6666699999996666699999999966666666'),
|
||||
$this->equalTo(['zone_id' => '023e105f4ecef8ad9ca31a8372d0c353']),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
$certEndpoint = new Certificates($mock);
|
||||
$response = $certEndpoint->getCertificate(
|
||||
'6666699999996666699999999966666666',
|
||||
'023e105f4ecef8ad9ca31a8372d0c353'
|
||||
);
|
||||
|
||||
$this->assertObjectHasAttribute('result', $response);
|
||||
$cert = $response->result;
|
||||
$this->assertEquals('6666699999996666699999999966666666', $cert->id);
|
||||
$this->assertEquals('origin-ecc', $cert->request_type);
|
||||
$this->assertEquals(5475, $cert->requested_validity);
|
||||
$this->assertEquals(['foo.example.com', 'bar.example.com'], $cert->hostnames);
|
||||
$this->assertEquals('some-cert-data-foobar', $cert->certificate);
|
||||
$this->assertEquals('some-csr-data-foobar', $cert->csr);
|
||||
}
|
||||
|
||||
public function testRevokeCertificate()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCertificate.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('certificates/11112222233333444455555'),
|
||||
$this->equalTo(['zone_id' => '023e105f4ecef8ad9ca31a8372d0c353']),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
$certEndpoint = new Certificates($mock);
|
||||
$result = $certEndpoint->revokeCertificate(
|
||||
'11112222233333444455555',
|
||||
'023e105f4ecef8ad9ca31a8372d0c353'
|
||||
);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testCreateCertificate()
|
||||
{
|
||||
$certificate = new \Cloudflare\API\Configurations\Certificate();
|
||||
$certificate->setHostnames(['foo.example.com', 'bar.exapmle.com']);
|
||||
$certificate->setRequestType(\Cloudflare\API\Configurations\Certificate::ORIGIN_ECC);
|
||||
$certificate->setRequestedValidity(365);
|
||||
$certificate->setCsr('some-csr-data-barbar');
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCertificate.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('certificates'),
|
||||
$this->equalTo($certificate->getArray()),
|
||||
$this->equalTo([])
|
||||
);
|
||||
|
||||
$certEndpoint = new Certificates($mock);
|
||||
$result = $certEndpoint->createCertificate($certificate);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ class CustomHostnamesTest extends TestCase
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json');
|
||||
|
||||
$customSsl = $this->getCustomSsl();
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
@@ -23,15 +25,41 @@ class CustomHostnamesTest extends TestCase
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
||||
$this->equalTo([
|
||||
'hostname' => 'app.example.com',
|
||||
'custom_origin_server' => 'origin.example.com',
|
||||
'ssl' => [
|
||||
'method' => 'http',
|
||||
'type' => 'dv'
|
||||
]
|
||||
'type' => 'dv',
|
||||
'settings' => [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2',
|
||||
],
|
||||
'bundle_method' => 'optimal',
|
||||
'custom_key' => $customSsl['key'],
|
||||
'custom_certificate' => $customSsl['certificate'],
|
||||
'wildcard' => true,
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$hostname = new CustomHostnames($mock);
|
||||
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv');
|
||||
$sslSettings = [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2'
|
||||
];
|
||||
|
||||
$hostname->addHostname(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
'app.example.com',
|
||||
'http',
|
||||
'dv',
|
||||
$sslSettings,
|
||||
'origin.example.com',
|
||||
true,
|
||||
'optimal',
|
||||
$customSsl
|
||||
);
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id);
|
||||
}
|
||||
|
||||
@@ -93,6 +121,8 @@ class CustomHostnamesTest extends TestCase
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json');
|
||||
|
||||
$customSsl = $this->getCustomSsl();
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('patch')->willReturn($response);
|
||||
|
||||
@@ -101,15 +131,45 @@ class CustomHostnamesTest extends TestCase
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
||||
$this->equalTo([
|
||||
'custom_origin_server' => 'origin.example.com',
|
||||
'ssl' => [
|
||||
'method' => 'http',
|
||||
'type' => 'dv'
|
||||
'type' => 'dv',
|
||||
'settings' => [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2'
|
||||
],
|
||||
'bundle_method' => 'optimal',
|
||||
'custom_key' => $customSsl['key'],
|
||||
'custom_certificate' => $customSsl['certificate'],
|
||||
'wildcard' => true,
|
||||
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv');
|
||||
$sslSettings = [
|
||||
'http2' => 'on',
|
||||
'http3' => 'on',
|
||||
'min_tls_version' => '1.2'
|
||||
];
|
||||
|
||||
$result = $zones->updateHostname(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
'0d89c70d-ad9f-4843-b99f-6cc0252067e9',
|
||||
'http',
|
||||
'dv',
|
||||
$sslSettings,
|
||||
'origin.example.com',
|
||||
true,
|
||||
'optimal',
|
||||
[
|
||||
'key' => $customSsl['key'],
|
||||
'certificate' => $customSsl['certificate'],
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertObjectHasAttribute('id', $result);
|
||||
$this->assertObjectHasAttribute('hostname', $result);
|
||||
@@ -135,4 +195,88 @@ class CustomHostnamesTest extends TestCase
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id);
|
||||
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->id);
|
||||
}
|
||||
|
||||
public function testGetHostnameFallbackOrigin()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getCustomHostnameFallbackOrigin.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/fallback_origin')
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||
$result = $zones->getFallbackOrigin('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertObjectHasAttribute('origin', $result);
|
||||
$this->assertObjectHasAttribute('status', $result);
|
||||
}
|
||||
|
||||
private function getCustomSsl(): array
|
||||
{
|
||||
$customKey = <<<KEY
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDZfoCUkzkZLCzo
|
||||
OFTtlXU9OYqNFx06J/GOKCwDCyfkY5RY1x6BVrVpTqf/JaU42DZmCjIiEugBg4bu
|
||||
eu9/w21prIWgRKEe8mjrw83+3QSIyQrs+78rqwDptUfL+IyhYln6SBjqPQ569Y0w
|
||||
x6A896PDMYPHgnWtclGwsxDNKJ2eWsH+C4UkLUeVM4BILEJ00YUjayowL/0sflTJ
|
||||
yY58c9fVV27aGBJ4znreYkBojPQ0fzVZ3HJfYD+DgYUUkuzN/WohOLTNTxvzt/i2
|
||||
GNxP8tZzi0E/t4KtGTsIVmROKaCXnmozQyv0VES5TNZL1nxLvVuPca9DKXwVst2o
|
||||
v5czEM8fAgMBAAECggEBANgG/aIVpWYqaaRyp3CgviWE7Oh9J+um1xgzMJwJTaNd
|
||||
gXDIoyUmweQKW3Vjp/uRTl8GC4uqqcUvJivj8dU+gIOw970bzcmWT7616vsV/rX6
|
||||
sp524wh1vt9jzx97DfwSW3rsd8rZwHNDSO1FqxRDiOaNXO4i183iud8/zRVqHTy1
|
||||
5girngsGl7ebTt3LDHDQQ86kND2nVr8xZuFaqs8Td41AsF6DGbB709wMUqoM/obO
|
||||
iUtXCZ5Rrm2a78OUi0cqWsuxdhJjtOW0PBvrPTlSq+1EuQWAWV8HN1JI58YnLcLy
|
||||
SKZpsu5wxWdKMgX0NCkfLjDZCAPlBaZLPPp986GHavECgYEA8hM6tIfGBnXuxBvI
|
||||
y2lJG3sHGs83pnCqYg9dDrr+m3JOPQu6l9MEPEtsrOiI0Ktu/L+kV5uyBDRvB6ff
|
||||
BD6BJ2CiG86UvMpKojBeAlZBLXr1SnWzIPC+3fBzkVSo1MiRs3nTNRfeblkRxC3e
|
||||
LWtl96obA1GOgpifrh6ZB2RfvrcCgYEA5gFL4+oDUDcRtc1Pw+AFwPTey+3rkVU+
|
||||
FHvRGeU+m6dtxXF+BYFpDs/ONfmHzsdBSwkYxta/x8rKP5uyjl9p0QSdhysrJibO
|
||||
sWsoux35QxEZiyplCV2+zMK/79EhS2CuiudAidF6NxK+/g9EwXRlGDDlnFDB2epe
|
||||
kyL97K4zCtkCgYEA68Bgbsq/xzD5XFG2xqr9wN6a97gQ+W5F8QQHW74vEZJLsdYH
|
||||
Xa7rNBE8gFRiUd5zU4EL+yotPz0VWH5bilWZEJFirvQMFKRp9PRnyZzZEwLpeh+Q
|
||||
WSc8qwZudn3dgoTmqMSfNdjODed+jvEgrFkoz/8BGcVGpdcfw8IWxIUzXZcCgYAY
|
||||
/OsRx8q0XEdASR3xWdVGMVRDM4X0NB6aexkshwtWPcpfOQVH89dGFK2Cj6mBfYRK
|
||||
cqKOd6Y+Pnnajz/G1/bXDnlOxhHaAz1RaSLzsT3zW1g7FlADxHuGI2JW25GSbt6H
|
||||
mLgaQPfWI+M8FsyRd+PDzQwk/2EQG7ZKpfKQVByXgQKBgQDkKciB6Wb2hLNTKzK8
|
||||
Kr42U70H++QT8AqZX2F79PjgYcRFZqGXLuq/hEuiOhXfl8DFur3fC5JN8AeLC5/j
|
||||
bsrBsljYfVvtLQzilugs1oEe94LTrYjR2oQt0W24bqpGQHuv1ILuUBuodERkxSFL
|
||||
/cMkj3wSfC341hFaJEuG1+PcxA==
|
||||
-----END PRIVATE KEY-----
|
||||
KEY;
|
||||
|
||||
$customCertificate = <<<CERTIFICATE
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDmTCCAoGgAwIBAgIULyaeNqp0tOut/wvuxNyKmUxOGYEwDQYJKoZIhvcNAQEL
|
||||
BQAwXDELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UE
|
||||
CgwTRGVmYXVsdCBDb21wYW55IEx0ZDEYMBYGA1UEAwwPYXBwLmV4YW1wbGUuY29t
|
||||
MB4XDTIxMDYxNDIzMzU0MVoXDTIyMDYxNDIzMzU0MVowXDELMAkGA1UEBhMCWFgx
|
||||
FTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBDb21wYW55
|
||||
IEx0ZDEYMBYGA1UEAwwPYXBwLmV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEF
|
||||
AAOCAQ8AMIIBCgKCAQEA2X6AlJM5GSws6DhU7ZV1PTmKjRcdOifxjigsAwsn5GOU
|
||||
WNcegVa1aU6n/yWlONg2ZgoyIhLoAYOG7nrvf8NtaayFoEShHvJo68PN/t0EiMkK
|
||||
7Pu/K6sA6bVHy/iMoWJZ+kgY6j0OevWNMMegPPejwzGDx4J1rXJRsLMQzSidnlrB
|
||||
/guFJC1HlTOASCxCdNGFI2sqMC/9LH5UycmOfHPX1Vdu2hgSeM563mJAaIz0NH81
|
||||
WdxyX2A/g4GFFJLszf1qITi0zU8b87f4thjcT/LWc4tBP7eCrRk7CFZkTimgl55q
|
||||
M0Mr9FREuUzWS9Z8S71bj3GvQyl8FbLdqL+XMxDPHwIDAQABo1MwUTAdBgNVHQ4E
|
||||
FgQUbAfyBm0wpM7FqUb1yqeaF4voY/gwHwYDVR0jBBgwFoAUbAfyBm0wpM7FqUb1
|
||||
yqeaF4voY/gwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAO2Dd
|
||||
k/seFjp83caYE/NVdDy5B7l5JeVtruaUdlGbb0xtVhiIdoY43ukhHFw8zuWMW9RX
|
||||
SUbrzwacfKLDBikcefk9go6cMimqYIRF8Hntph1gjjqB0papUm2WVYbsBRv2okys
|
||||
ej0dGSeUEsWjKRTSMkJsbbiEv6oveeSki069zl+tln0UhbHedkIY3rJsFIyoddSu
|
||||
g96r5HPHksnObm1JCym0xd09+msliDkBmq87mxok9m5aEqWX4XvdGfYERV/eD5vC
|
||||
KcW4DoM1KZd8E6tlniglc1jC0pzKfho7Uoe6UtObgHZGNwRYwYy+BHvHYY46ctSI
|
||||
NdZ7G/lUyrBFhsRrhw==
|
||||
-----END CERTIFICATE-----
|
||||
CERTIFICATE;
|
||||
|
||||
return [
|
||||
'key' => $customKey,
|
||||
'certificate' => $customCertificate,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
91
tests/Endpoints/DNSAnalyticsTest.php
Normal file
91
tests/Endpoints/DNSAnalyticsTest.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Visual Studio Code.
|
||||
* User: elliot.alderson
|
||||
* Date: 10/02/2020
|
||||
* Time: 04:28 AM
|
||||
*/
|
||||
class DNSAnalyticsTest extends TestCase
|
||||
{
|
||||
public function testGetDNSAnalyticsReportTable()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture(
|
||||
'Endpoints/getDNSAnalyticsReportTable.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_analytics/report'
|
||||
)
|
||||
);
|
||||
|
||||
$analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
|
||||
$since = '2020-02-01T00:00:00Z';
|
||||
$until = '2020-02-28T23:59:59Z';
|
||||
$filters = 'responseCode==NOERROR AND queryType==A';
|
||||
|
||||
$result = $analytics->getReportTable(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
['queryName', 'queryType', 'responseCode'],
|
||||
['queryCount'],
|
||||
['-queryCount'],
|
||||
$filters,
|
||||
$since,
|
||||
$until
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $result->rows);
|
||||
$this->assertEquals($since, $result->query->since);
|
||||
$this->assertEquals($until, $result->query->until);
|
||||
}
|
||||
|
||||
public function testGetDNSAnalyticsReportByTime()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture(
|
||||
'Endpoints/getDNSAnalyticsReportByTime.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_analytics/report/bytime'
|
||||
)
|
||||
);
|
||||
|
||||
$analytics = new \Cloudflare\API\Endpoints\DNSAnalytics($mock);
|
||||
$since = '2020-02-01T00:00:00Z';
|
||||
$until = '2020-02-28T23:59:59Z';
|
||||
$filters = 'responseCode==NOERROR AND queryType==A';
|
||||
|
||||
$result = $analytics->getReportByTime(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
['queryName', 'queryType', 'responseCode'],
|
||||
['queryCount'],
|
||||
['-queryCount'],
|
||||
$filters,
|
||||
$since,
|
||||
$until,
|
||||
2
|
||||
);
|
||||
|
||||
$this->assertEquals(2, $result->rows);
|
||||
$this->assertEquals($since, $result->query->since);
|
||||
$this->assertEquals($until, $result->query->until);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,57 @@ class DNSTest extends TestCase
|
||||
$dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', '120', false);
|
||||
}
|
||||
|
||||
public function testAddMXRecordPriority10()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.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/dns_records'),
|
||||
$this->equalTo([
|
||||
'type' => 'MX',
|
||||
'name' => 'example.com',
|
||||
'content' => '127.0.0.1',
|
||||
'ttl' => 120,
|
||||
'proxied' => false,
|
||||
'priority' => 10,
|
||||
])
|
||||
);
|
||||
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||
$dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'MX', 'example.com', '127.0.0.1', '120', false, 10);
|
||||
}
|
||||
|
||||
public function testAddMXRecordPriority0()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.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/dns_records'),
|
||||
$this->equalTo([
|
||||
'type' => 'MX',
|
||||
'name' => 'example.com',
|
||||
'content' => '127.0.0.1',
|
||||
'ttl' => 120,
|
||||
'proxied' => false,
|
||||
'priority' => 0,
|
||||
])
|
||||
);
|
||||
|
||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||
$dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'MX', 'example.com', '127.0.0.1', '120', false, 0);
|
||||
}
|
||||
|
||||
|
||||
public function testListRecords()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.json');
|
||||
|
||||
177
tests/Endpoints/FirewallTest.php
Normal file
177
tests/Endpoints/FirewallTest.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
class FirewallTest extends TestCase
|
||||
{
|
||||
public function testCreatePageRules()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createFirewallRules.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/rules'),
|
||||
$this->equalTo([
|
||||
[
|
||||
'action' => 'block',
|
||||
'description' => 'Foo',
|
||||
'filter' => [
|
||||
'expression' => 'http.cookie eq "foo"',
|
||||
'paused' => false
|
||||
],
|
||||
],
|
||||
[
|
||||
'action' => 'block',
|
||||
'description' => 'Bar',
|
||||
'filter' => [
|
||||
'expression' => 'http.cookie eq "bar"',
|
||||
'paused' => false
|
||||
],
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||
$result = $firewall->createFirewallRules(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
[
|
||||
[
|
||||
'filter' => [
|
||||
'expression' => 'http.cookie eq "foo"',
|
||||
'paused' => false
|
||||
],
|
||||
'action' => 'block',
|
||||
'description' => 'Foo'
|
||||
],
|
||||
[
|
||||
'filter' => [
|
||||
'expression' => 'http.cookie eq "bar"',
|
||||
'paused' => false
|
||||
],
|
||||
'action' => 'block',
|
||||
'description' => 'Bar'
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testCreatePageRule()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createFirewallRule.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/rules'),
|
||||
$this->equalTo([
|
||||
[
|
||||
'action' => 'block',
|
||||
'description' => 'Foobar',
|
||||
'filter' => [
|
||||
'expression' => 'http.cookie eq "foobar"',
|
||||
'paused' => false
|
||||
],
|
||||
'paused' => false
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||
$options = new \Cloudflare\API\Configurations\FirewallRuleOptions();
|
||||
$options->setActionBlock();
|
||||
$result = $firewall->createFirewallRule(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
'http.cookie eq "foobar"',
|
||||
$options,
|
||||
'Foobar'
|
||||
);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testListFirewallRules()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listFirewallRules.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/rules'),
|
||||
$this->equalTo([
|
||||
'page' => 1,
|
||||
'per_page' => 50
|
||||
])
|
||||
);
|
||||
|
||||
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||
$result = $firewall->listFirewallRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertObjectHasAttribute('result_info', $result);
|
||||
|
||||
$this->assertEquals('970b10321e3f4adda674c912b5f76591', $result->result[0]->id);
|
||||
}
|
||||
|
||||
public function testDeleteFirewallRule()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteFirewallRule.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/rules/970b10321e3f4adda674c912b5f76591')
|
||||
);
|
||||
|
||||
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||
$firewall->deleteFirewallRule('023e105f4ecef8ad9ca31a8372d0c353', '970b10321e3f4adda674c912b5f76591');
|
||||
}
|
||||
|
||||
public function testUpdateFirewallRule()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateFirewallRule.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('put')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('put')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/rules/970b10321e3f4adda674c912b5f76591'),
|
||||
$this->equalTo([
|
||||
'id' => '970b10321e3f4adda674c912b5f76591',
|
||||
'action' => 'block',
|
||||
'description' => 'Foo',
|
||||
'filter' => [
|
||||
'id' => '5def9c4297e0466cb0736b838345d910',
|
||||
'expression' => 'http.cookie eq "foo"',
|
||||
'paused' => false
|
||||
],
|
||||
'paused' => false
|
||||
])
|
||||
);
|
||||
|
||||
$firewall = new Cloudflare\API\Endpoints\Firewall($mock);
|
||||
$options = new \Cloudflare\API\Configurations\FirewallRuleOptions();
|
||||
$options->setActionBlock();
|
||||
$result = $firewall->updateFirewallRule(
|
||||
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||
'970b10321e3f4adda674c912b5f76591',
|
||||
'5def9c4297e0466cb0736b838345d910',
|
||||
'http.cookie eq "foo"',
|
||||
$options,
|
||||
'Foo'
|
||||
);
|
||||
$this->assertEquals('970b10321e3f4adda674c912b5f76591', $result->id);
|
||||
}
|
||||
}
|
||||
191
tests/Endpoints/RulesListsTest.php
Executable file
191
tests/Endpoints/RulesListsTest.php
Executable file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace Endpoints;
|
||||
|
||||
use TestCase;
|
||||
|
||||
class RulesListsTest extends TestCase
|
||||
{
|
||||
|
||||
public function testCreateRulesList()
|
||||
{
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRulesList.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists'),
|
||||
$this->equalTo([
|
||||
'kind' => 'ip',
|
||||
'name' => 'ip-allowlist',
|
||||
])
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->createList('01a7362d577a6c3019a474fd6f485823', 'ip', 'ip-allowlist');
|
||||
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->id);
|
||||
$this->assertEquals('ip', $result->kind);
|
||||
$this->assertEquals('ip-allowlist', $result->name);
|
||||
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testDeleteRulesList()
|
||||
{
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRulesList.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e')
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->deleteList('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e');
|
||||
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->id);
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testGetRulesLists()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRulesLists.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists')
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->getLists('01a7362d577a6c3019a474fd6f485823');
|
||||
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result[0]->id);
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result[0]->id);
|
||||
}
|
||||
|
||||
public function testGetRulesListDetails()
|
||||
{
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRulesListDetails.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e')
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->getListDetails('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e');
|
||||
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $result->id);
|
||||
$this->assertEquals('ip', $result->kind);
|
||||
|
||||
$this->assertEquals('2c0fc9fa937b11eaa1b71c4d701ab86e', $rulesLists->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testGetRulesListItems()
|
||||
{
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRulesListItems.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items'),
|
||||
$this->equalTo([
|
||||
'per_page' => 20,
|
||||
])
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->getListItems('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e');
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertObjectHasAttribute('result_info', $result);
|
||||
|
||||
$this->assertEquals('10.0.0.1', $result->result[0]);
|
||||
$this->assertEquals('10.0.0.1', $rulesLists->getBody()->result[0]);
|
||||
}
|
||||
|
||||
public function testCreateRulesListItem() {
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRulesListItem.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items')
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->createListItem('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e', [
|
||||
'10.0.0.1'
|
||||
]);
|
||||
|
||||
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $result->operation_id);
|
||||
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $rulesLists->getBody()->result->operation_id);
|
||||
}
|
||||
|
||||
public function testDeleteRulesListItem() {
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRulesListItem.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/2c0fc9fa937b11eaa1b71c4d701ab86e/items')
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->deleteListItem('01a7362d577a6c3019a474fd6f485823', '2c0fc9fa937b11eaa1b71c4d701ab86e', ['6as9450mma215q6so7p79dd981r4ee09']);
|
||||
|
||||
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $result->operation_id);
|
||||
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $rulesLists->getBody()->result->operation_id);
|
||||
}
|
||||
|
||||
public function testGetOperationStatus() {
|
||||
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOperationStatus.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/rules/lists/bulk_operations/4da8780eeb215e6cb7f48dd981c4ea02')
|
||||
);
|
||||
|
||||
$rulesLists = new \Cloudflare\API\Endpoints\RulesLists($mock);
|
||||
$result = $rulesLists->getOperationStatus('01a7362d577a6c3019a474fd6f485823', '4da8780eeb215e6cb7f48dd981c4ea02');
|
||||
|
||||
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $result->id);
|
||||
$this->assertEquals('4da8780eeb215e6cb7f48dd981c4ea02', $rulesLists->getBody()->result->id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class SSLTest extends TestCase
|
||||
$result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||
|
||||
$this->assertObjectHasAttribute('result', $result);
|
||||
$this->assertEquals('active', $result->result{0}->certificate_status);
|
||||
$this->assertEquals('active', $result->result[0]->certificate_status);
|
||||
}
|
||||
|
||||
public function testGetHTTPSRedirectSetting()
|
||||
@@ -138,4 +138,24 @@ class SSLTest extends TestCase
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testUpdateSSLCertificatePackValidationMethod()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLCertificatePackValidationMethod.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/ssl/verification/a77f8bd7-3b47-46b4-a6f1-75cf98109948'),
|
||||
$this->equalTo(['validation_method' => 'txt'])
|
||||
);
|
||||
|
||||
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||
$result = $sslMock->updateSSLCertificatePackValidationMethod('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'a77f8bd7-3b47-46b4-a6f1-75cf98109948', 'txt');
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
|
||||
78
tests/Endpoints/ZoneCacheTest.php
Normal file
78
tests/Endpoints/ZoneCacheTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
class ZoneCacheTest extends TestCase
|
||||
{
|
||||
public function testCachePurgeEverything()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.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/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||
$this->equalTo(['purge_everything' => true])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testCachePurgeHost()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->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('post')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->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);
|
||||
}
|
||||
}
|
||||
19
tests/Endpoints/ZoneDeleteTest.php
Normal file
19
tests/Endpoints/ZoneDeleteTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
class ZoneDeleteTest extends TestCase
|
||||
{
|
||||
public function testDeleteTest()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteZoneTest.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')
|
||||
);
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->deleteZone('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
69
tests/Endpoints/ZoneSettingsTest.php
Normal file
69
tests/Endpoints/ZoneSettingsTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Endpoints\ZoneSettings;
|
||||
|
||||
class ZoneSettingsTest extends TestCase
|
||||
{
|
||||
public function testGetServerSideExcludeSetting()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getServerSideExclude.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())->method('get');
|
||||
|
||||
$zones = new ZoneSettings($mock);
|
||||
$result = $zones->getServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertSame('on', $result);
|
||||
}
|
||||
|
||||
public function testUpdateServerSideExcludeSetting()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateServerSideExclude.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('patch')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())->method('patch');
|
||||
|
||||
$zones = new ZoneSettings($mock);
|
||||
$result = $zones->updateServerSideExcludeSetting('023e105f4ecef8ad9ca31a8372d0c353', 'on');
|
||||
|
||||
$this->assertSame('on', $result);
|
||||
}
|
||||
|
||||
public function testGetBrowserCacheTtlSetting()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserCacheTtlSetting.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())->method('get');
|
||||
|
||||
$zones = new ZoneSettings($mock);
|
||||
$result = $zones->getBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertSame(14400, $result);
|
||||
}
|
||||
|
||||
public function testUpdateBrowserCacheTtlSetting()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserCacheTtlSetting.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('patch')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())->method('patch');
|
||||
|
||||
$zones = new ZoneSettings($mock);
|
||||
$result = $zones->updateBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353', 16070400);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
81
tests/Endpoints/ZoneSubscriptionsTest.php
Normal file
81
tests/Endpoints/ZoneSubscriptionsTest.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
use Cloudflare\API\Endpoints\ZoneSubscriptions;
|
||||
|
||||
class ZoneSubscriptionsTest extends TestCase
|
||||
{
|
||||
public function testListZoneSubscriptions()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listZoneSubscriptions.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscriptions')
|
||||
);
|
||||
|
||||
$zoneSubscriptions = new ZoneSubscriptions($mock);
|
||||
$zoneSubscriptions->listZoneSubscriptions('023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result[0]->id);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result[0]->zone->id);
|
||||
}
|
||||
|
||||
public function testAddZoneSubscriptionIfMissing()
|
||||
{
|
||||
$postResponse = $this->getPsr7JsonResponseForFixture('Endpoints/createZoneSubscription.json');
|
||||
$getResponse = $this->getPsr7JsonResponseForFixture('Endpoints/listEmptyZoneSubscriptions.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('post')->willReturn($postResponse);
|
||||
$mock->method('get')->willReturn($getResponse);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('post')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscription'),
|
||||
$this->equalTo([
|
||||
'rate_plan' => [
|
||||
'id' => 'PARTNER_PRO',
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$zoneSubscriptions = new ZoneSubscriptions($mock);
|
||||
$zoneSubscriptions->addZoneSubscription('023e105f4ecef8ad9ca31a8372d0c353', 'PARTNER_PRO');
|
||||
|
||||
$this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result->id);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result->zone->id);
|
||||
}
|
||||
|
||||
public function testAddZoneSubscriptionIfExisting()
|
||||
{
|
||||
$postResponse = $this->getPsr7JsonResponseForFixture('Endpoints/createZoneSubscription.json');
|
||||
$getResponse = $this->getPsr7JsonResponseForFixture('Endpoints/listZoneSubscriptions.json');
|
||||
|
||||
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||
$mock->method('put')->willReturn($postResponse);
|
||||
$mock->method('get')->willReturn($getResponse);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('put')
|
||||
->with(
|
||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscription'),
|
||||
$this->equalTo([
|
||||
'rate_plan' => [
|
||||
'id' => 'PARTNER_PRO',
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$zoneSubscriptions = new ZoneSubscriptions($mock);
|
||||
$zoneSubscriptions->addZoneSubscription('023e105f4ecef8ad9ca31a8372d0c353', 'PARTNER_PRO');
|
||||
|
||||
$this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result->id);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result->zone->id);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,9 @@ class ZonesTest extends TestCase
|
||||
$this->equalTo([
|
||||
'name' => 'example.com',
|
||||
'jump_start' => true,
|
||||
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
|
||||
'account' => [
|
||||
'id' => '01a7362d577a6c3019a474fd6f485823',
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
@@ -49,6 +51,33 @@ class ZonesTest extends TestCase
|
||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testAddZoneWithAccountId()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addZone.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'),
|
||||
$this->equalTo([
|
||||
'name' => 'example.com',
|
||||
'jump_start' => false,
|
||||
'account' => [
|
||||
'id' => '023e105f4ecef8ad9ca31a8372d0c353',
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->addZone('example.com', false, '023e105f4ecef8ad9ca31a8372d0c353');
|
||||
|
||||
$this->assertObjectHasAttribute('id', $result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->account->id);
|
||||
}
|
||||
|
||||
public function testActivationTest()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
|
||||
@@ -188,78 +217,4 @@ class ZonesTest extends TestCase
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('development_mode', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testCachePurgeEverything()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.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(['purge_everything' => true])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testCachePurgeHost()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||
$this->equalTo(
|
||||
[
|
||||
'files' => [],
|
||||
'tags' => [],
|
||||
'hosts' => ['dash.cloudflare.com']
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
|
||||
public function testCachePurge()
|
||||
{
|
||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
|
||||
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('delete')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('delete')
|
||||
->with(
|
||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||
$this->equalTo(['files' => [
|
||||
'https://example.com/file.jpg',
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
|
||||
'https://example.com/file.jpg',
|
||||
]);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
"email": "user@example.com",
|
||||
"owner_type": "user"
|
||||
},
|
||||
"account": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
"name": "Demo Account"
|
||||
},
|
||||
"permissions": [
|
||||
"#zone:read",
|
||||
"#zone:edit"
|
||||
|
||||
74
tests/Fixtures/Endpoints/createAccountMember.json
Normal file
74
tests/Fixtures/Endpoints/createAccountMember.json
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "4536bcfad5faccb111b47003c79917fa",
|
||||
"code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0",
|
||||
"user": {
|
||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||
"first_name": "John",
|
||||
"last_name": "Appleseed",
|
||||
"email": "user@example.com",
|
||||
"two_factor_authentication_enabled": false
|
||||
},
|
||||
"status": "accepted",
|
||||
"roles": [
|
||||
{
|
||||
"id": "3536bcfad5faccb999b47003c79917fb",
|
||||
"name": "Account Administrator",
|
||||
"description": "Administrative access to the entire Account",
|
||||
"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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
17
tests/Fixtures/Endpoints/createCertificate.json
Normal file
17
tests/Fixtures/Endpoints/createCertificate.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "12341234123412341234",
|
||||
"certificate": "some-cert-data-foofoo",
|
||||
"hostnames": [
|
||||
"foo.example.com",
|
||||
"bar.example.com"
|
||||
],
|
||||
"expires_on": "2014-01-01T05:20:00.12345Z",
|
||||
"request_type": "origin-ecc",
|
||||
"requested_validity": 365,
|
||||
"csr": "some-csr-data-barbar"
|
||||
}
|
||||
}
|
||||
13
tests/Fixtures/Endpoints/createEnterpriseAccount.json
Normal file
13
tests/Fixtures/Endpoints/createEnterpriseAccount.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"result": {
|
||||
"id": "2bab6ace8c72ed3f09b9eca6db1396bb",
|
||||
"name": "Foo Bar",
|
||||
"type": "enterprise",
|
||||
"settings": {
|
||||
"enforce_twofactor": false
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
20
tests/Fixtures/Endpoints/createFirewallRule.json
Normal file
20
tests/Fixtures/Endpoints/createFirewallRule.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"id": "970b10321e3f4adda674c912b5f76591",
|
||||
"paused": false,
|
||||
"description": "Foobar",
|
||||
"action": "block",
|
||||
"filter": {
|
||||
"id": "70f39827184d487e97cc286b960f4cc3",
|
||||
"expression": "http.cookie eq \"foobar\"",
|
||||
"paused": false
|
||||
},
|
||||
"created_on": "2019-07-05T15:53:15Z",
|
||||
"modified_on": "2019-07-05T15:53:15Z"
|
||||
}
|
||||
],
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
33
tests/Fixtures/Endpoints/createFirewallRules.json
Normal file
33
tests/Fixtures/Endpoints/createFirewallRules.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"id": "970b10321e3f4adda674c912b5f76591",
|
||||
"paused": false,
|
||||
"description": "Foo",
|
||||
"action": "block",
|
||||
"filter": {
|
||||
"id": "70f39827184d487e97cc286b960f4cc3",
|
||||
"expression": "http.cookie eq \"foo\"",
|
||||
"paused": false
|
||||
},
|
||||
"created_on": "2019-07-05T15:53:15Z",
|
||||
"modified_on": "2019-07-05T15:53:15Z"
|
||||
},
|
||||
{
|
||||
"id": "42c05fd0e0af4d17a361d2d1423476bc",
|
||||
"paused": false,
|
||||
"description": "Bar",
|
||||
"action": "block",
|
||||
"filter": {
|
||||
"id": "246b4d9f5f51471485bdc95e1c6b53a7",
|
||||
"expression": "http.cookie eq \"bar\"",
|
||||
"paused": false
|
||||
},
|
||||
"created_on": "2019-07-05T15:53:15Z",
|
||||
"modified_on": "2019-07-05T15:53:15Z"
|
||||
}
|
||||
],
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
25
tests/Fixtures/Endpoints/createRulesList.json
Executable file
25
tests/Fixtures/Endpoints/createRulesList.json
Executable file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e",
|
||||
"created_on": "2020-01-01T08:00:00Z",
|
||||
"description": "",
|
||||
"kind": "ip",
|
||||
"modified_on": "2020-01-10T14:00:00Z",
|
||||
"name": "ip-allowlist",
|
||||
"num_items": 10,
|
||||
"num_referencing_filters": 2
|
||||
}
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/createRulesListItem.json
Executable file
18
tests/Fixtures/Endpoints/createRulesListItem.json
Executable file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"operation_id": "4da8780eeb215e6cb7f48dd981c4ea02"
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
13
tests/Fixtures/Endpoints/createStandardAccount.json
Normal file
13
tests/Fixtures/Endpoints/createStandardAccount.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"result": {
|
||||
"id": "2bab6ace8c72ed3f09b9eca6db1396bb",
|
||||
"name": "Foo Bar",
|
||||
"type": "standard",
|
||||
"settings": {
|
||||
"enforce_twofactor": false
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
40
tests/Fixtures/Endpoints/createZoneSubscription.json
Normal file
40
tests/Fixtures/Endpoints/createZoneSubscription.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"app": {
|
||||
"install_id": null
|
||||
},
|
||||
"id": "506e3185e9c882d175a2d0cb0093d9f2",
|
||||
"state": "Paid",
|
||||
"price": 20,
|
||||
"currency": "USD",
|
||||
"component_values": [
|
||||
{
|
||||
"name": "page_rules",
|
||||
"value": 20,
|
||||
"default": 5,
|
||||
"price": 5
|
||||
}
|
||||
],
|
||||
"zone": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
"name": "example.com"
|
||||
},
|
||||
"frequency": "monthly",
|
||||
"rate_plan": {
|
||||
"id": "free",
|
||||
"public_name": "Business Plan",
|
||||
"currency": "USD",
|
||||
"scope": "zone",
|
||||
"sets": [
|
||||
{}
|
||||
],
|
||||
"is_contract": false,
|
||||
"externally_managed": false
|
||||
},
|
||||
"current_period_end": "2014-03-31T12:20:00Z",
|
||||
"current_period_start": "2014-05-11T12:20:00Z"
|
||||
}
|
||||
}
|
||||
8
tests/Fixtures/Endpoints/deleteFirewallRule.json
Normal file
8
tests/Fixtures/Endpoints/deleteFirewallRule.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"result": {
|
||||
"id": "970b10321e3f4adda674c912b5f76591"
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/deleteRulesList.json
Executable file
18
tests/Fixtures/Endpoints/deleteRulesList.json
Executable file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e"
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
18
tests/Fixtures/Endpoints/deleteRulesListItem.json
Executable file
18
tests/Fixtures/Endpoints/deleteRulesListItem.json
Executable file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"operation_id": "4da8780eeb215e6cb7f48dd981c4ea02"
|
||||
}
|
||||
}
|
||||
8
tests/Fixtures/Endpoints/deleteZoneTest.json
Normal file
8
tests/Fixtures/Endpoints/deleteZoneTest.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "9a7806061c88ada191ed06f989cc3dac"
|
||||
}
|
||||
}
|
||||
11
tests/Fixtures/Endpoints/getBrowserCacheTtlSetting.json
Normal file
11
tests/Fixtures/Endpoints/getBrowserCacheTtlSetting.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "browser_cache_ttl",
|
||||
"value": 14400,
|
||||
"editable": true,
|
||||
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||
}
|
||||
}
|
||||
17
tests/Fixtures/Endpoints/getCertificate.json
Normal file
17
tests/Fixtures/Endpoints/getCertificate.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "6666699999996666699999999966666666",
|
||||
"certificate": "some-cert-data-foobar",
|
||||
"hostnames": [
|
||||
"foo.example.com",
|
||||
"bar.example.com"
|
||||
],
|
||||
"expires_on": "2014-01-01T05:20:00.12345Z",
|
||||
"request_type": "origin-ecc",
|
||||
"requested_validity": 5475,
|
||||
"csr": "some-csr-data-foobar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{}
|
||||
],
|
||||
"messages": [
|
||||
{}
|
||||
],
|
||||
"result": {
|
||||
"origin": "fallback.example.com",
|
||||
"status": "pending_deployment",
|
||||
"errors": [
|
||||
"DNS records are not setup correctly. Origin should be a proxied A/AAAA/CNAME dns record"
|
||||
],
|
||||
"created_at": "2019-10-28T18:11:23.37411Z",
|
||||
"updated_at": "2020-03-16T18:11:23.531995Z"
|
||||
}
|
||||
}
|
||||
31
tests/Fixtures/Endpoints/getDNSAnalyticsReportByTime.json
Normal file
31
tests/Fixtures/Endpoints/getDNSAnalyticsReportByTime.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"result": {
|
||||
"rows": 2,
|
||||
"data": [
|
||||
{
|
||||
"metrics": [[911, 993]]
|
||||
}
|
||||
],
|
||||
"data_lag": 0,
|
||||
"min": {},
|
||||
"max": {},
|
||||
"totals": {
|
||||
"queryCount": 455312
|
||||
},
|
||||
"time_intervals": [
|
||||
["2020-02-10T11:19:00Z", "2020-02-10T11:19:59Z"],
|
||||
["2020-02-10T11:20:00Z", "2020-02-10T11:20:59Z"]
|
||||
],
|
||||
"query": {
|
||||
"dimensions": [],
|
||||
"metrics": ["queryCount"],
|
||||
"since": "2020-02-01T00:00:00Z",
|
||||
"until": "2020-02-28T23:59:59Z",
|
||||
"time_delta": "minute",
|
||||
"limit": 2
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
34
tests/Fixtures/Endpoints/getDNSAnalyticsReportTable.json
Normal file
34
tests/Fixtures/Endpoints/getDNSAnalyticsReportTable.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"result": {
|
||||
"rows": 1,
|
||||
"data": [
|
||||
{
|
||||
"dimensions": ["thrdld.sld.tld", "TXT", "NOERROR"],
|
||||
"metrics": [2]
|
||||
}
|
||||
],
|
||||
"data_lag": 0,
|
||||
"min": {},
|
||||
"max": {},
|
||||
"totals": {
|
||||
"queryCount": 2
|
||||
},
|
||||
"query": {
|
||||
"dimensions": ["queryName", "queryType", "responseCode"],
|
||||
"metrics": ["queryCount"],
|
||||
"filters": "responseCode==NOERROR AND queryType==TXT",
|
||||
"sort": [
|
||||
{
|
||||
"Id": "queryCount",
|
||||
"Desc": true
|
||||
}
|
||||
],
|
||||
"since": "2020-02-01T00:00:00Z",
|
||||
"until": "2020-02-28T23:59:59Z",
|
||||
"limit": 10000
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
21
tests/Fixtures/Endpoints/getOperationStatus.json
Executable file
21
tests/Fixtures/Endpoints/getOperationStatus.json
Executable file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"id": "4da8780eeb215e6cb7f48dd981c4ea02",
|
||||
"status": "pending",
|
||||
"completed": "2020-01-01T08:00:00Z",
|
||||
"error": "This list is at the maximum number of items"
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
25
tests/Fixtures/Endpoints/getRulesListDetails.json
Executable file
25
tests/Fixtures/Endpoints/getRulesListDetails.json
Executable file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e",
|
||||
"created_on": "2020-01-01T08:00:00Z",
|
||||
"description": "This is a note",
|
||||
"kind": "ip",
|
||||
"modified_on": "2020-01-10T14:00:00Z",
|
||||
"name": "list1",
|
||||
"num_items": 10,
|
||||
"num_referencing_filters": 2
|
||||
}
|
||||
}
|
||||
24
tests/Fixtures/Endpoints/getRulesListItems.json
Executable file
24
tests/Fixtures/Endpoints/getRulesListItems.json
Executable file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": [
|
||||
"10.0.0.1"
|
||||
],
|
||||
"result_info": {
|
||||
"cursors": {
|
||||
"after": "yyy",
|
||||
"before": "xxx"
|
||||
}
|
||||
}
|
||||
}
|
||||
11
tests/Fixtures/Endpoints/getServerSideExclude.json
Normal file
11
tests/Fixtures/Endpoints/getServerSideExclude.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "server_side_exclude",
|
||||
"value": "on",
|
||||
"editable": true,
|
||||
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||
}
|
||||
}
|
||||
82
tests/Fixtures/Endpoints/listAccountMembers.json
Normal file
82
tests/Fixtures/Endpoints/listAccountMembers.json
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": [
|
||||
{
|
||||
"id": "4536bcfad5faccb111b47003c79917fa",
|
||||
"code": "05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0",
|
||||
"user": {
|
||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
||||
"first_name": "John",
|
||||
"last_name": "Appleseed",
|
||||
"email": "user@example.com",
|
||||
"two_factor_authentication_enabled": false
|
||||
},
|
||||
"status": "accepted",
|
||||
"roles": [
|
||||
{
|
||||
"id": "3536bcfad5faccb999b47003c79917fb",
|
||||
"name": "Account Administrator",
|
||||
"description": "Administrative access to the entire Account",
|
||||
"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": 200
|
||||
}
|
||||
}
|
||||
69
tests/Fixtures/Endpoints/listAccountRoles.json
Normal file
69
tests/Fixtures/Endpoints/listAccountRoles.json
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": [
|
||||
{
|
||||
"id": "3536bcfad5faccb999b47003c79917fb",
|
||||
"name": "Account Administrator",
|
||||
"description": "Administrative access to the entire Account",
|
||||
"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": 1,
|
||||
"total_pages": 1,
|
||||
"count": 1,
|
||||
"total_count": 1
|
||||
}
|
||||
}
|
||||
20
tests/Fixtures/Endpoints/listAccounts.json
Normal file
20
tests/Fixtures/Endpoints/listAccounts.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": [
|
||||
{
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
"name": "Example Account",
|
||||
"settings": {
|
||||
"enforce_twofactor": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"result_info": {
|
||||
"page": 1,
|
||||
"per_page": 20,
|
||||
"count": 1,
|
||||
"total_count": 2000
|
||||
}
|
||||
}
|
||||
19
tests/Fixtures/Endpoints/listCertificates.json
Normal file
19
tests/Fixtures/Endpoints/listCertificates.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": [
|
||||
{
|
||||
"id": "328578533902268680212849205732770752308931942346",
|
||||
"certificate": "some-cert-data",
|
||||
"hostnames": [
|
||||
"example.com",
|
||||
"*.example.com"
|
||||
],
|
||||
"expires_on": "2014-01-01T05:20:00.12345Z",
|
||||
"request_type": "origin-rsa",
|
||||
"requested_validity": 5475,
|
||||
"csr": "some-csr-data"
|
||||
}
|
||||
]
|
||||
}
|
||||
6
tests/Fixtures/Endpoints/listEmptyZoneSubscriptions.json
Normal file
6
tests/Fixtures/Endpoints/listEmptyZoneSubscriptions.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": []
|
||||
}
|
||||
27
tests/Fixtures/Endpoints/listFirewallRules.json
Normal file
27
tests/Fixtures/Endpoints/listFirewallRules.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"result": [
|
||||
{
|
||||
"id": "970b10321e3f4adda674c912b5f76591",
|
||||
"paused": false,
|
||||
"description": "Foobar",
|
||||
"action": "block",
|
||||
"filter": {
|
||||
"id": "70f39827184d487e97cc286b960f4cc3",
|
||||
"expression": "http.cookie eq \"foobar\"",
|
||||
"paused": false
|
||||
},
|
||||
"created_on": "2019-07-05T15:53:15Z",
|
||||
"modified_on": "2019-07-05T15:53:15Z"
|
||||
}
|
||||
],
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result_info": {
|
||||
"page": 1,
|
||||
"per_page": 50,
|
||||
"count": 1,
|
||||
"total_count": 1,
|
||||
"total_pages": 1
|
||||
}
|
||||
}
|
||||
27
tests/Fixtures/Endpoints/listRulesLists.json
Executable file
27
tests/Fixtures/Endpoints/listRulesLists.json
Executable file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"code": 1000,
|
||||
"message": "message"
|
||||
}
|
||||
],
|
||||
"result": [
|
||||
{
|
||||
"id": "2c0fc9fa937b11eaa1b71c4d701ab86e",
|
||||
"created_on": "2020-01-01T08:00:00Z",
|
||||
"kind": "ip",
|
||||
"modified_on": "2020-01-10T14:00:00Z",
|
||||
"name": "list1",
|
||||
"num_items": 10,
|
||||
"description": "This is a note",
|
||||
"num_referencing_filters": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
42
tests/Fixtures/Endpoints/listZoneSubscriptions.json
Normal file
42
tests/Fixtures/Endpoints/listZoneSubscriptions.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": [
|
||||
{
|
||||
"app": {
|
||||
"install_id": null
|
||||
},
|
||||
"id": "506e3185e9c882d175a2d0cb0093d9f2",
|
||||
"state": "Paid",
|
||||
"price": 20,
|
||||
"currency": "USD",
|
||||
"component_values": [
|
||||
{
|
||||
"name": "page_rules",
|
||||
"value": 20,
|
||||
"default": 5,
|
||||
"price": 5
|
||||
}
|
||||
],
|
||||
"zone": {
|
||||
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||
"name": "example.com"
|
||||
},
|
||||
"frequency": "monthly",
|
||||
"rate_plan": {
|
||||
"id": "free",
|
||||
"public_name": "Business Plan",
|
||||
"currency": "USD",
|
||||
"scope": "zone",
|
||||
"sets": [
|
||||
{}
|
||||
],
|
||||
"is_contract": false,
|
||||
"externally_managed": false
|
||||
},
|
||||
"current_period_end": "2014-03-31T12:20:00Z",
|
||||
"current_period_start": "2014-05-11T12:20:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
8
tests/Fixtures/Endpoints/revokeCertificate.json
Normal file
8
tests/Fixtures/Endpoints/revokeCertificate.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "11112222233333444455555"
|
||||
}
|
||||
}
|
||||
11
tests/Fixtures/Endpoints/updateBrowserCacheTtlSetting.json
Normal file
11
tests/Fixtures/Endpoints/updateBrowserCacheTtlSetting.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "browser_cache_ttl",
|
||||
"value": 14400,
|
||||
"editable": true,
|
||||
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||
}
|
||||
}
|
||||
19
tests/Fixtures/Endpoints/updateFirewallRule.json
Normal file
19
tests/Fixtures/Endpoints/updateFirewallRule.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"result": {
|
||||
"id": "970b10321e3f4adda674c912b5f76591",
|
||||
"paused": false,
|
||||
"description": "Foo",
|
||||
"action": "block",
|
||||
"filter": {
|
||||
"id": "5def9c4297e0466cb0736b838345d910",
|
||||
"expression": "http.cookie eq \"foo\"",
|
||||
"paused": false
|
||||
},
|
||||
"created_on": "2019-07-05T15:53:15Z",
|
||||
"modified_on": "2019-07-05T18:07:46Z",
|
||||
"index": 1
|
||||
},
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": []
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"validation_method": "txt",
|
||||
"status": "pending_validation"
|
||||
}
|
||||
}
|
||||
11
tests/Fixtures/Endpoints/updateServerSideExclude.json
Normal file
11
tests/Fixtures/Endpoints/updateServerSideExclude.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"id": "server_side_exclude",
|
||||
"value": "on",
|
||||
"editable": true,
|
||||
"modified_on": "2014-01-01T05:20:00.12345Z"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user