Compare commits
321 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 | ||
|
|
9b9738910d | ||
|
|
90a9f51fd6 | ||
|
|
b17ae6e7d0 | ||
|
|
b558622bb5 | ||
|
|
d913aa827f | ||
|
|
6a9a9f55b6 | ||
|
|
b04abe73bc | ||
|
|
1724b66147 | ||
|
|
7343b7cc46 | ||
|
|
bd10d7f833 | ||
|
|
598ba5c1d1 | ||
|
|
ed06650390 | ||
|
|
246925dec2 | ||
|
|
7a7e6dc364 | ||
|
|
5f57b871aa | ||
|
|
31453d8184 | ||
|
|
21b3f20fb1 | ||
|
|
45834c0709 | ||
|
|
c44a26fa35 | ||
|
|
1764856f5b | ||
|
|
79ca15c066 | ||
|
|
63ded280d3 | ||
|
|
fb9d75d94a | ||
|
|
1cf5963445 | ||
|
|
ecb23ccc44 | ||
|
|
b81c67ddc5 | ||
|
|
b46a2f80f5 | ||
|
|
fab0bc7a12 | ||
|
|
6a29d75001 | ||
|
|
99c174bcb3 | ||
|
|
3cfeedbe4d | ||
|
|
7aa3a118af | ||
|
|
ae2c680e85 | ||
|
|
78eadb9a47 | ||
|
|
e1c2539d9a | ||
|
|
471a42d554 | ||
|
|
d9c0a27b7d | ||
|
|
8182aa8810 | ||
|
|
df12f7ba6f | ||
|
|
9d434a23b3 | ||
|
|
f105d38d85 | ||
|
|
910644f88d | ||
|
|
68b9fa3353 | ||
|
|
c394f5ac4d | ||
|
|
e94ab8ddbe | ||
|
|
2b25365988 | ||
|
|
bd92b2a4c0 | ||
|
|
44eb77f9ca | ||
|
|
fb45932677 | ||
|
|
dde2de4495 | ||
|
|
6acf09ba82 | ||
|
|
6410f50f6d | ||
|
|
d6f0eada8c | ||
|
|
6f1ac605f5 | ||
|
|
9311583f43 | ||
|
|
4694904b38 | ||
|
|
7e3e367f16 | ||
|
|
97af6a2ca6 | ||
|
|
3da4f053f0 | ||
|
|
1e369bd9cd | ||
|
|
5841936f04 | ||
|
|
a8017f864b | ||
|
|
ba2c37fe1e | ||
|
|
db0f0eed79 | ||
|
|
4e17cc8984 | ||
|
|
c1193f7f91 | ||
|
|
67a24c5784 | ||
|
|
8bb2e8a110 | ||
|
|
9d1750594e | ||
|
|
ed6b1ec5a2 | ||
|
|
90e01ff095 | ||
|
|
8c68295daa | ||
|
|
57318b2a56 | ||
|
|
099f383ef3 | ||
|
|
2639331c2b | ||
|
|
d871bdd007 | ||
|
|
c60064e542 | ||
|
|
0492e9b17b | ||
|
|
5bea924c76 | ||
|
|
943b0d85d4 | ||
|
|
e28fed86d1 | ||
|
|
45df26fec3 | ||
|
|
a39d6fb170 | ||
|
|
4c288c38d7 | ||
|
|
2dd4d8f883 | ||
|
|
59f6d72d0a | ||
|
|
f19f17ea6f | ||
|
|
a3a346ccb2 | ||
|
|
deb420d087 | ||
|
|
640b787540 | ||
|
|
8df0ec5511 | ||
|
|
938065cdf3 | ||
|
|
9076d714f4 | ||
|
|
c9d2782b88 | ||
|
|
1cca3e0724 | ||
|
|
63be6cf154 | ||
|
|
c06fe79ad0 | ||
|
|
cca073c809 | ||
|
|
35ce8eadf1 | ||
|
|
d95573976e | ||
|
|
3bfd5e17f1 | ||
|
|
19a4f481d3 | ||
|
|
9c56941516 | ||
|
|
e18a64e7e4 | ||
|
|
3585dde8ea | ||
|
|
730b0c97ee | ||
|
|
dc53414c2a | ||
|
|
a628cac283 | ||
|
|
0112425a61 | ||
|
|
fe854e1b21 | ||
|
|
45cb8ee539 | ||
|
|
cd2fd73cc3 | ||
|
|
bd83c6d48a | ||
|
|
4e3d307bdd | ||
|
|
99d89e7dc3 | ||
|
|
55e81fe02c | ||
|
|
d00a1d3f44 | ||
|
|
c8e85d2582 | ||
|
|
ff42f334a5 | ||
|
|
dfa299c895 | ||
|
|
e1864a6824 | ||
|
|
c9d21466aa | ||
|
|
b15b4ecc51 | ||
|
|
0aa9f6c05a | ||
|
|
a09478eb2f | ||
|
|
f6cb9a8e30 | ||
|
|
bc9e15a557 | ||
|
|
5caae74370 | ||
|
|
ee4a42ea06 | ||
|
|
90eaea7be2 | ||
|
|
dac1e15e2d | ||
|
|
a4224265d8 | ||
|
|
4f3f82b1ba | ||
|
|
7c9ea4874d | ||
|
|
0920fc48b2 | ||
|
|
65e4f29bc0 | ||
|
|
3453e44158 | ||
|
|
8ee1bbcc6f | ||
|
|
d8b2093eed | ||
|
|
3cfaed1019 | ||
|
|
84ee7302ca | ||
|
|
f088c67314 | ||
|
|
30fc22aa5b | ||
|
|
0d89f13f9b | ||
|
|
ca9e5bbc28 | ||
|
|
f0213ecf92 | ||
|
|
b4a6237509 | ||
|
|
a909f3780e | ||
|
|
e1cf1ae41f | ||
|
|
70ee68f755 | ||
|
|
566ab3fc70 | ||
|
|
ca80e2c388 | ||
|
|
d49028a31e | ||
|
|
6a76e1cc3c | ||
|
|
a5384b7466 | ||
|
|
8ffd3e3541 | ||
|
|
3ce5e1911f | ||
|
|
1226d35472 | ||
|
|
cebeae15a3 | ||
|
|
db62f1db8a | ||
|
|
b7e70655ce | ||
|
|
49ed1c9e8f | ||
|
|
68a26e7e77 | ||
|
|
b4a13d8e2b | ||
|
|
a80747ee06 | ||
|
|
fbb5aac074 | ||
|
|
471227b96f | ||
|
|
4d17609641 | ||
|
|
feecc9fcbb | ||
|
|
589766e008 | ||
|
|
2faff272df | ||
|
|
90196ea836 | ||
|
|
80c611691b | ||
|
|
85385dedf5 | ||
|
|
b91dd5e684 | ||
|
|
77df7ead1e | ||
|
|
9939afd0b6 | ||
|
|
7d838d7f5f | ||
|
|
ebe2a9803a | ||
|
|
f38b1c61f7 | ||
|
|
635a299b43 | ||
|
|
85d64f8afc | ||
|
|
48db6337c5 | ||
|
|
4699270f51 |
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
|
||||||
2
.gitignore
vendored
Normal file → Executable file
2
.gitignore
vendored
Normal file → Executable file
@@ -1 +1,3 @@
|
|||||||
|
/.idea
|
||||||
/vendor/
|
/vendor/
|
||||||
|
/nbproject/
|
||||||
|
|||||||
15
.php_cs
Normal file
15
.php_cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$finder = PhpCsFixer\Finder::create()
|
||||||
|
->in(__DIR__ . '/src')
|
||||||
|
->in(__DIR__ . '/tests')
|
||||||
|
;
|
||||||
|
|
||||||
|
return PhpCsFixer\Config::create()
|
||||||
|
->setUsingCache(false)
|
||||||
|
->setRules([
|
||||||
|
'@PSR2' => true,
|
||||||
|
'array_syntax' => ['syntax' => 'short'],
|
||||||
|
])
|
||||||
|
->setFinder($finder)
|
||||||
|
;
|
||||||
14
.travis.yml
14
.travis.yml
@@ -1,14 +0,0 @@
|
|||||||
language: php
|
|
||||||
|
|
||||||
php:
|
|
||||||
- 7.0
|
|
||||||
- 7.1
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- composer self-update
|
|
||||||
|
|
||||||
install:
|
|
||||||
- travis_retry composer install --no-interaction --prefer-source
|
|
||||||
|
|
||||||
script:
|
|
||||||
- composer test
|
|
||||||
17
CONTRIBUTING.md
Normal file
17
CONTRIBUTING.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Contributing to Cloudflare PHP API Binding
|
||||||
|
|
||||||
|
👍🎉 First off, thanks for taking the time to contribute! 🎉👍
|
||||||
|
|
||||||
|
## How To Contribute
|
||||||
|
|
||||||
|
We welcome community contribution to this repository. To help add functionality or address issues, please take the following steps:
|
||||||
|
|
||||||
|
* Fork the repository from the master branch.
|
||||||
|
* Create a new branch for your features / fixes.
|
||||||
|
* Make the changes you wish to see.
|
||||||
|
* Add tests for all changes.
|
||||||
|
* Run `make fix` command to ensure the code is styled.
|
||||||
|
* Run `make test` command to ensure the tests pass.
|
||||||
|
* Create a pull request with details of what changes have been made and explanation of new behaviour.
|
||||||
|
* Ensure documentation contains the correct information.
|
||||||
|
* Pull requests will be reviewed and hopefully merged into a release.
|
||||||
14
Makefile
Normal file
14
Makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
.PHONY: all fix lint test
|
||||||
|
|
||||||
|
all: lint test
|
||||||
|
|
||||||
|
fix:
|
||||||
|
php vendor/bin/php-cs-fixer fix --config=.php_cs
|
||||||
|
|
||||||
|
lint:
|
||||||
|
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 vendor/bin/phpunit --configuration phpunit.xml
|
||||||
70
README.md
Normal file → Executable file
70
README.md
Normal file → Executable file
@@ -2,42 +2,48 @@
|
|||||||
|
|
||||||
[](https://travis-ci.org/cloudflare/cloudflare-php)
|
[](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: added by Shellrent
|
||||||
|
|
||||||
## Cloudflare API version 4
|
- DNS Record is returned on creation:
|
||||||
|
|
||||||
The Cloudflare API can be found [here](https://api.cloudflare.com/).
|
`Class: Cloudflare\API\Endpoints\DNS`
|
||||||
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-)
|
|
||||||
- [ ] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
|
||||||
- [ ] Virtual DNS Management
|
|
||||||
- [ ] Custom hostnames
|
|
||||||
- [x] Zone Lockdown and User-Agent Block rules
|
|
||||||
- [ ] Organization Administration
|
|
||||||
- [ ] [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/)
|
|
||||||
|
|
||||||
Note that this repository is currently under development, additional classes and endpoints being actively added.
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$key = new \Cloudflare\API\Auth\APIKey('user@example.com', 'apiKey');
|
public function addRecord(
|
||||||
$adapter = new Cloudflare\API\Adapter\Guzzle($key);
|
string $zoneID,
|
||||||
$user = new \Cloudflare\API\Endpoints\User($adapter);
|
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;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Licensing
|
|
||||||
|
|
||||||
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.
|
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "cloudflare/sdk",
|
"name": "yuemi/cloudflare-php",
|
||||||
"description": "PHP binding for v4 of the Cloudflare Client API.",
|
"description": "PHP binding for v4 of the Cloudflare Client API.",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^6.2.2",
|
"guzzlehttp/guzzle": "^7.0.1",
|
||||||
"php": ">=7.0.0",
|
"php": ">=7.2.5",
|
||||||
"psr/http-message": "~1.0"
|
"psr/http-message": "^1.0 || ^2.0",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "5.7.5",
|
"phpunit/phpunit": "^5.7",
|
||||||
"phpmd/phpmd" : "@stable"
|
"phpmd/phpmd" : "@stable",
|
||||||
|
"friendsofphp/php-cs-fixer": "^2.6"
|
||||||
},
|
},
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -23,7 +25,14 @@
|
|||||||
"Cloudflare\\API\\": "src/"
|
"Cloudflare\\API\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"autoload-dev": {
|
||||||
"test": "phpunit"
|
"classmap": [
|
||||||
|
"tests/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"preferred-install": "dist",
|
||||||
|
"sort-packages": true,
|
||||||
|
"optimize-autoloader": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1714
composer.lock
generated
1714
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -21,55 +21,56 @@ interface Adapter
|
|||||||
* Adapter constructor.
|
* Adapter constructor.
|
||||||
*
|
*
|
||||||
* @param Auth $auth
|
* @param Auth $auth
|
||||||
* @param String $baseURI
|
* @param string $baseURI
|
||||||
*/
|
*/
|
||||||
public function __construct(Auth $auth, String $baseURI);
|
public function __construct(Auth $auth, string $baseURI);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a GET request.
|
* Sends a GET request.
|
||||||
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
|
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
|
||||||
* RFCs, it is never useful).
|
* RFCs, it is never useful).
|
||||||
*
|
*
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get(String $uri, array $headers): ResponseInterface;
|
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function post(String $uri, array $headers, array $body): ResponseInterface;
|
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function put(String $uri, array $headers, array $body): ResponseInterface;
|
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function patch(String $uri, array $headers, array $body): ResponseInterface;
|
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $uri
|
* @param string $uri
|
||||||
|
* @param array $data
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @param array $body
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function delete(String $uri, array $headers, array $body): ResponseInterface;
|
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface;
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* User: junade
|
|
||||||
* Date: 13/01/2017
|
|
||||||
* Time: 18:26
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Cloudflare\API\Adapter;
|
namespace Cloudflare\API\Adapter;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Auth\Auth;
|
use Cloudflare\API\Auth\Auth;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
class Guzzle implements Adapter
|
class Guzzle implements Adapter
|
||||||
@@ -19,10 +14,10 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function __construct(Auth $auth, String $baseURI = null)
|
public function __construct(Auth $auth, string $baseURI = null)
|
||||||
{
|
{
|
||||||
if ($baseURI === null) {
|
if ($baseURI === null) {
|
||||||
$baseURI = "https://api.cloudflare.com/client/v4/";
|
$baseURI = 'https://api.cloudflare.com/client/v4/';
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers = $auth->getHeaders();
|
$headers = $auth->getHeaders();
|
||||||
@@ -38,95 +33,89 @@ class Guzzle implements Adapter
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function get(String $uri, array $headers = array()): ResponseInterface
|
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$response = $this->client->get($uri, ['headers' => $headers]);
|
return $this->request('get', $uri, $data, $headers);
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function post(String $uri, array $headers = array(), array $body = array()): ResponseInterface
|
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$response = $this->client->post($uri, [
|
return $this->request('post', $uri, $data, $headers);
|
||||||
'headers' => $headers,
|
|
||||||
'json' => $body
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function put(String $uri, array $headers = array(), array $body = array()): ResponseInterface
|
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$jsonBody = json_encode($body);
|
return $this->request('put', $uri, $data, $headers);
|
||||||
|
|
||||||
$response = $this->client->put($uri, [
|
|
||||||
'headers' => $headers,
|
|
||||||
'json' => $jsonBody
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function patch(String $uri, array $headers = array(), array $body = array()): ResponseInterface
|
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$jsonBody = json_encode($body);
|
return $this->request('patch', $uri, $data, $headers);
|
||||||
|
|
||||||
$response = $this->client->patch($uri, [
|
|
||||||
'headers' => $headers,
|
|
||||||
'json' => $jsonBody
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function delete(String $uri, array $headers = array(), array $body = array()): ResponseInterface
|
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$response = $this->client->delete($uri, [
|
return $this->request('delete', $uri, $data, $headers);
|
||||||
'headers' => $headers,
|
|
||||||
'json' => $body
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->checkError($response);
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkError(ResponseInterface $response)
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||||
|
*/
|
||||||
|
public function request(string $method, string $uri, array $data = [], array $headers = [])
|
||||||
{
|
{
|
||||||
$json = json_decode($response->getBody());
|
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
|
||||||
|
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
||||||
throw new JSONException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json->errors)) {
|
try {
|
||||||
foreach ($json->errors as $error) {
|
$response = $this->client->$method($uri, [
|
||||||
throw new ResponseException($error->message, $error->code);
|
'headers' => $headers,
|
||||||
}
|
($method === 'get' ? 'query' : 'json') => $data,
|
||||||
|
]);
|
||||||
|
} catch (RequestException $err) {
|
||||||
|
throw ResponseException::fromRequestException($err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($json->success) && ($json->success === false)) {
|
return $response;
|
||||||
throw new ResponseException("Request was unsuccessful.");
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$multipart = [];
|
||||||
|
foreach( $data as $key => $value ) {
|
||||||
|
$multipart[] = [
|
||||||
|
'name' => $key,
|
||||||
|
'contents' => $value
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->client->$method($uri, [
|
||||||
|
'headers' => $headers,
|
||||||
|
'multipart' => $multipart
|
||||||
|
]);
|
||||||
|
} catch (RequestException $err) {
|
||||||
|
throw ResponseException::fromRequestException($err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Adapter;
|
namespace Cloudflare\API\Adapter;
|
||||||
|
|
||||||
|
|
||||||
class JSONException extends \Exception
|
class JSONException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,37 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Adapter;
|
namespace Cloudflare\API\Adapter;
|
||||||
|
|
||||||
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
|
||||||
class ResponseException extends \Exception
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,13 +7,12 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
class APIKey implements Auth
|
class APIKey implements Auth
|
||||||
{
|
{
|
||||||
private $email;
|
private $email;
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
|
|
||||||
public function __construct(String $email, String $apiKey)
|
public function __construct(string $email, string $apiKey)
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
$this->apiKey = $apiKey;
|
$this->apiKey = $apiKey;
|
||||||
|
|||||||
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
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
interface Auth
|
interface Auth
|
||||||
{
|
{
|
||||||
public function getHeaders(): array;
|
public function getHeaders(): array;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
class None implements Auth
|
class None implements Auth
|
||||||
{
|
{
|
||||||
public function getHeaders(): array
|
public function getHeaders(): array
|
||||||
|
|||||||
@@ -7,12 +7,11 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Auth;
|
namespace Cloudflare\API\Auth;
|
||||||
|
|
||||||
|
|
||||||
class UserServiceKey implements Auth
|
class UserServiceKey implements Auth
|
||||||
{
|
{
|
||||||
private $userServiceKey;
|
private $userServiceKey;
|
||||||
|
|
||||||
public function __construct(String $userServiceKey)
|
public function __construct(string $userServiceKey)
|
||||||
{
|
{
|
||||||
$this->userServiceKey = $userServiceKey;
|
$this->userServiceKey = $userServiceKey;
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/Configurations/AccessRules.php
Normal file
33
src/Configurations/AccessRules.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class AccessRules implements Configurations
|
||||||
|
{
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
public function setIP(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'ip', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIPRange(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'ip_range', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCountry(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'country', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setASN(string $value)
|
||||||
|
{
|
||||||
|
$this->config = ['target' => 'asn', 'value' => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->config;
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
interface Configurations
|
interface Configurations
|
||||||
{
|
{
|
||||||
public function getArray(): array;
|
public function getArray(): array;
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationsException extends \Exception
|
class ConfigurationsException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
178
src/Configurations/LoadBalancer.php
Normal file
178
src/Configurations/LoadBalancer.php
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class LoadBalancer implements Configurations
|
||||||
|
{
|
||||||
|
private $configs = [];
|
||||||
|
|
||||||
|
public function __construct(string $name, array $defaultPools, string $fallbackPool)
|
||||||
|
{
|
||||||
|
$this->setName($name);
|
||||||
|
$this->setDefaultPools($defaultPools);
|
||||||
|
$this->setFallbackPool($fallbackPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name)
|
||||||
|
{
|
||||||
|
$this->configs['name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName():string
|
||||||
|
{
|
||||||
|
return $this->configs['name'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDefaultPools(array $defaultPools)
|
||||||
|
{
|
||||||
|
$this->configs['default_pools'] = $defaultPools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaultPools():array
|
||||||
|
{
|
||||||
|
return $this->configs['default_pools'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFallbackPool(string $fallbackPool)
|
||||||
|
{
|
||||||
|
$this->configs['fallback_pools'] = $fallbackPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFallbackPool():string
|
||||||
|
{
|
||||||
|
return $this->configs['fallback_pools'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSteeringPolicy(string $steeringPolicy = '')
|
||||||
|
{
|
||||||
|
$allowedOptions = ['off', 'geo', 'random', 'dynamic_latency', ''];
|
||||||
|
if (!in_array($steeringPolicy, $allowedOptions)) {
|
||||||
|
throw new ConfigurationsException('Given steering policy value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->configs['steering_policy'] = $steeringPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSteeringPolicy():string
|
||||||
|
{
|
||||||
|
return $this->configs['steering_policy'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDisabled():bool
|
||||||
|
{
|
||||||
|
return !$this->configs['enabled'] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPopPools(array $popPools)
|
||||||
|
{
|
||||||
|
$this->configs['pop_pools'] = $popPools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPopPools():array
|
||||||
|
{
|
||||||
|
return $this->configs['pop_pools'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTtl(int $ttl)
|
||||||
|
{
|
||||||
|
$this->configs['ttl'] = $ttl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTtl():int
|
||||||
|
{
|
||||||
|
return $this->configs['ttl'] ?? 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRegionPools(array $regionPools)
|
||||||
|
{
|
||||||
|
$this->configs['region_pools'] = $regionPools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRegionPools():array
|
||||||
|
{
|
||||||
|
return $this->configs['region_pools'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSessionAffinity(string $sessionAffinity = '')
|
||||||
|
{
|
||||||
|
$allowedOptions = ['none', 'cookie', 'ip_cookie', ''];
|
||||||
|
if (!in_array($sessionAffinity, $allowedOptions)) {
|
||||||
|
throw new ConfigurationsException('Given session affinity value is not a valid option, valid options are: ' . implode(', ', $allowedOptions));
|
||||||
|
}
|
||||||
|
$this->configs['session_affinity'] = $sessionAffinity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSessionAffinity():string
|
||||||
|
{
|
||||||
|
return $this->configs['session_affinity'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(string $description = '')
|
||||||
|
{
|
||||||
|
$this->configs['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription():string
|
||||||
|
{
|
||||||
|
return $this->configs['description'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enableProxied()
|
||||||
|
{
|
||||||
|
$this->configs['proxied'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disableProxied()
|
||||||
|
{
|
||||||
|
$this->configs['proxied'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isProxied():bool
|
||||||
|
{
|
||||||
|
return $this->configs['proxied'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSessionAffinityTtl(int $sessionAffinityTtl = 82800)
|
||||||
|
{
|
||||||
|
if ($sessionAffinityTtl > 604800 || $sessionAffinityTtl < 1800) {
|
||||||
|
throw new ConfigurationsException('The value of session affinity ttl must be between 1800 and 604800');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->configs['session_affinity_ttl'] = $sessionAffinityTtl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSessionAffinityTtl():int
|
||||||
|
{
|
||||||
|
return $this->configs['session_affinity_ttl'] ?? 82800;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
337
src/Configurations/PageRulesActions.php
Normal file → Executable file
337
src/Configurations/PageRulesActions.php
Normal file → Executable file
@@ -10,360 +10,311 @@ namespace Cloudflare\API\Configurations;
|
|||||||
|
|
||||||
class PageRulesActions implements Configurations
|
class PageRulesActions implements Configurations
|
||||||
{
|
{
|
||||||
private $configs = array();
|
private $configs = [];
|
||||||
|
|
||||||
public function setAlwaysOnline(bool $active)
|
public function setAlwaysOnline(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('always_online', [
|
||||||
$object->id = "always_online";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAlwaysUseHTTPS(bool $active)
|
public function setAlwaysUseHTTPS(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('always_use_https', [
|
||||||
$object->id = "always_use_https";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBrowserCacheTTL(int $ttl)
|
public function setBrowserCacheTTL(int $ttl)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('browser_cache_ttl', [
|
||||||
$object->id = "browser_cache_ttl";
|
'value' => $ttl
|
||||||
$object->value = $ttl;
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
public function setOriginCacheControl(bool $active)
|
||||||
|
{
|
||||||
|
$this->addConfigurationOption('explicit_cache_control', [
|
||||||
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBrowserIntegrityCheck(bool $active)
|
public function setBrowserIntegrityCheck(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('browser_check', [
|
||||||
$object->id = "browser_check";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBypassCacheOnCookie(bool $value)
|
public function setBypassCacheOnCookie(string $value)
|
||||||
{
|
{
|
||||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||||
throw new ConfigurationsException("Invalid cookie string.");
|
throw new ConfigurationsException('Invalid cookie string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('bypass_cache_on_cookie', [
|
||||||
$object->id = "bypass_cache_on_cookie";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheByDeviceType(bool $active)
|
public function setCacheByDeviceType(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_by_device_type', [
|
||||||
$object->id = "cache_by_device_type";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheKey(string $value)
|
public function setCacheKey(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_key', [
|
||||||
$object->id = "cache_key";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheLevel(string $value)
|
public function setCacheLevel(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
|
if (!in_array($value, ['bypass', 'basic', 'simplified', 'aggressive', 'cache_everything'])) {
|
||||||
throw new ConfigurationsException("Invalid cache level");
|
throw new ConfigurationsException('Invalid cache level');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_level', [
|
||||||
$object->id = "cache_level";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCacheOnCookie(bool $value)
|
public function setCacheOnCookie(string $value)
|
||||||
{
|
{
|
||||||
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
|
||||||
throw new ConfigurationsException("Invalid cookie string.");
|
throw new ConfigurationsException('Invalid cookie string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('cache_on_cookie', [
|
||||||
$object->id = "cache_on_cookie";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableApps(bool $active)
|
public function setDisableApps(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_apps', [
|
||||||
$object->id = "disable_apps";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisablePerformance(bool $active)
|
public function setDisablePerformance(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_performance', [
|
||||||
$object->id = "disable_performance";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableSecurity(bool $active)
|
public function setDisableSecurity(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_security', [
|
||||||
$object->id = "disable_security";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEdgeCacheTTL(int $value)
|
public function setEdgeCacheTTL(int $value)
|
||||||
{
|
{
|
||||||
if ($value > 2419200) {
|
if ($value > 2678400) {
|
||||||
throw new ConfigurationsException("Edge Cache TTL too high.");
|
throw new ConfigurationsException('Edge Cache TTL too high.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('edge_cache_ttl', [
|
||||||
$object->id = "edge_cache_ttl";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEmailObfuscation(bool $active)
|
public function setEmailObfuscation(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_security', [
|
||||||
$object->id = "disable_security";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setForwardingURL(int $statusCode, string $forwardingUrl)
|
public function setForwardingURL(int $statusCode, string $forwardingUrl)
|
||||||
{
|
{
|
||||||
if (in_array($statusCode, ['301', '302'])) {
|
if (!in_array($statusCode, ['301', '302'])) {
|
||||||
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
|
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption("forwarding_url", [
|
||||||
$object->id = "forwarding_url";
|
'value' => [
|
||||||
$object->status_code = $statusCode;
|
'status_code' => $statusCode,
|
||||||
$object->url = $forwardingUrl;
|
'url' => $forwardingUrl,
|
||||||
|
],
|
||||||
array_push($this->configs, $object);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHostHeaderOverride(bool $active)
|
public function setHostHeaderOverride(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('host_header_override', [
|
||||||
$object->id = "host_header_override";
|
'value' => $value
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHotlinkProtection(bool $active)
|
public function setHotlinkProtection(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('hotlink_protection', [
|
||||||
$object->id = "hotlink_protection";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIPGeoLocationHeader(bool $active)
|
public function setIPGeoLocationHeader(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('ip_geolocation', [
|
||||||
$object->id = "ip_geolocation";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMinification(bool $html, bool $css, bool $js)
|
public function setMinification(bool $html, bool $css, bool $javascript)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('minification', [
|
||||||
$object->id = "minification";
|
'html' => $this->getBoolAsOnOrOff($html),
|
||||||
$object->html = $html === true ? "on" : "off";
|
'css' => $this->getBoolAsOnOrOff($css),
|
||||||
$object->css = $css === true ? "on" : "off";
|
'js' => $this->getBoolAsOnOrOff($javascript),
|
||||||
$object->js = $js === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMirage(bool $active)
|
public function setMirage(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('mirage', [
|
||||||
$object->id = "mirage";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOriginErrorPagePassthru(bool $active)
|
public function setOriginErrorPagePassthru(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('origin_error_page_pass_thru', [
|
||||||
$object->id = "origin_error_page_pass_thru";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setQueryStringSort(bool $active)
|
public function setQueryStringSort(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('sort_query_string_for_cache', [
|
||||||
$object->id = "sort_query_string_for_cache";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDisableRailgun(bool $active)
|
public function setDisableRailgun(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('disable_railgun', [
|
||||||
$object->id = "disable_railgun";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResolveOverride(bool $value)
|
public function setResolveOverride(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('resolve_override', [
|
||||||
$object->id = "resolve_override";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRespectStrongEtag(bool $active)
|
public function setRespectStrongEtag(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('respect_strong_etag', [
|
||||||
$object->id = "respect_strong_etag";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResponseBuffering(bool $active)
|
public function setResponseBuffering(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('response_buffering', [
|
||||||
$object->id = "response_buffering";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRocketLoader(string $value)
|
public function setRocketLoader(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "manual", "automatic"])) {
|
if (!in_array($value, ['off', 'manual', 'automatic'])) {
|
||||||
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
|
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('rocket_loader', [
|
||||||
$object->id = "rocket_loader";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSecurityLevel(string $value)
|
public function setSecurityLevel(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
|
if (!in_array($value, ['off', 'essentially_off', 'low', 'medium', 'high', 'under_attack'])) {
|
||||||
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
|
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('security_level', [
|
||||||
$object->id = "security_level";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setServerSideExcludes(bool $active)
|
public function setServerSideExcludes(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('server_side_exclude', [
|
||||||
$object->id = "server_side_exclude";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSmartErrors(bool $active)
|
public function setSmartErrors(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('smart_errors', [
|
||||||
$object->id = "smart_errors";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSSL(string $value)
|
public function setSSL(string $value)
|
||||||
{
|
{
|
||||||
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
|
if (!in_array($value, ['off', 'flexible', 'full', 'strict', 'origin_pull'])) {
|
||||||
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('ssl', [
|
||||||
$object->id = "smart_errors";
|
'value' => $value
|
||||||
$object->value = $value;
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTrueClientIpHeader(bool $active)
|
public function setTrueClientIpHeader(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('true_client_ip_header', [
|
||||||
$object->id = "true_client_ip_header";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setWAF(bool $active)
|
public function setWAF(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('waf', [
|
||||||
$object->id = "waf";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAutomatedHTTPSRewrites(bool $active)
|
public function setAutomatedHTTPSRewrites(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('automatic_https_rewrites', [
|
||||||
$object->id = "automatic_https_rewrites";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOpportunisticEncryption(bool $active)
|
public function setOpportunisticEncryption(bool $active)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->addConfigurationOption('opportunistic_encryption', [
|
||||||
$object->id = "opportunistic_encryption";
|
'value' => $this->getBoolAsOnOrOff($active)
|
||||||
$object->value = $active === true ? "on" : "off";
|
]);
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
{
|
{
|
||||||
return $this->configs;
|
return $this->configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addConfigurationOption(string $setting, array $configuration)
|
||||||
|
{
|
||||||
|
$configuration['id'] = $setting;
|
||||||
|
|
||||||
|
array_push($this->configs, $configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBoolAsOnOrOff(bool $value): string
|
||||||
|
{
|
||||||
|
return true === $value ? 'on' : 'off';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,20 +8,21 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class PageRulesTargets implements Configurations
|
class PageRulesTargets implements Configurations
|
||||||
{
|
{
|
||||||
private $targets;
|
private $targets;
|
||||||
|
|
||||||
public function __construct(string $queryUrl)
|
public function __construct(string $queryUrl)
|
||||||
{
|
{
|
||||||
$target = new \stdClass();
|
$this->targets = [
|
||||||
$target->target = 'url';
|
[
|
||||||
$target->constraint = new \stdClass();
|
'target' => 'url',
|
||||||
$target->constraint->operator = "matches";
|
'constraint' => [
|
||||||
$target->constraint->value = $queryUrl;
|
'operator' => 'matches',
|
||||||
|
'value' => $queryUrl
|
||||||
$this->targets = [$target];
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
121
src/Configurations/Pool.php
Normal file
121
src/Configurations/Pool.php
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
class Pool implements Configurations
|
||||||
|
{
|
||||||
|
private $configs = [];
|
||||||
|
|
||||||
|
public function __construct(string $name, array $origins)
|
||||||
|
{
|
||||||
|
$this->setName($name);
|
||||||
|
$this->setOrigins($origins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name)
|
||||||
|
{
|
||||||
|
$this->configs['name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName():string
|
||||||
|
{
|
||||||
|
return $this->configs['name'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOrigins(array $origins)
|
||||||
|
{
|
||||||
|
foreach ($origins as $origin) {
|
||||||
|
if (!isset($origin['name'])) {
|
||||||
|
throw new ConfigurationsException('name is required for origin');
|
||||||
|
}
|
||||||
|
if (!isset($origin['address'])) {
|
||||||
|
throw new ConfigurationsException('address is required for origin');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->configs['origins'] = $origins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrigins():array
|
||||||
|
{
|
||||||
|
return $this->configs['origins'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(string $description = '')
|
||||||
|
{
|
||||||
|
$this->configs['description'] = $description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription():string
|
||||||
|
{
|
||||||
|
return $this->configs['description'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable()
|
||||||
|
{
|
||||||
|
$this->configs['enabled'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDisabled():bool
|
||||||
|
{
|
||||||
|
return !$this->configs['enabled'] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEnabled():bool
|
||||||
|
{
|
||||||
|
return $this->configs['enabled'] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMonitor(string $monitor)
|
||||||
|
{
|
||||||
|
$this->configs['monitor'] = $monitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMonitor():string
|
||||||
|
{
|
||||||
|
return $this->configs['monitor'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCheckRegions(array $checkRegions)
|
||||||
|
{
|
||||||
|
$this->configs['check_regions'] = $checkRegions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCheckRegions():array
|
||||||
|
{
|
||||||
|
return $this->configs['check_regions'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNotificationEmail(string $email)
|
||||||
|
{
|
||||||
|
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
||||||
|
throw new ConfigurationsException('Invalid notification email given');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->configs['notification_email'] = $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNotificationEmail():string
|
||||||
|
{
|
||||||
|
return $this->configs['notification_email'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArray(): array
|
||||||
|
{
|
||||||
|
return $this->configs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,18 +8,13 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class UARules implements Configurations
|
class UARules implements Configurations
|
||||||
{
|
{
|
||||||
private $configs = array();
|
private $configs = [];
|
||||||
|
|
||||||
public function addUA(string $value)
|
public function addUA(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = ['target' => 'ua', 'value' => $value];
|
||||||
$object->target = "ua";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
@@ -8,27 +8,18 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Configurations;
|
namespace Cloudflare\API\Configurations;
|
||||||
|
|
||||||
|
|
||||||
class ZoneLockdown implements Configurations
|
class ZoneLockdown implements Configurations
|
||||||
{
|
{
|
||||||
private $configs = array();
|
private $configs = [];
|
||||||
|
|
||||||
public function addIP(string $value)
|
public function addIP(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = ['target' => 'ip', 'value' => $value];
|
||||||
$object->target = "ip";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addIPRange(string $value)
|
public function addIPRange(string $value)
|
||||||
{
|
{
|
||||||
$object = new \stdClass();
|
$this->configs[] = ['target' => 'ip_range', 'value' => $value];
|
||||||
$object->target = "ip_range";
|
|
||||||
$object->value = $value;
|
|
||||||
|
|
||||||
array_push($this->configs, $object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArray(): array
|
public function getArray(): array
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
interface API
|
interface API
|
||||||
|
|||||||
156
src/Endpoints/AccessRules.php
Normal file
156
src/Endpoints/AccessRules.php
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\Configurations;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class AccessRules implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $scopeType
|
||||||
|
* @param string $mode
|
||||||
|
* @param string $configurationTarget
|
||||||
|
* @param string $configurationValue
|
||||||
|
* @param int $page
|
||||||
|
* @param int $perPage
|
||||||
|
* @param string $order
|
||||||
|
* @param string $direction
|
||||||
|
* @param string $match
|
||||||
|
* @param string $notes
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function listRules(
|
||||||
|
string $zoneID,
|
||||||
|
string $scopeType = '',
|
||||||
|
string $mode = '',
|
||||||
|
string $configurationTarget = '',
|
||||||
|
string $configurationValue = '',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 50,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all',
|
||||||
|
string $notes = ''
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($scopeType)) {
|
||||||
|
$query['scope_type'] = $scopeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($mode)) {
|
||||||
|
$query['mode'] = $mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($configurationTarget)) {
|
||||||
|
$query['configuration_target'] = $configurationTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($configurationValue)) {
|
||||||
|
$query['configuration_value'] = $configurationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($notes)) {
|
||||||
|
$query['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query);
|
||||||
|
$this->body = json_decode($data->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $mode,
|
||||||
|
Configurations $configuration,
|
||||||
|
string $notes = null
|
||||||
|
): bool {
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode,
|
||||||
|
'configuration' => $configuration->getArray()
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($notes !== null) {
|
||||||
|
$options['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
|
string $mode,
|
||||||
|
string $notes = null
|
||||||
|
): bool {
|
||||||
|
$options = [
|
||||||
|
'mode' => $mode
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($notes !== null) {
|
||||||
|
$options['notes'] = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteRule(string $zoneID, string $ruleID, string $cascade = 'none'): bool
|
||||||
|
{
|
||||||
|
$options = [
|
||||||
|
'cascade' => $cascade
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($data->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
95
src/Endpoints/Crypto.php
Normal file
95
src/Endpoints/Crypto.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class Crypto implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Opportunistic Encryption feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getOpportunisticEncryptionSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_encryption'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Onion Routing feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getOnionRoutingSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_onion'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Oppurtunistic Encryption setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateOpportunisticEncryptionSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_encryption',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Onion Routing setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateOnionRoutingSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/opportunistic_onion',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
240
src/Endpoints/CustomHostnames.php
Normal file
240
src/Endpoints/CustomHostnames.php
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 18/03/2018
|
||||||
|
* Time: 21:46
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class CustomHostnames implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostname
|
||||||
|
* @param string $sslMethod
|
||||||
|
* @param string $sslType
|
||||||
|
* @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',
|
||||||
|
array $sslSettings = [],
|
||||||
|
string $customOriginServer = '',
|
||||||
|
bool $wildcard = false,
|
||||||
|
string $bundleMethod = '',
|
||||||
|
array $customSsl = []
|
||||||
|
): \stdClass {
|
||||||
|
$options = [
|
||||||
|
'hostname' => $hostname,
|
||||||
|
'ssl' => [
|
||||||
|
'method' => $sslMethod,
|
||||||
|
'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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostname
|
||||||
|
* @param string $id
|
||||||
|
* @param int $page
|
||||||
|
* @param int $perPage
|
||||||
|
* @param string $order
|
||||||
|
* @param string $direction
|
||||||
|
* @param int $ssl
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function listHostnames(
|
||||||
|
string $zoneID,
|
||||||
|
string $hostname = '',
|
||||||
|
string $hostnameID = '',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
int $ssl = 0
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'ssl' => $ssl
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($hostname)) {
|
||||||
|
$query['hostname'] = $hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($hostnameID)) {
|
||||||
|
$query['id'] = $hostnameID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query);
|
||||||
|
$this->body = json_decode($zone->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostnameID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getHostname(string $zoneID, string $hostnameID)
|
||||||
|
{
|
||||||
|
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
|
||||||
|
$this->body = json_decode($zone->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
* @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 = '',
|
||||||
|
array $sslSettings = [],
|
||||||
|
string $customOriginServer = '',
|
||||||
|
bool $wildcard = null,
|
||||||
|
string $bundleMethod = '',
|
||||||
|
array $customSsl = []
|
||||||
|
): \stdClass {
|
||||||
|
$query = [];
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
if (!empty($sslMethod)) {
|
||||||
|
$query['method'] = $sslMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($sslType)) {
|
||||||
|
$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());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $hostnameID
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
|
||||||
|
{
|
||||||
|
$zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
|
||||||
|
$this->body = json_decode($zone->getBody());
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class DNS implements API
|
class DNS implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -19,14 +22,29 @@ class DNS implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $type
|
||||||
|
* @param string $name
|
||||||
|
* @param string $content
|
||||||
|
* @param int $ttl
|
||||||
|
* @param bool $proxied
|
||||||
|
* @param string $priority
|
||||||
|
* @param array $data
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
public function addRecord(
|
public function addRecord(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $type,
|
string $type,
|
||||||
string $name,
|
string $name,
|
||||||
string $content,
|
string $content,
|
||||||
int $ttl = 0,
|
int $ttl = 0,
|
||||||
bool $proxied = true
|
bool $proxied = true,
|
||||||
): bool {
|
string $priority = '',
|
||||||
|
array $data = []
|
||||||
|
): \stdClass {
|
||||||
$options = [
|
$options = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
@@ -38,90 +56,112 @@ class DNS implements API
|
|||||||
$options['ttl'] = $ttl;
|
$options['ttl'] = $ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options);
|
if (is_numeric($priority)) {
|
||||||
|
$options['priority'] = (int)$priority;
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if (!empty($data)) {
|
||||||
|
$options['data'] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
$result = $this->body->result;
|
||||||
|
|
||||||
|
if( !( $result instanceof \stdClass ) ) {
|
||||||
|
$errorMessage = '';
|
||||||
|
|
||||||
|
if( is_array( $result ) ) {
|
||||||
|
$errorMessage.= implode( $result );
|
||||||
|
|
||||||
|
} elseif( is_string( $result ) ) {
|
||||||
|
$errorMessage.= $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new EndpointException( sprintf( 'Unexpected add record result. %s', $errorMessage ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listRecords(
|
public function listRecords(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $type = "",
|
string $type = '',
|
||||||
string $name = "",
|
string $name = '',
|
||||||
string $content = "",
|
string $content = '',
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$options = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'per_page' => $perPage,
|
'per_page' => $perPage,
|
||||||
'match' => $match
|
'match' => $match
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($type)) {
|
if (!empty($type)) {
|
||||||
$options['type'] = $type;
|
$query['type'] = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
$options['name'] = $name;
|
$query['name'] = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($content)) {
|
if (!empty($content)) {
|
||||||
$options['content'] = $content;
|
$query['content'] = $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($order)) {
|
if (!empty($order)) {
|
||||||
$options['order'] = $order;
|
$query['order'] = $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($direction)) {
|
if (!empty($direction)) {
|
||||||
$options['direction'] = $direction;
|
$query['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = http_build_query($options);
|
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records?' . $query, []);
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
$result = new \stdClass();
|
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
|
||||||
|
{
|
||||||
|
$records = $this->listRecords($zoneID, $type, $name);
|
||||||
|
if (isset($records->result[0]->id)) {
|
||||||
|
return $records->result[0]->id;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
|
||||||
{
|
{
|
||||||
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
|
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
|
||||||
return json_decode($response->getBody());
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteRecord(string $zoneID, string $recordID): bool
|
public function deleteRecord(string $zoneID, string $recordID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
|
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
class EndpointException extends \Exception
|
class EndpointException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
135
src/Endpoints/FirewallSettings.php
Normal file
135
src/Endpoints/FirewallSettings.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class FirewallSettings implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Security Level feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getSecurityLevelSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/security_level'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Challenge TTL feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return integer|false
|
||||||
|
*/
|
||||||
|
public function getChallengeTTLSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/challenge_ttl'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Browser Integrity Check feature for a zone.
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getBrowserIntegrityCheckSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/browser_check'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Security Level setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateSecurityLevelSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/security_level',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Challenge TTL setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param int $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateChallengeTTLSetting(string $zoneID, int $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/challenge_ttl',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Browser Integrity Check setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateBrowserIntegrityCheckSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/browser_check',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,13 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class IPs implements API
|
class IPs implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -20,10 +22,11 @@ class IPs implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listIPs(): \stdClass {
|
public function listIPs(): \stdClass
|
||||||
$ips = $this->adapter->get('ips', []);
|
{
|
||||||
$body = json_decode($ips->getBody());
|
$ips = $this->adapter->get('ips');
|
||||||
|
$this->body = json_decode($ips->getBody());
|
||||||
|
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
157
src/Endpoints/LoadBalancers.php
Normal file
157
src/Endpoints/LoadBalancers.php
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\LoadBalancer;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class LoadBalancers implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function listLoadBalancers(string $zoneID)
|
||||||
|
{
|
||||||
|
$loadBalancers = $this->adapter->get('zones/' . $zoneID . '/load_balancers');
|
||||||
|
$this->body = json_decode($loadBalancers->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getLoadBalancerDetails(string $zoneID, string $loadBalancerID)
|
||||||
|
{
|
||||||
|
$loadBalancer = $this->adapter->get('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID);
|
||||||
|
$this->body = json_decode($loadBalancer->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @return LoadBalancer
|
||||||
|
* @throws ConfigurationsException
|
||||||
|
*/
|
||||||
|
public function getLoadBalancerConfiguration(string $zoneID, string $loadBalancerID)
|
||||||
|
{
|
||||||
|
$loadBalancer = $this->getLoadBalancerDetails($zoneID, $loadBalancerID);
|
||||||
|
|
||||||
|
$lbConfiguration = new LoadBalancer($loadBalancer->name, $loadBalancer->default_pools, $loadBalancer->fallback_pool);
|
||||||
|
$lbConfiguration->setSteeringPolicy($loadBalancer->steering_policy);
|
||||||
|
if ($loadBalancer->enabled === true) {
|
||||||
|
$lbConfiguration->enable();
|
||||||
|
} elseif ($loadBalancer->enabled === false) {
|
||||||
|
$lbConfiguration->disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($loadBalancer->pop_pools)) {
|
||||||
|
$lbConfiguration->setPopPools($loadBalancer->pop_pools);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($loadBalancer->ttl)) {
|
||||||
|
$lbConfiguration->setTtl($loadBalancer->ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($loadBalancer->region_pools)) {
|
||||||
|
$lbConfiguration->setRegionPools($loadBalancer->region_pools);
|
||||||
|
}
|
||||||
|
$lbConfiguration->setSessionAffinity($loadBalancer->session_affinity);
|
||||||
|
$lbConfiguration->setDescription($loadBalancer->description);
|
||||||
|
if ($loadBalancer->proxied === true) {
|
||||||
|
$lbConfiguration->enableProxied();
|
||||||
|
} elseif ($loadBalancer->proxied === false) {
|
||||||
|
$lbConfiguration->disableProxied();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($loadBalancer->session_affinity_ttl)) {
|
||||||
|
$lbConfiguration->setSessionAffinityTtl($loadBalancer->session_affinity_ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lbConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @param LoadBalancer $lbConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateLoadBalancer(
|
||||||
|
string $zoneID,
|
||||||
|
string $loadBalancerID,
|
||||||
|
LoadBalancer $lbConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $lbConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->put('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param LoadBalancer $lbConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function createLoadBalancer(
|
||||||
|
string $zoneID,
|
||||||
|
LoadBalancer $lbConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $lbConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->post('zones/' . $zoneID . '/load_balancers', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $loadBalancerID
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deleteLoadBalancer(string $zoneID, string $loadBalancerID): bool
|
||||||
|
{
|
||||||
|
$loadBalancer = $this->adapter->delete('zones/' . $zoneID . '/load_balancers/' . $loadBalancerID);
|
||||||
|
|
||||||
|
$this->body = json_decode($loadBalancer->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/Endpoints/Membership.php
Normal file
83
src/Endpoints/Membership.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
/* A list of memberships of accounts this user can access */
|
||||||
|
|
||||||
|
class Membership implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function listMemberships(
|
||||||
|
string $name = '',
|
||||||
|
string $status = '',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = ''
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($name)) {
|
||||||
|
$query['account.name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($status) && in_array($status, ['accepted', 'pending', 'rejected'], true)) {
|
||||||
|
$query['status'] = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($order) && in_array($order, ['id', 'account.name', 'status'], true)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction) && in_array($direction, ['asc', 'desc'], true)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$memberships = $this->adapter->get('memberships', $query);
|
||||||
|
$this->body = json_decode($memberships->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMembershipDetails(string $membershipId): \stdClass
|
||||||
|
{
|
||||||
|
$membership = $this->adapter->get(sprintf('memberships/%s', $membershipId));
|
||||||
|
$this->body = json_decode($membership->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateMembershipStatus(string $membershipId, string $status): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->put(sprintf('memberships/%s', $membershipId), ['status' => $status]);
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteMembership(string $membershipId): bool
|
||||||
|
{
|
||||||
|
$response = $this->adapter->delete(sprintf('memberships/%s', $membershipId));
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,13 +8,15 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
use Cloudflare\API\Configurations\PageRulesActions;
|
use Cloudflare\API\Configurations\PageRulesActions;
|
||||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class PageRules implements API
|
class PageRules implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -22,6 +24,16 @@ class PageRules implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param PageRulesTargets $target
|
||||||
|
* @param PageRulesActions $actions
|
||||||
|
* @param bool $active
|
||||||
|
* @param int|null $priority
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function createPageRule(
|
public function createPageRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
PageRulesTargets $target,
|
PageRulesTargets $target,
|
||||||
@@ -35,7 +47,7 @@ class PageRules implements API
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($active !== null) {
|
if ($active !== null) {
|
||||||
$options['active'] = $active == true ? 'active' : 'disabled';
|
$options['status'] = $active == true ? 'active' : 'disabled';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($priority !== null) {
|
if ($priority !== null) {
|
||||||
@@ -43,11 +55,11 @@ class PageRules implements API
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', [], $options);
|
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', $options);
|
||||||
|
|
||||||
$body = json_decode($query->getBody());
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,51 +72,77 @@ class PageRules implements API
|
|||||||
string $order = null,
|
string $order = null,
|
||||||
string $direction = null,
|
string $direction = null,
|
||||||
string $match = null
|
string $match = null
|
||||||
): \stdClass {
|
): array {
|
||||||
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
|
if ($status != null && !in_array($status, ['active', 'disabled'])) {
|
||||||
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
|
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($order) && !in_array($order, ['status', 'priority'])) {
|
if ($order != null && !in_array($order, ['status', 'priority'])) {
|
||||||
throw new EndpointException('Page Rules can only be ordered by status or priority.');
|
throw new EndpointException('Page Rules can only be ordered by status or priority.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) {
|
if ($direction != null && !in_array($direction, ['asc', 'desc'])) {
|
||||||
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
|
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($match) && !in_array($match, ['all', 'any'])) {
|
if ($match != null && !in_array($match, ['all', 'any'])) {
|
||||||
throw new EndpointException('Match can only be any or all.');
|
throw new EndpointException('Match can only be any or all.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = [
|
$query = [
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'order' => $order,
|
'order' => $order,
|
||||||
'direction' => $direction,
|
'direction' => $direction,
|
||||||
'match' => $match
|
'match' => $match
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = http_build_query($options);
|
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules?' . $query, []);
|
return $this->body->result;
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
$result = new \stdClass();
|
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
|
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function 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(
|
public function updatePageRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
|
string $ruleID,
|
||||||
PageRulesTargets $target = null,
|
PageRulesTargets $target = null,
|
||||||
PageRulesActions $actions = null,
|
PageRulesActions $actions = null,
|
||||||
bool $active = null,
|
bool $active = null,
|
||||||
@@ -112,7 +150,7 @@ class PageRules implements API
|
|||||||
): bool {
|
): bool {
|
||||||
$options = [];
|
$options = [];
|
||||||
|
|
||||||
if ($active !== null) {
|
if ($target !== null) {
|
||||||
$options['targets'] = $target->getArray();
|
$options['targets'] = $target->getArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,19 +159,18 @@ class PageRules implements API
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($active !== null) {
|
if ($active !== null) {
|
||||||
$options['active'] = $active == true ? 'active' : 'disabled';
|
$options['status'] = $active == true ? 'active' : 'disabled';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($priority !== null) {
|
if ($priority !== null) {
|
||||||
$options['priority'] = $priority;
|
$options['priority'] = $priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules/' . $ruleID, $options);
|
||||||
|
|
||||||
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', [], $options);
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
$body = json_decode($query->getBody());
|
if (isset($this->body->result->id)) {
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,11 +179,11 @@ class PageRules implements API
|
|||||||
|
|
||||||
public function deletePageRule(string $zoneID, string $ruleID): bool
|
public function deletePageRule(string $zoneID, string $ruleID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
|
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
156
src/Endpoints/Pools.php
Normal file
156
src/Endpoints/Pools.php
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\Pool;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class Pools implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function listPools(string $accountID)
|
||||||
|
{
|
||||||
|
$pools = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools');
|
||||||
|
$this->body = json_decode($pools->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getPoolDetails(string $accountID, string $poolID)
|
||||||
|
{
|
||||||
|
$pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID);
|
||||||
|
$this->body = json_decode($pool->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getPoolHealthDetails(string $accountID, string $poolID)
|
||||||
|
{
|
||||||
|
$pool = $this->adapter->get('accounts/' . $accountID . '/load_balancers/pools/' . $poolID . '/health');
|
||||||
|
$this->body = json_decode($pool->getBody());
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return Pool
|
||||||
|
* @throws ConfigurationsException
|
||||||
|
*/
|
||||||
|
public function getPoolConfiguration(string $accountID, string $poolID)
|
||||||
|
{
|
||||||
|
$pool = $this->getPoolDetails($accountID, $poolID);
|
||||||
|
|
||||||
|
$origins = [];
|
||||||
|
foreach ($pool->origins as $origin) {
|
||||||
|
$origins[] = (array)$origin;
|
||||||
|
}
|
||||||
|
$poolConfiguration = new Pool($pool->name, $origins);
|
||||||
|
$poolConfiguration->setDescription($pool->description);
|
||||||
|
if ($pool->enabled === true) {
|
||||||
|
$poolConfiguration->enable();
|
||||||
|
} elseif ($pool->enabled === false) {
|
||||||
|
$poolConfiguration->disable();
|
||||||
|
}
|
||||||
|
$poolConfiguration->setMonitor($pool->monitor);
|
||||||
|
$poolConfiguration->setNotificationEmail($pool->notification_email);
|
||||||
|
|
||||||
|
if (is_array($pool->check_regions)) {
|
||||||
|
$poolConfiguration->setCheckRegions($pool->check_regions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $poolConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @param Pool $poolConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updatePool(
|
||||||
|
string $accountID,
|
||||||
|
string $poolID,
|
||||||
|
Pool $poolConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $poolConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->put('accounts/' . $accountID . '/load_balancers/pools/' . $poolID, $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param Pool $poolConfiguration
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function createPool(
|
||||||
|
string $accountID,
|
||||||
|
Pool $poolConfiguration
|
||||||
|
): bool {
|
||||||
|
$options = $poolConfiguration->getArray();
|
||||||
|
|
||||||
|
$query = $this->adapter->post('accounts/' . $accountID . '/load_balancers/pools', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($query->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $accountID
|
||||||
|
* @param string $poolID
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deletePool(string $accountID, string $poolID): bool
|
||||||
|
{
|
||||||
|
$pool = $this->adapter->delete('accounts/' . $accountID . '/load_balancers/pools/' . $poolID);
|
||||||
|
|
||||||
|
$this->body = json_decode($pool->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
102
src/Endpoints/Railgun.php
Normal file
102
src/Endpoints/Railgun.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 11:15
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class Railgun implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(
|
||||||
|
string $name
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'name' => $name,
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->post('railguns', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(
|
||||||
|
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('railguns', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(
|
||||||
|
string $railgunID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('railguns/' . $railgunID);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getZones(
|
||||||
|
string $railgunID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('railguns/' . $railgunID . '/zones');
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(
|
||||||
|
string $railgunID,
|
||||||
|
bool $status
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'enabled' => $status
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->patch('railguns/' . $railgunID, $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(
|
||||||
|
string $railgunID
|
||||||
|
): bool {
|
||||||
|
$user = $this->adapter->delete('railguns/' . $railgunID);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
183
src/Endpoints/SSL.php
Normal file
183
src/Endpoints/SSL.php
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class SSL implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SSL setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getSSLSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/ssl'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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, bool $retry = false)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/ssl/verification',
|
||||||
|
[
|
||||||
|
'retry' => $retry
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the HTTPS Redirect setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getHTTPSRedirectSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/always_use_https'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the HTTPS Rewrite setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getHTTPSRewritesSetting(string $zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/automatic_https_rewrites'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the SSL setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateSSLSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/ssl',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the HTTPS Redirect setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateHTTPSRedirectSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/always_use_https',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the HTTPS Rewrite setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateHTTPSRewritesSetting(string $zoneID, string $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/automatic_https_rewrites',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
121
src/Endpoints/TLS.php
Normal file
121
src/Endpoints/TLS.php
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Jurgen Coetsiers
|
||||||
|
* Date: 21/10/2018
|
||||||
|
* Time: 09:10
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
|
||||||
|
class TLS implements API
|
||||||
|
{
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the TLS Client Auth setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public function getTLSClientAuth($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_client_auth'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->result)) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable TLS 1.3 for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function enableTLS13($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_1_3',
|
||||||
|
['value' => 'on']
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable TLS 1.3 for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function disableTLS13($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_1_3',
|
||||||
|
['value' => 'off']
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the minimum TLS version setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $minimumVersion The version to update to
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function changeMinimumTLSVersion($zoneID, $minimumVersion)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/min_tls_version',
|
||||||
|
[
|
||||||
|
'value' => $minimumVersion,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the TLS Client Auth setting for the zone
|
||||||
|
*
|
||||||
|
* @param string $zoneID The ID of the zone
|
||||||
|
* @param string $value The value of the zone setting
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateTLSClientAuth($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/tls_client_auth',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
if (isset($body->success) && $body->success == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,10 +8,14 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\Configurations;
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class UARules implements API
|
class UARules implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -24,49 +28,42 @@ class UARules implements API
|
|||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20
|
int $perPage = 20
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$options = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'per_page' => $perPage
|
'per_page' => $perPage
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = http_build_query($options);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules?' . $query, []);
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
$result = new \stdClass();
|
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createRule(
|
public function createRule(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
string $mode,
|
string $mode,
|
||||||
\Cloudflare\API\Configurations\Configurations $configuration,
|
Configurations $configuration,
|
||||||
string $id = null,
|
string $ruleID = null,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'configurations' => $configuration->getArray()
|
'configurations' => $configuration->getArray()
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($id !== null) {
|
if ($ruleID !== null) {
|
||||||
$options['id'] = $id;
|
$options['id'] = $ruleID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($description !== null) {
|
if ($description !== null) {
|
||||||
$options['description'] = $description;
|
$options['description'] = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', [], $options);
|
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', $options);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,9 +72,9 @@ class UARules implements API
|
|||||||
|
|
||||||
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateRule(
|
public function updateRule(
|
||||||
@@ -87,7 +84,6 @@ class UARules implements API
|
|||||||
\Cloudflare\API\Configurations\UARules $configuration,
|
\Cloudflare\API\Configurations\UARules $configuration,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
'id' => $ruleID,
|
'id' => $ruleID,
|
||||||
@@ -98,11 +94,11 @@ class UARules implements API
|
|||||||
$options['description'] = $description;
|
$options['description'] = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], $options);
|
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, $options);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,11 +107,11 @@ class UARules implements API
|
|||||||
|
|
||||||
public function deleteRule(string $zoneID, string $ruleID): bool
|
public function deleteRule(string $zoneID, string $ruleID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], []);
|
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,13 @@
|
|||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class User implements API
|
class User implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -21,24 +23,25 @@ class User implements API
|
|||||||
|
|
||||||
public function getUserDetails(): \stdClass
|
public function getUserDetails(): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('user', []);
|
$user = $this->adapter->get('user');
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserID(): string
|
public function getUserID(): string
|
||||||
{
|
{
|
||||||
return ($this->getUserDetails())->id;
|
return $this->getUserDetails()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserEmail(): string
|
public function getUserEmail(): string
|
||||||
{
|
{
|
||||||
return ($this->getUserDetails())->email;
|
return $this->getUserDetails()->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateUserDetails(array $details): \stdClass
|
public function updateUserDetails(array $details): \stdClass
|
||||||
{
|
{
|
||||||
$response = $this->adapter->patch("user", [], $details);
|
$response = $this->adapter->patch('user', $details);
|
||||||
return json_decode($response->getBody());
|
$this->body = json_decode($response->getBody());
|
||||||
|
return $this->body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
183
src/Endpoints/WAF.php
Normal file
183
src/Endpoints/WAF.php
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 11:17
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
|
class WAF implements API
|
||||||
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
public function __construct(Adapter $adapter)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPackages(
|
||||||
|
string $zoneID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all'
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getPackageInfo(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRules(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all'
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRuleInfo(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $ruleID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRule(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $ruleID,
|
||||||
|
string $status
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'mode' => $status,
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroups(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 20,
|
||||||
|
string $order = '',
|
||||||
|
string $direction = '',
|
||||||
|
string $match = 'all'
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'page' => $page,
|
||||||
|
'per_page' => $perPage,
|
||||||
|
'match' => $match
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($order)) {
|
||||||
|
$query['order'] = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($direction)) {
|
||||||
|
$query['direction'] = $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroupInfo(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $groupID
|
||||||
|
): \stdClass {
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateGroup(
|
||||||
|
string $zoneID,
|
||||||
|
string $packageID,
|
||||||
|
string $groupID,
|
||||||
|
string $status
|
||||||
|
): \stdClass {
|
||||||
|
$query = [
|
||||||
|
'mode' => $status
|
||||||
|
];
|
||||||
|
|
||||||
|
$user = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return $this->body->result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class ZoneLockdown implements API
|
class ZoneLockdown implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -24,49 +27,42 @@ class ZoneLockdown implements API
|
|||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20
|
int $perPage = 20
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$options = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'per_page' => $perPage
|
'per_page' => $perPage
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = http_build_query($options);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns?' . $query, []);
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
$result = new \stdClass();
|
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createLockdown(
|
public function createLockdown(
|
||||||
string $zoneID,
|
string $zoneID,
|
||||||
array $urls,
|
array $urls,
|
||||||
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||||
string $id = null,
|
string $lockdownID = null,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'urls' => $urls,
|
'urls' => $urls,
|
||||||
'configurations' => $configuration->getArray()
|
'configurations' => $configuration->getArray()
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($id !== null) {
|
if ($lockdownID !== null) {
|
||||||
$options['id'] = $id;
|
$options['id'] = $lockdownID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($description !== null) {
|
if ($description !== null) {
|
||||||
$options['description'] = $description;
|
$options['description'] = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', [], $options);
|
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', $options);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,9 +71,9 @@ class ZoneLockdown implements API
|
|||||||
|
|
||||||
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
|
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
|
||||||
{
|
{
|
||||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, []);
|
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateLockdown(
|
public function updateLockdown(
|
||||||
@@ -87,7 +83,6 @@ class ZoneLockdown implements API
|
|||||||
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||||
string $description = null
|
string $description = null
|
||||||
): bool {
|
): bool {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'urls' => $urls,
|
'urls' => $urls,
|
||||||
'id' => $lockdownID,
|
'id' => $lockdownID,
|
||||||
@@ -98,11 +93,11 @@ class ZoneLockdown implements API
|
|||||||
$options['description'] = $description;
|
$options['description'] = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], $options);
|
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, $options);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,11 +106,11 @@ class ZoneLockdown implements API
|
|||||||
|
|
||||||
public function deleteLockdown(string $zoneID, string $lockdownID): bool
|
public function deleteLockdown(string $zoneID, string $lockdownID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
|
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
245
src/Endpoints/ZoneSettings.php
Normal file
245
src/Endpoints/ZoneSettings.php
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: paul.adams
|
||||||
|
* Date: 2019-02-22
|
||||||
|
* Time: 23:28
|
||||||
|
*/
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinifySetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/minify'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRocketLoaderSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/rocket_loader'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAlwaysOnlineSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/always_online'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmailObfuscationSetting($zoneID)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->get(
|
||||||
|
'zones/' . $zoneID . '/settings/email_obfuscation'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function 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(
|
||||||
|
'zones/' . $zoneID . '/settings/hotlink_protection'
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return $body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
|
'zones/' . $zoneID . '/settings/minify',
|
||||||
|
[
|
||||||
|
'value' => [
|
||||||
|
'html' => $html,
|
||||||
|
'css' => $css,
|
||||||
|
'js' => $javascript,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRocketLoaderSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/rocket_loader',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAlwaysOnlineSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/always_online',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateEmailObfuscationSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/email_obfuscation',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateHotlinkProtectionSetting($zoneID, $value)
|
||||||
|
{
|
||||||
|
$return = $this->adapter->patch(
|
||||||
|
'zones/' . $zoneID . '/settings/hotlink_protection',
|
||||||
|
[
|
||||||
|
'value' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$body = json_decode($return->getBody());
|
||||||
|
|
||||||
|
if ($body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,12 @@
|
|||||||
namespace Cloudflare\API\Endpoints;
|
namespace Cloudflare\API\Endpoints;
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Traits\BodyAccessorTrait;
|
||||||
|
|
||||||
class Zones implements API
|
class Zones implements API
|
||||||
{
|
{
|
||||||
|
use BodyAccessorTrait;
|
||||||
|
|
||||||
private $adapter;
|
private $adapter;
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
public function __construct(Adapter $adapter)
|
||||||
@@ -19,90 +22,196 @@ class Zones implements API
|
|||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param bool $jumpStart
|
||||||
|
* @param string $accountId
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function addZone(string $name, bool $jumpStart = false, string $accountId = ''): \stdClass
|
||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'jumpstart' => $jumpstart
|
'jump_start' => $jumpStart
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($organizationID)) {
|
if (!empty($accountId)) {
|
||||||
$organization = new \stdClass();
|
$options['account'] = [
|
||||||
$organization->id = $organizationID;
|
'id' => $accountId,
|
||||||
$options["organization"] = $organization;
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones', [], $options);
|
$user = $this->adapter->post('zones', $options);
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
return $body->result;
|
return $this->body->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function activationCheck(string $zoneID): bool
|
public function activationCheck(string $zoneID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []);
|
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check');
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function 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 {
|
||||||
|
$user = $this->adapter->get('zones/' . $zoneId);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
return (object)['result' => $this->body->result];
|
||||||
|
}
|
||||||
|
|
||||||
public function listZones(
|
public function listZones(
|
||||||
string $name = "",
|
string $name = '',
|
||||||
string $status = "",
|
string $status = '',
|
||||||
int $page = 1,
|
int $page = 1,
|
||||||
int $perPage = 20,
|
int $perPage = 20,
|
||||||
string $order = "",
|
string $order = '',
|
||||||
string $direction = "",
|
string $direction = '',
|
||||||
string $match = "all"
|
string $match = 'all'
|
||||||
): \stdClass {
|
): \stdClass {
|
||||||
$options = [
|
$query = [
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'per_page' => $perPage,
|
'per_page' => $perPage,
|
||||||
'match' => $match
|
'match' => $match
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
$options['name'] = $name;
|
$query['name'] = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($status)) {
|
if (!empty($status)) {
|
||||||
$options['status'] = $status;
|
$query['status'] = $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($order)) {
|
if (!empty($order)) {
|
||||||
$options['order'] = $order;
|
$query['order'] = $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($direction)) {
|
if (!empty($direction)) {
|
||||||
$options['direction'] = $direction;
|
$query['direction'] = $direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = http_build_query($options);
|
$user = $this->adapter->get('zones', $query);
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
$user = $this->adapter->get('zones?' . $query, []);
|
return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info];
|
||||||
$body = json_decode($user->getBody());
|
|
||||||
|
|
||||||
$result = new \stdClass();
|
|
||||||
$result->result = $body->result;
|
|
||||||
$result->result_info = $body->result_info;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getZoneID(string $name = ""): string
|
public function getZoneID(string $name = ''): string
|
||||||
{
|
{
|
||||||
$zones = $this->listZones($name);
|
$zones = $this->listZones($name);
|
||||||
|
|
||||||
if (sizeof($zones) < 1) {
|
if (count($zones->result) < 1) {
|
||||||
throw new EndpointException("Could not find zones with specified name.");
|
throw new EndpointException('Could not find zones with specified name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $zones->result[0]->id;
|
return $zones->result[0]->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $since
|
||||||
|
* @param string $until
|
||||||
|
* @param bool $continuous
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', string $until = '0', bool $continuous = true): \stdClass
|
||||||
|
{
|
||||||
|
$response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)]);
|
||||||
|
|
||||||
|
$this->body = $response->getBody();
|
||||||
|
|
||||||
|
return json_decode($this->body)->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
||||||
|
*
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param bool $enable
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
|
||||||
|
{
|
||||||
|
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', ['value' => $enable ? 'on' : 'off']);
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
if ($this->body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return caching level settings
|
||||||
|
* @param string $zoneID
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCachingLevel(string $zoneID): string
|
||||||
|
{
|
||||||
|
$response = $this->adapter->get('zones/' . $zoneID . '/settings/cache_level');
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
return $this->body->result->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change caching level settings
|
||||||
|
* @param string $zoneID
|
||||||
|
* @param string $level (aggressive | basic | simplified)
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setCachingLevel(string $zoneID, string $level = 'aggressive'): bool
|
||||||
|
{
|
||||||
|
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/cache_level', ['value' => $level]);
|
||||||
|
|
||||||
|
$this->body = json_decode($response->getBody());
|
||||||
|
|
||||||
|
if ($this->body->success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge Everything
|
* Purge Everything
|
||||||
* @param string $zoneID
|
* @param string $zoneID
|
||||||
@@ -110,33 +219,55 @@ class Zones implements API
|
|||||||
*/
|
*/
|
||||||
public function cachePurgeEverything(string $zoneID): bool
|
public function cachePurgeEverything(string $zoneID): bool
|
||||||
{
|
{
|
||||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
|
$user = $this->adapter->post('zones/' . $zoneID . '/purge_cache', ['purge_everything' => true]);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
if (isset($this->body->result->id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cachePurge(string $zoneID, array $files = [], array $tags = []): bool
|
public function cachePurge(string $zoneID, array $files = null, array $tags = null, array $hosts = null): bool
|
||||||
{
|
{
|
||||||
if (empty($files) && empty($tags)) {
|
if ($files === null && $tags === null && $hosts === null) {
|
||||||
throw new EndpointException("No files or tags to purge.");
|
throw new EndpointException('No files, tags or hosts to purge.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = [
|
$options = [];
|
||||||
'files' => $files,
|
if (!is_null($files)) {
|
||||||
'tags' => $tags
|
$options['files'] = $files;
|
||||||
];
|
}
|
||||||
|
|
||||||
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], $options);
|
if (!is_null($tags)) {
|
||||||
|
$options['tags'] = $tags;
|
||||||
|
}
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
if (!is_null($hosts)) {
|
||||||
|
$options['hosts'] = $hosts;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($body->result->id)) {
|
$user = $this->adapter->post('zones/' . $zoneID . '/purge_cache', $options);
|
||||||
|
|
||||||
|
$this->body = json_decode($user->getBody());
|
||||||
|
|
||||||
|
if (isset($this->body->result->id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/Traits/BodyAccessorTrait.php
Normal file
13
src/Traits/BodyAccessorTrait.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Cloudflare\API\Traits;
|
||||||
|
|
||||||
|
trait BodyAccessorTrait
|
||||||
|
{
|
||||||
|
private $body;
|
||||||
|
|
||||||
|
public function getBody()
|
||||||
|
{
|
||||||
|
return $this->body;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
use Cloudflare\API\Adapter\ResponseException;
|
||||||
* User: junade
|
|
||||||
* Date: 13/01/2017
|
|
||||||
* Time: 23:35
|
|
||||||
*/
|
|
||||||
|
|
||||||
use GuzzleHttp\Psr7\Response;
|
class GuzzleTest extends TestCase
|
||||||
|
|
||||||
class GuzzleTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
@@ -29,104 +23,75 @@ class GuzzleTest extends PHPUnit_Framework_TestCase
|
|||||||
$response = $this->client->get('https://httpbin.org/get');
|
$response = $this->client->get('https://httpbin.org/get');
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Test", $body->headers->{"X-Testing"});
|
$this->assertEquals('Test', $body->headers->{'X-Testing'});
|
||||||
|
|
||||||
$response = $this->client->get('https://httpbin.org/get', ['X-Another-Test' => 'Test2']);
|
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
|
$this->assertEquals('Test2', $body->headers->{'X-Another-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPost()
|
public function testPost()
|
||||||
{
|
{
|
||||||
$response = $this->client->post('https://httpbin.org/post', [], ['X-Post-Test' => 'Testing a POST request.']);
|
$response = $this->client->post('https://httpbin.org/post', ['X-Post-Test' => 'Testing a POST request.']);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a POST request.", $body->json->{"X-Post-Test"});
|
$this->assertEquals('Testing a POST request.', $body->json->{'X-Post-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPut()
|
public function testPut()
|
||||||
{
|
{
|
||||||
$response = $this->client->put('https://httpbin.org/put', [], ['X-Put-Test' => 'Testing a PUT request.']);
|
$response = $this->client->put('https://httpbin.org/put', ['X-Put-Test' => 'Testing a PUT request.']);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a PUT request.", json_decode($body->json)->{"X-Put-Test"});
|
$this->assertEquals('Testing a PUT request.', $body->json->{'X-Put-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPatch()
|
public function testPatch()
|
||||||
{
|
{
|
||||||
$response = $this->client->patch('https://httpbin.org/patch', [],
|
$response = $this->client->patch(
|
||||||
['X-Patch-Test' => 'Testing a PATCH request.']);
|
'https://httpbin.org/patch',
|
||||||
|
['X-Patch-Test' => 'Testing a PATCH request.']
|
||||||
|
);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a PATCH request.", json_decode($body->json)->{"X-Patch-Test"});
|
$this->assertEquals('Testing a PATCH request.', $body->json->{'X-Patch-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
$response = $this->client->delete('https://httpbin.org/delete', [],
|
$response = $this->client->delete(
|
||||||
['X-Delete-Test' => 'Testing a DELETE request.']);
|
'https://httpbin.org/delete',
|
||||||
|
['X-Delete-Test' => 'Testing a DELETE request.']
|
||||||
|
);
|
||||||
|
|
||||||
$headers = $response->getHeaders();
|
$headers = $response->getHeaders();
|
||||||
$this->assertEquals("application/json", $headers["Content-Type"][0]);
|
$this->assertEquals('application/json', $headers['Content-Type'][0]);
|
||||||
|
|
||||||
$body = json_decode($response->getBody());
|
$body = json_decode($response->getBody());
|
||||||
$this->assertEquals("Testing a DELETE request.", $body->json->{"X-Delete-Test"});
|
$this->assertEquals('Testing a DELETE request.', $body->json->{'X-Delete-Test'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testErrors()
|
public function testNotFound()
|
||||||
{
|
{
|
||||||
$class = new ReflectionClass(\Cloudflare\API\Adapter\Guzzle::class);
|
$this->expectException(ResponseException::class);
|
||||||
$method = $class->getMethod('checkError');
|
$this->client->get('https://httpbin.org/status/404');
|
||||||
$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() {
|
public function testServerError()
|
||||||
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
|
{
|
||||||
$response = $this->client->get('https://httpbin.org/status/404');
|
$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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
* Date: 13/01/2017
|
* Date: 13/01/2017
|
||||||
* Time: 17:15
|
* Time: 17:15
|
||||||
*/
|
*/
|
||||||
class APIKeyTest extends PHPUnit_Framework_TestCase
|
class APIKeyTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
@@ -18,7 +18,6 @@ class APIKeyTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
|
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
|
||||||
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
|
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
|
||||||
|
|
||||||
$this->assertEquals(2, sizeof($headers));
|
$this->assertCount(2, $headers);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,7 @@
|
|||||||
* Time: 20:08
|
* Time: 20:08
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Auth\None;
|
class NoneTest extends TestCase
|
||||||
|
|
||||||
class NoneTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,19 +5,20 @@
|
|||||||
* Date: 13/01/2017
|
* Date: 13/01/2017
|
||||||
* Time: 18:03
|
* Time: 18:03
|
||||||
*/
|
*/
|
||||||
class UserServiceKeyTest extends PHPUnit_Framework_TestCase
|
class UserServiceKeyTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetHeaders()
|
public function testGetHeaders()
|
||||||
{
|
{
|
||||||
$auth = new \Cloudflare\API\Auth\UserServiceKey("v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a");
|
$auth = new \Cloudflare\API\Auth\UserServiceKey('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a');
|
||||||
$headers = $auth->getHeaders();
|
$headers = $auth->getHeaders();
|
||||||
|
|
||||||
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
|
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
|
||||||
|
|
||||||
$this->assertEquals('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
|
$this->assertEquals(
|
||||||
$headers['X-Auth-User-Service-Key']);
|
'v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a',
|
||||||
|
$headers['X-Auth-User-Service-Key']
|
||||||
$this->assertEquals(1, sizeof($headers));
|
);
|
||||||
|
|
||||||
|
$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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* Date: 19/09/2017
|
* Date: 19/09/2017
|
||||||
* Time: 15:24
|
* Time: 15:24
|
||||||
*/
|
*/
|
||||||
class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
|
class ConfigurationsUARulesTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetArray()
|
public function testGetArray()
|
||||||
{
|
{
|
||||||
@@ -14,12 +14,14 @@ class ConfigurationsUARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
$configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
$configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
||||||
|
|
||||||
$array = $configuration->getArray();
|
$array = $configuration->getArray();
|
||||||
$this->assertEquals(1, sizeof($array));
|
$this->assertCount(1, $array);
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('target', $array[0]);
|
$this->assertArrayHasKey('target', $array[0]);
|
||||||
$this->assertEquals('ua', $array[0]->target);
|
$this->assertEquals('ua', $array[0]['target']);
|
||||||
$this->assertObjectHasAttribute('value', $array[0]);
|
$this->assertArrayHasKey('value', $array[0]);
|
||||||
$this->assertEquals('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
|
$this->assertEquals(
|
||||||
$array[0]->value);
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
|
||||||
|
$array[0]['value']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
tests/Configurations/ConfigurationsZoneLockdownTest.php
Normal file
34
tests/Configurations/ConfigurationsZoneLockdownTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 05/09/2017
|
||||||
|
* Time: 13:50
|
||||||
|
*/
|
||||||
|
class ConfigurationsZoneLockdownTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetArray()
|
||||||
|
{
|
||||||
|
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
|
||||||
|
$configuration->addIP('1.2.3.4');
|
||||||
|
|
||||||
|
$array = $configuration->getArray();
|
||||||
|
$this->assertCount(1, $array);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('target', $array[0]);
|
||||||
|
$this->assertEquals('ip', $array[0]['target']);
|
||||||
|
$this->assertArrayHasKey('value', $array[0]);
|
||||||
|
$this->assertEquals('1.2.3.4', $array[0]['value']);
|
||||||
|
|
||||||
|
$configuration->addIPRange('1.2.3.4/24');
|
||||||
|
|
||||||
|
$array = $configuration->getArray();
|
||||||
|
$this->assertCount(2, $array);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('target', $array[1]);
|
||||||
|
$this->assertEquals('ip_range', $array[1]['target']);
|
||||||
|
$this->assertArrayHasKey('value', $array[1]);
|
||||||
|
$this->assertEquals('1.2.3.4/24', $array[1]['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
56
tests/Configurations/LoadBalancerTest.php
Normal file
56
tests/Configurations/LoadBalancerTest.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\LoadBalancer;
|
||||||
|
|
||||||
|
class LoadBalancerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider testArgumentsDataProvider
|
||||||
|
*/
|
||||||
|
public function testArguments($setFunction, $arguments, $getFunction, $invalid)
|
||||||
|
{
|
||||||
|
$loadBalancer = new LoadBalancer('bogus', [], 'bogus');
|
||||||
|
foreach ($arguments as $argument) {
|
||||||
|
if ($invalid === true) {
|
||||||
|
try {
|
||||||
|
$loadBalancer->{$setFunction}($argument);
|
||||||
|
} catch (ConfigurationsException $e) {
|
||||||
|
$this->assertNotEquals($argument, $loadBalancer->{$getFunction}());
|
||||||
|
}
|
||||||
|
} elseif ($invalid === false) {
|
||||||
|
$loadBalancer->{$setFunction}($argument);
|
||||||
|
$this->assertEquals($argument, $loadBalancer->{$getFunction}());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArgumentsDataProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'steeringPolicy arguments valid' => [
|
||||||
|
'setSteeringPolicy', ['off', 'geo', 'random', 'dynamic_latency', ''], 'getSteeringPolicy', false
|
||||||
|
],
|
||||||
|
'sessionAffinity arguments valid' => [
|
||||||
|
'setSessionAffinity', ['none', 'cookie', 'ip_cookie', ''], 'getSessionAffinity', false
|
||||||
|
],
|
||||||
|
'sessionAffinityTtl arguments valid' => [
|
||||||
|
'setSessionAffinityTtl', [3600], 'getSessionAffinityTtl', false
|
||||||
|
],
|
||||||
|
'steeringPolicy arguments invalid' => [
|
||||||
|
'setSteeringPolicy', ['invalid'], 'getSteeringPolicy', true
|
||||||
|
],
|
||||||
|
'sessionAffinity arguments invalid' => [
|
||||||
|
'setSessionAffinity', ['invalid'], 'getSessionAffinity', true
|
||||||
|
],
|
||||||
|
'sessionAffinityTtl arguments invalid' => [
|
||||||
|
'setSessionAffinityTtl', [1337], 'getSessionAffinityTtl', true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
21
tests/Configurations/PageRulesActionTest.php
Normal file
21
tests/Configurations/PageRulesActionTest.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
use Cloudflare\API\Configurations\PageRulesActions;
|
||||||
|
|
||||||
|
class PageRulesActionTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testForwardingURLConfigurationIsApplied()
|
||||||
|
{
|
||||||
|
$identifier = 'forwarding_url';
|
||||||
|
$statusCode = 301;
|
||||||
|
$forwardingURL = 'https://www.example.org/';
|
||||||
|
|
||||||
|
$actions = new PageRulesActions();
|
||||||
|
$actions->setForwardingURL($statusCode, $forwardingURL);
|
||||||
|
$configuration = $actions->getArray();
|
||||||
|
|
||||||
|
$this->assertCount(1, $configuration);
|
||||||
|
$this->assertEquals($identifier, $configuration[0]['id']);
|
||||||
|
$this->assertEquals($statusCode, $configuration[0]['value']['status_code']);
|
||||||
|
$this->assertEquals($forwardingURL, $configuration[0]['value']['url']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,14 +8,15 @@
|
|||||||
|
|
||||||
use Cloudflare\API\Configurations\PageRulesTargets;
|
use Cloudflare\API\Configurations\PageRulesTargets;
|
||||||
|
|
||||||
class PageRulesTargetTest extends PHPUnit_Framework_TestCase
|
class PageRulesTargetTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetArray() {
|
public function testGetArray()
|
||||||
|
{
|
||||||
$targets = new PageRulesTargets('junade.com/*');
|
$targets = new PageRulesTargets('junade.com/*');
|
||||||
$array = $targets->getArray();
|
$array = $targets->getArray();
|
||||||
|
|
||||||
$this->assertEquals(1, sizeof($array));
|
$this->assertCount(1, $array);
|
||||||
$this->assertEquals("junade.com/*", $array[0]->constraint->value);
|
$this->assertEquals('junade.com/*', $array[0]['constraint']['value']);
|
||||||
$this->assertEquals("matches", $array[0]->constraint->operator);
|
$this->assertEquals('matches', $array[0]['constraint']['operator']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
53
tests/Configurations/PoolTest.php
Normal file
53
tests/Configurations/PoolTest.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Configurations\ConfigurationsException;
|
||||||
|
use Cloudflare\API\Configurations\Pool;
|
||||||
|
|
||||||
|
class PoolTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider testArgumentsDataProvider
|
||||||
|
*/
|
||||||
|
public function testArguments($setFunction, $arguments, $getFunction, $invalid)
|
||||||
|
{
|
||||||
|
$pool = new Pool('bogus', []);
|
||||||
|
foreach ($arguments as $argument) {
|
||||||
|
if ($invalid) {
|
||||||
|
try {
|
||||||
|
$pool->{$setFunction}($argument);
|
||||||
|
} catch (ConfigurationsException $e) {
|
||||||
|
$this->assertNotEquals($argument, $pool->{$getFunction}());
|
||||||
|
}
|
||||||
|
} elseif ($invalid === false) {
|
||||||
|
$pool->{$setFunction}($argument);
|
||||||
|
$this->assertEquals($argument, $pool->{$getFunction}());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArgumentsDataProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'origins arguments valid' => [
|
||||||
|
'setOrigins', [[['name' => 'test', 'address' => 'server1.example.com']]], 'getOrigins', false
|
||||||
|
],
|
||||||
|
'setNotificationEmail arguments valid' => [
|
||||||
|
'setNotificationEmail', ['user@example.com'], 'getNotificationEmail', false
|
||||||
|
],
|
||||||
|
'origins arguments invalid no address' => [
|
||||||
|
'setOrigins', [['name' => 'test']], 'getOrigins', true
|
||||||
|
],
|
||||||
|
'origins arguments invalid no name' => [
|
||||||
|
'setOrigins', [['address' => 'server1.example.com']], 'getOrigins', true
|
||||||
|
],
|
||||||
|
'setNotificationEmail arguments invalid' => [
|
||||||
|
'setNotificationEmail', ['userexample.com'], 'getNotificationEmail', true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: junade
|
|
||||||
* Date: 05/09/2017
|
|
||||||
* Time: 13:50
|
|
||||||
*/
|
|
||||||
class ConfigurationZoneLockdownTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
public function testGetArray()
|
|
||||||
{
|
|
||||||
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
|
|
||||||
$configuration->addIP('1.2.3.4');
|
|
||||||
|
|
||||||
$array = $configuration->getArray();
|
|
||||||
$this->assertEquals(1, sizeof($array));
|
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('target', $array[0]);
|
|
||||||
$this->assertEquals('ip', $array[0]->target);
|
|
||||||
$this->assertObjectHasAttribute('value', $array[0]);
|
|
||||||
$this->assertEquals('1.2.3.4', $array[0]->value);
|
|
||||||
|
|
||||||
$configuration->addIPRange('1.2.3.4/24');
|
|
||||||
|
|
||||||
$array = $configuration->getArray();
|
|
||||||
$this->assertEquals(2, sizeof($array));
|
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('target', $array[1]);
|
|
||||||
$this->assertEquals('ip_range', $array[1]->target);
|
|
||||||
$this->assertObjectHasAttribute('value', $array[1]);
|
|
||||||
$this->assertEquals('1.2.3.4/24', $array[1]->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
112
tests/Endpoints/AccessRulesTest.php
Normal file
112
tests/Endpoints/AccessRulesTest.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class AccessRulesTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListRules()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccessRules.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 50,
|
||||||
|
'match' => 'all'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $zones->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateRule()
|
||||||
|
{
|
||||||
|
$config = new \Cloudflare\API\Configurations\AccessRules();
|
||||||
|
$config->setIP('1.2.3.4');
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccessRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'challenge',
|
||||||
|
'configuration' => $config->getArray(),
|
||||||
|
'notes' => 'This rule is on because of an event that occured on date X',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->createRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'challenge',
|
||||||
|
$config,
|
||||||
|
'This rule is on because of an event that occured on date X'
|
||||||
|
);
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateAccessRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||||
|
$this->equalTo([
|
||||||
|
'mode' => 'challenge',
|
||||||
|
'notes' => 'This rule is on because of an event that occured on date X',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->updateRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'92f17202ed8bd63d69a66b86a49a8f6b',
|
||||||
|
'challenge',
|
||||||
|
'This rule is on because of an event that occured on date X'
|
||||||
|
);
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteAccessRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
|
||||||
|
$this->equalTo([
|
||||||
|
'cascade' => 'none'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
|
||||||
|
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b');
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
tests/Endpoints/CryptoTest.php
Normal file
82
tests/Endpoints/CryptoTest.php
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class CryptoTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetOpportunisticEncryptionSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOpportunisticEncryptionSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption')
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->getOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetOnionRoutingSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOnionRoutingSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion')
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->getOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateOpportunisticEncryptionSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->updateOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateOnionRoutingSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOnionRoutingSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
|
||||||
|
$result = $cryptoMock->updateOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
282
tests/Endpoints/CustomHostnamesTest.php
Normal file
282
tests/Endpoints/CustomHostnamesTest.php
Normal file
@@ -0,0 +1,282 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 18/03/2018
|
||||||
|
* Time: 22:23
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Cloudflare\API\Endpoints\CustomHostnames;
|
||||||
|
|
||||||
|
class CustomHostnamesTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testAddHostname()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json');
|
||||||
|
|
||||||
|
$customSsl = $this->getCustomSsl();
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
||||||
|
$this->equalTo([
|
||||||
|
'hostname' => 'app.example.com',
|
||||||
|
'custom_origin_server' => 'origin.example.com',
|
||||||
|
'ssl' => [
|
||||||
|
'method' => 'http',
|
||||||
|
'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);
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListHostnames()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listHostnames.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
||||||
|
$this->equalTo([
|
||||||
|
'hostname' => 'app.example.com',
|
||||||
|
'id' => '0d89c70d-ad9f-4843-b99f-6cc0252067e9',
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'order' => 'ssl',
|
||||||
|
'direction' => 'desc',
|
||||||
|
'ssl' => 0
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||||
|
$result = $zones->listHostnames('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 1, 20, 'ssl', 'desc', 0);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetHostname()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHostname.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||||
|
$result = $zones->getHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('id', $result);
|
||||||
|
$this->assertObjectHasAttribute('hostname', $result);
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateHostname()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json');
|
||||||
|
|
||||||
|
$customSsl = $this->getCustomSsl();
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
||||||
|
$this->equalTo([
|
||||||
|
'custom_origin_server' => 'origin.example.com',
|
||||||
|
'ssl' => [
|
||||||
|
'method' => 'http',
|
||||||
|
'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);
|
||||||
|
$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);
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteHostname()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteHostname.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
||||||
|
$result = $zones->deleteHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
|
||||||
|
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id);
|
||||||
|
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,38 +6,19 @@
|
|||||||
* Date: 09/06/2017
|
* Date: 09/06/2017
|
||||||
* Time: 15:31
|
* Time: 15:31
|
||||||
*/
|
*/
|
||||||
class DNSTest extends PHPUnit_Framework_TestCase
|
class DNSTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testAddRecord()
|
public function testAddRecord()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.json');
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"type": "A",
|
|
||||||
"name": "example.com",
|
|
||||||
"content": "1.2.3.4",
|
|
||||||
"proxiable": true,
|
|
||||||
"proxied": false,
|
|
||||||
"ttl": 120,
|
|
||||||
"locked": false,
|
|
||||||
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
|
||||||
"zone_name": "example.com",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'type' => 'A',
|
'type' => 'A',
|
||||||
'name' => 'example.com',
|
'name' => 'example.com',
|
||||||
@@ -51,93 +32,160 @@ class DNSTest extends PHPUnit_Framework_TestCase
|
|||||||
$dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', '120', false);
|
$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()
|
public function testListRecords()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.json');
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": [
|
|
||||||
{
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"type": "A",
|
|
||||||
"name": "example.com",
|
|
||||||
"content": "1.2.3.4",
|
|
||||||
"proxiable": true,
|
|
||||||
"proxied": false,
|
|
||||||
"ttl": 120,
|
|
||||||
"locked": false,
|
|
||||||
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
|
||||||
"zone_name": "example.com",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"result_info": {
|
|
||||||
"page": 1,
|
|
||||||
"per_page": 20,
|
|
||||||
"count": 1,
|
|
||||||
"total_count": 2000
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records?page=1&per_page=20&match=all&type=A&name=example.com&content=127.0.0.1&order=type&direction=desc'),
|
->with(
|
||||||
$this->equalTo([])
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'match' => 'all',
|
||||||
|
'type' => 'A',
|
||||||
|
'name' => 'example.com',
|
||||||
|
'content' => '127.0.0.1',
|
||||||
|
'order' => 'type',
|
||||||
|
'direction' => 'desc',
|
||||||
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
$result = $zones->listRecords("023e105f4ecef8ad9ca31a8372d0c353","A", "example.com", "127.0.0.1", 1, 20, "type", "desc", "all");
|
$result = $zones->listRecords('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', 1, 20, 'type', 'desc');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRecordDetails()
|
public function testGetDNSRecordDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getDNSRecordDetails.json');
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"type": "A",
|
|
||||||
"name": "example.com",
|
|
||||||
"content": "1.2.3.4",
|
|
||||||
"proxiable": true,
|
|
||||||
"proxied": false,
|
|
||||||
"ttl": 120,
|
|
||||||
"locked": false,
|
|
||||||
"zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
|
|
||||||
"zone_name": "example.com",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
$this->equalTo([])
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
);
|
);
|
||||||
|
|
||||||
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
$result = $dns->getRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetRecordID()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRecordId.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records')
|
||||||
|
);
|
||||||
|
|
||||||
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
|
$result = $dns->getRecordID('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com');
|
||||||
|
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateDNSRecord()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$details = [
|
||||||
|
'type' => 'A',
|
||||||
|
'name' => 'example.com',
|
||||||
|
'content' => '1.2.3.4',
|
||||||
|
'ttl' => 120,
|
||||||
|
'proxied' => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
|
$this->equalTo($details)
|
||||||
|
);
|
||||||
|
|
||||||
|
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
|
||||||
|
$result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details);
|
||||||
|
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id);
|
||||||
|
|
||||||
|
foreach ($details as $property => $value) {
|
||||||
|
$this->assertEquals($result->result->{ $property }, $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
121
tests/Endpoints/FirewallSettingsTest.php
Normal file
121
tests/Endpoints/FirewallSettingsTest.php
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class FirewallSettingsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetSecurityLevelSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSecurityLevelSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/security_level')
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->getSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('medium', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetChallengeTTLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getChallengeTTLSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/challenge_ttl')
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->getChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals(1800, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetBrowserIntegrityCheckSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserIntegrityCheckSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/browser_check')
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->getBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('on', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateSecurityLevelSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSecurityLevelSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/security_level'),
|
||||||
|
$this->equalTo(['value' => 'medium'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->updateSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'medium');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateChallengeTTLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateChallengeTTLSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/challenge_ttl'),
|
||||||
|
$this->equalTo(['value' => 1800])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->updateChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 1800);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateBrowserIntegrityCheckSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserIntegrityCheckSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/browser_check'),
|
||||||
|
$this->equalTo(['value' => 'on'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
|
||||||
|
$result = $firewallSettingsMock->updateBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'on');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,37 +6,26 @@
|
|||||||
* Time: 20:16
|
* Time: 20:16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\IPs;
|
class IPsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListIPs()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listIPs.json');
|
||||||
|
|
||||||
class IPsTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
public function testListIPs() {
|
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"ipv4_cidrs": [
|
|
||||||
"199.27.128.0/21"
|
|
||||||
],
|
|
||||||
"ipv6_cidrs": [
|
|
||||||
"2400:cb00::/32"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('ips'), $this->equalTo([])
|
->with(
|
||||||
|
$this->equalTo('ips')
|
||||||
);
|
);
|
||||||
|
|
||||||
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
$ipsMock = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||||
$ips = $ips->listIPs();
|
$ips = $ipsMock->listIPs();
|
||||||
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
|
$this->assertObjectHasAttribute('ipv4_cidrs', $ips);
|
||||||
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
|
$this->assertObjectHasAttribute('ipv6_cidrs', $ips);
|
||||||
|
$this->assertObjectHasAttribute('ipv4_cidrs', $ipsMock->getBody()->result);
|
||||||
|
$this->assertObjectHasAttribute('ipv6_cidrs', $ipsMock->getBody()->result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
128
tests/Endpoints/LoadBalancersTest.php
Normal file
128
tests/Endpoints/LoadBalancersTest.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Configurations\LoadBalancer;
|
||||||
|
use Cloudflare\API\Endpoints\LoadBalancers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
class LoadBalancersTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreateLoadBalancer()
|
||||||
|
{
|
||||||
|
$pools = [
|
||||||
|
'17b5962d775c646f3f9725cbc7a53df4',
|
||||||
|
'9290f38c5d07c2e2f4df57b1f61d4196',
|
||||||
|
'00920f38ce07c2e2f4df50b1f61d4194'
|
||||||
|
];
|
||||||
|
|
||||||
|
$lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createLoadBalancer.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers'),
|
||||||
|
$lbConfiguration->getArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$result = $loadBalancers->createLoadBalancer('699d98642c564d2e855e9661899b7252', $lbConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListLoadBalancer()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listLoadBalancers.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers')
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$loadBalancers->listLoadBalancers('699d98642c564d2e855e9661899b7252');
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetLoadBalancerDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getLoadBalancerDetails.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252')
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$loadBalancers->getLoadBalancerDetails('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252');
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateLoadBalancer()
|
||||||
|
{
|
||||||
|
$pools = [
|
||||||
|
'17b5962d775c646f3f9725cbc7a53df4',
|
||||||
|
'9290f38c5d07c2e2f4df57b1f61d4196',
|
||||||
|
'00920f38ce07c2e2f4df50b1f61d4194'
|
||||||
|
];
|
||||||
|
|
||||||
|
$lbConfiguration = new LoadBalancer('www.example.com', $pools, '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateLoadBalancer.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252'),
|
||||||
|
$this->equalTo($lbConfiguration->getArray())
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$result = $loadBalancers->updateLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252', $lbConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteLoadBalancer()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteLoadBalancer.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/699d98642c564d2e855e9661899b7252/load_balancers/699d98642c564d2e855e9661899b7252')
|
||||||
|
);
|
||||||
|
|
||||||
|
$loadBalancers = new LoadBalancers($mock);
|
||||||
|
$result = $loadBalancers->deleteLoadBalancer('699d98642c564d2e855e9661899b7252', '699d98642c564d2e855e9661899b7252');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('699d98642c564d2e855e9661899b7252', $loadBalancers->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
93
tests/Endpoints/MembershipTest.php
Normal file
93
tests/Endpoints/MembershipTest.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
class MembershipTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListMemberships()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listMemberships.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('memberships'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'account.name' => 'Demo Account',
|
||||||
|
'status' => 'accepted',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
$result = $zones->listMemberships('Demo Account', 'accepted', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $zones->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMembershipDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getMembershipDetails.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
$details = $membership->getMembershipDetails('4536bcfad5faccb111b47003c79917fa');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('id', $details);
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $details->id);
|
||||||
|
$this->assertObjectHasAttribute('code', $details);
|
||||||
|
$this->assertEquals('05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0', $details->code);
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateMembershipDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateMembershipStatus.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'),
|
||||||
|
$this->equalTo([
|
||||||
|
'status' => 'accepted'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
$membership->updateMembershipStatus('4536bcfad5faccb111b47003c79917fa', 'accepted');
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleteMembership()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteMembership.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with($this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'));
|
||||||
|
|
||||||
|
$membership = new \Cloudflare\API\Endpoints\Membership($mock);
|
||||||
|
|
||||||
|
$membership->deleteMembership('4536bcfad5faccb111b47003c79917fa');
|
||||||
|
|
||||||
|
$this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,256 +6,127 @@
|
|||||||
* Time: 19:25
|
* Time: 19:25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\PageRules;
|
class PageRulesTest extends TestCase
|
||||||
|
|
||||||
class PageRulesTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
public function testCreatePageRule()
|
public function testCreatePageRule()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "9a7806061c88ada191ed06f989cc3dac",
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target": "url",
|
|
||||||
"constraint": {
|
|
||||||
"operator": "matches",
|
|
||||||
"value": "*example.com/images/*"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"id": "always_online",
|
|
||||||
"value": "on"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"priority": 1,
|
|
||||||
"status": "active",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z"
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
||||||
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
||||||
$action->setAlwaysOnline(true);
|
$action->setAlwaysOnline(true);
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'targets' => $target->getArray(),
|
'targets' => $target->getArray(),
|
||||||
'actions' => $action->getArray(),
|
'actions' => $action->getArray(),
|
||||||
'active' => 'active',
|
'status' => 'active',
|
||||||
'priority' => '1'
|
'priority' => 1
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pr->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListPageRules()
|
public function testListPageRules()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPageRules.json');
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": [
|
|
||||||
{
|
|
||||||
"id": "9a7806061c88ada191ed06f989cc3dac",
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target": "url",
|
|
||||||
"constraint": {
|
|
||||||
"operator": "matches",
|
|
||||||
"value": "*example.com/images/*"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"id": "always_online",
|
|
||||||
"value": "on"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"priority": 1,
|
|
||||||
"status": "active",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"result_info": {
|
|
||||||
"page": 1,
|
|
||||||
"per_page": 20,
|
|
||||||
"count": 1,
|
|
||||||
"total_count": 2000
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules?status=active&order=status&direction=desc&match=all'), $this->equalTo([])
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'status' => 'active',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc',
|
||||||
|
'match' => 'all'
|
||||||
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$pr->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPageRuleDetails()
|
public function testGetPageRuleDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPageRuleDetails.json');
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "9a7806061c88ada191ed06f989cc3dac",
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target": "url",
|
|
||||||
"constraint": {
|
|
||||||
"operator": "matches",
|
|
||||||
"value": "*example.com/images/*"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"id": "always_online",
|
|
||||||
"value": "on"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"priority": 1,
|
|
||||||
"status": "active",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z"
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([])
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$pr->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdatePageRule()
|
public function testUpdatePageRule()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "9a7806061c88ada191ed06f989cc3dac",
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target": "url",
|
|
||||||
"constraint": {
|
|
||||||
"operator": "matches",
|
|
||||||
"value": "*example.com/images/*"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"id": "always_online",
|
|
||||||
"value": "on"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"priority": 1,
|
|
||||||
"status": "active",
|
|
||||||
"modified_on": "2014-01-01T05:20:00.12345Z",
|
|
||||||
"created_on": "2014-01-01T05:20:00.12345Z"
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
$target = new \Cloudflare\API\Configurations\PageRulesTargets('*example.com/images/*');
|
||||||
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
$action = new \Cloudflare\API\Configurations\PageRulesActions();
|
||||||
$action->setAlwaysOnline(true);
|
$action->setAlwaysOnline(true);
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePageRule.json');
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('patch')->willReturn($response);
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('patch')
|
->method('patch')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'targets' => $target->getArray(),
|
'targets' => $target->getArray(),
|
||||||
'actions' => $action->getArray(),
|
'actions' => $action->getArray(),
|
||||||
'active' => 'active',
|
'status' => 'active',
|
||||||
'priority' => '1'
|
'priority' => 1
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pr->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
|
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac', $target, $action, true, 1);
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeletePageRule()
|
public function testDeletePageRule()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePageRule.json');
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "9a7806061c88ada191ed06f989cc3dac"
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('delete')->willReturn($response);
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'), $this->equalTo([]),
|
->with(
|
||||||
$this->equalTo([])
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
|
||||||
);
|
);
|
||||||
|
|
||||||
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
|
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
|
||||||
$result = $pr->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
|
||||||
|
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
133
tests/Endpoints/PoolsTest.php
Normal file
133
tests/Endpoints/PoolsTest.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Cloudflare\API\Adapter\Adapter;
|
||||||
|
use Cloudflare\API\Endpoints\Pools;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Martijn Smidt <martijn@squeezely.tech>
|
||||||
|
* User: HemeraOne
|
||||||
|
* Date: 13/05/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PoolsTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCreatePool()
|
||||||
|
{
|
||||||
|
$origins = [
|
||||||
|
[
|
||||||
|
'name' => 'app-server-1',
|
||||||
|
'address' => '0.0.0.0',
|
||||||
|
'enabled' => true,
|
||||||
|
'weight' => 0.56
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins);
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPool.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools'),
|
||||||
|
$poolConfiguration->getArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$result = $pools->createPool('01a7362d577a6c3019a474fd6f485823', $poolConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListPools()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPools.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$pools->listPools('01a7362d577a6c3019a474fd6f485823');
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetPoolDetails()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPoolDetails.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$pools->getPoolDetails('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdatePool()
|
||||||
|
{
|
||||||
|
$origins = [
|
||||||
|
[
|
||||||
|
'name' => 'app-server-1',
|
||||||
|
'address' => '0.0.0.0',
|
||||||
|
'enabled' => true,
|
||||||
|
'weight' => 0.56
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$poolConfiguration = new \Cloudflare\API\Configurations\Pool('primary-dc-1', $origins);
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePool.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('put')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4'),
|
||||||
|
$this->equalTo($poolConfiguration->getArray())
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$result = $pools->updatePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4', $poolConfiguration);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeletePool()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deletePool.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823/load_balancers/pools/17b5962d775c646f3f9725cbc7a53df4')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pools = new Pools($mock);
|
||||||
|
$result = $pools->deletePool('01a7362d577a6c3019a474fd6f485823', '17b5962d775c646f3f9725cbc7a53df4');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('17b5962d775c646f3f9725cbc7a53df4', $pools->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
149
tests/Endpoints/RailgunTest.php
Normal file
149
tests/Endpoints/RailgunTest.php
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 11:20
|
||||||
|
*/
|
||||||
|
|
||||||
|
class RailgunTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testcreate()
|
||||||
|
{
|
||||||
|
$details = [
|
||||||
|
'name' => 'My Railgun',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns'),
|
||||||
|
$this->equalTo(['name' => $details['name']])
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->create($details['name']);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
|
||||||
|
foreach ($details as $property => $value) {
|
||||||
|
$this->assertEquals($result->result->{ $property }, $value);
|
||||||
|
}
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testlist()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRailguns.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'direction' => 'desc'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->list(1, 20, 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testget()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->get('e928d310693a83094309acf9ead50448');
|
||||||
|
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetZones()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRailgunZones.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones')
|
||||||
|
);
|
||||||
|
|
||||||
|
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $railgun->getZones('e928d310693a83094309acf9ead50448');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $railgun->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testupdate()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$details = [
|
||||||
|
'enabled' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
|
||||||
|
$this->equalTo($details)
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$result = $waf->update('e928d310693a83094309acf9ead50448', true);
|
||||||
|
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testdelete()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRailgun.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
|
||||||
|
$waf->delete('e928d310693a83094309acf9ead50448');
|
||||||
|
$this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
161
tests/Endpoints/SSLTest.php
Normal file
161
tests/Endpoints/SSLTest.php
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class SSLTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetSSLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSSLVerificationStatus()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertEquals('active', $result->result[0]->certificate_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetHTTPSRedirectSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRedirectSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetHTTPSRewritesSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRewritesSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateSSLSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl'),
|
||||||
|
$this->equalTo(['value' => 'full'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateHTTPSRedirectSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRedirectSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->updateHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateHTTPSRewritesSetting()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRewritesSetting.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
|
||||||
|
$result = $sslMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
110
tests/Endpoints/TLSTest.php
Normal file
110
tests/Endpoints/TLSTest.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Jurgen Coetsiers
|
||||||
|
* Date: 21/10/2018
|
||||||
|
* Time: 09:09
|
||||||
|
*/
|
||||||
|
|
||||||
|
class TLSTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetTLSClientAuth()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getTLSClientAuth.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_client_auth')
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->getTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertEquals('off', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnableTLS13()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/enableTLS13.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_1_3'),
|
||||||
|
$this->equalTo(['value' => 'on'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->enableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisableTLS13()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/disableTLS13.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_1_3'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->disableTLS13('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testChangeMinimimTLSVersion()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeMinimumTLSVersion.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/min_tls_version'),
|
||||||
|
$this->equalTo(['value' => '1.1'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->changeMinimumTLSVersion('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', '1.1');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateTLSClientAuth()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateTLSClientAuth.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/tls_client_auth'),
|
||||||
|
$this->equalTo(['value' => 'off'])
|
||||||
|
);
|
||||||
|
|
||||||
|
$tlsMock = new \Cloudflare\API\Endpoints\TLS($mock);
|
||||||
|
$result = $tlsMock->updateTLSClientAuth('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,57 +6,34 @@
|
|||||||
* Time: 15:19
|
* Time: 15:19
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\UARules;
|
class UARulesTest extends TestCase
|
||||||
|
|
||||||
class UARulesTest extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
public function testListRules()
|
public function testListRules()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listRules.json');
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": [
|
|
||||||
{
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
|
|
||||||
"mode": "js_challenge",
|
|
||||||
"configuration": {
|
|
||||||
"target": "ua",
|
|
||||||
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"result_info": {
|
|
||||||
"page": 1,
|
|
||||||
"per_page": 20,
|
|
||||||
"count": 1,
|
|
||||||
"total_count": 2000
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules?page=1&per_page=20'),
|
->with(
|
||||||
$this->equalTo([])
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20
|
||||||
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
|
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('result', $result);
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
$this->assertObjectHasAttribute('result_info', $result);
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
|
||||||
$this->assertEquals(1, $result->result_info->page);
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateRule()
|
public function testCreateRule()
|
||||||
@@ -64,32 +41,15 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
$config = new \Cloudflare\API\Configurations\UARules();
|
$config = new \Cloudflare\API\Configurations\UARules();
|
||||||
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
||||||
|
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRule.json');
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
|
|
||||||
"mode": "js_challenge",
|
|
||||||
"configuration": {
|
|
||||||
"target": "ua",
|
|
||||||
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('post')->willReturn($response);
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('post')
|
->method('post')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'), $this->equalTo([]),
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'mode' => 'js_challenge',
|
'mode' => 'js_challenge',
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
@@ -98,47 +58,35 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$ld->createRule('023e105f4ecef8ad9ca31a8372d0c353', 'js_challenge', $config,
|
$rules->createRule(
|
||||||
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
'js_challenge',
|
||||||
|
$config,
|
||||||
'372e67954025e0ba6aaa6d586b9e0b59',
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack');
|
'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack'
|
||||||
|
);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRuleDetails()
|
public function getRuleDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getRuleDetails.json');
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
|
|
||||||
"mode": "js_challenge",
|
|
||||||
"configuration": {
|
|
||||||
"target": "ua",
|
|
||||||
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
$this->equalTo([])
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
);
|
);
|
||||||
|
|
||||||
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
|
$result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
|
||||||
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateRule()
|
public function testUpdateRule()
|
||||||
@@ -146,33 +94,15 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
$config = new \Cloudflare\API\Configurations\UARules();
|
$config = new \Cloudflare\API\Configurations\UARules();
|
||||||
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
$config->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
|
||||||
|
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRule.json');
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59",
|
|
||||||
"description": "Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack",
|
|
||||||
"mode": "js_challenge",
|
|
||||||
"configuration": {
|
|
||||||
"target": "ua",
|
|
||||||
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('put')->willReturn($response);
|
$mock->method('put')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('put')
|
->method('put')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
$this->equalTo([]),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'mode' => 'js_challenge',
|
'mode' => 'js_challenge',
|
||||||
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
@@ -181,38 +111,32 @@ class UARulesTest extends PHPUnit_Framework_TestCase
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$ld->updateRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59',
|
$rules->updateRule(
|
||||||
'js_challenge', $config,
|
'023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
'Restrict access to these endpoints to requests from a known IP address');
|
'372e67954025e0ba6aaa6d586b9e0b59',
|
||||||
|
'js_challenge',
|
||||||
|
$config,
|
||||||
|
'Restrict access to these endpoints to requests from a known IP address'
|
||||||
|
);
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteRule()
|
public function testDeleteRule()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('{
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRule.json');
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "372e67954025e0ba6aaa6d586b9e0b59"
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('delete')->willReturn($response);
|
$mock->method('delete')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with($this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
|
->with(
|
||||||
$this->equalTo([]),
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
|
||||||
$this->equalTo([])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
|
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
|
||||||
$ld->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
|
||||||
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,132 +5,64 @@
|
|||||||
* Date: 01/02/2017
|
* Date: 01/02/2017
|
||||||
* Time: 12:50
|
* Time: 12:50
|
||||||
*/
|
*/
|
||||||
class UserTest extends PHPUnit_Framework_TestCase
|
class UserTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetUserDetails()
|
public function testGetUserDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserDetails.json');
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
|
||||||
"email": "user@example.com",
|
|
||||||
"first_name": "John",
|
|
||||||
"last_name": "Appleseed",
|
|
||||||
"username": "cfuser12345",
|
|
||||||
"telephone": "+1 123-123-1234",
|
|
||||||
"country": "US",
|
|
||||||
"zipcode": "12345",
|
|
||||||
"created_on": "2014-01-01T05:20:00Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00Z",
|
|
||||||
"two_factor_authentication_enabled": false
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$details = $user->getUserDetails();
|
$details = $user->getUserDetails();
|
||||||
|
|
||||||
$this->assertObjectHasAttribute("id", $details);
|
$this->assertObjectHasAttribute('id', $details);
|
||||||
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $details->id);
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
|
||||||
$this->assertObjectHasAttribute("email", $details);
|
$this->assertObjectHasAttribute('email', $details);
|
||||||
$this->assertEquals("user@example.com", $details->email);
|
$this->assertEquals('user@example.com', $details->email);
|
||||||
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUserID()
|
public function testGetUserID()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserId.json');
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
|
||||||
"email": "user@example.com",
|
|
||||||
"first_name": "John",
|
|
||||||
"last_name": "Appleseed",
|
|
||||||
"username": "cfuser12345",
|
|
||||||
"telephone": "+1 123-123-1234",
|
|
||||||
"country": "US",
|
|
||||||
"zipcode": "12345",
|
|
||||||
"created_on": "2014-01-01T05:20:00Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00Z",
|
|
||||||
"two_factor_authentication_enabled": false
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $user->getUserID());
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
|
||||||
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetUserEmail()
|
public function testGetUserEmail()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getUserEmail.json');
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
|
||||||
"email": "user@example.com",
|
|
||||||
"first_name": "John",
|
|
||||||
"last_name": "Appleseed",
|
|
||||||
"username": "cfuser12345",
|
|
||||||
"telephone": "+1 123-123-1234",
|
|
||||||
"country": "US",
|
|
||||||
"zipcode": "12345",
|
|
||||||
"created_on": "2014-01-01T05:20:00Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00Z",
|
|
||||||
"two_factor_authentication_enabled": false
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('get')->willReturn($response);
|
$mock->method('get')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())->method('get');
|
$mock->expects($this->once())->method('get');
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$this->assertEquals("user@example.com", $user->getUserEmail());
|
$this->assertEquals('user@example.com', $user->getUserEmail());
|
||||||
|
$this->assertEquals('user@example.com', $user->getBody()->result->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateUserDetails()
|
public function testUpdateUserDetails()
|
||||||
{
|
{
|
||||||
$stream = GuzzleHttp\Psr7\stream_for('
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateUserDetails.json');
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [],
|
|
||||||
"messages": [],
|
|
||||||
"result": {
|
|
||||||
"id": "7c5dae5552338874e5053f2534d2767a",
|
|
||||||
"email": "user@example.com",
|
|
||||||
"first_name": "John",
|
|
||||||
"last_name": "Appleseed",
|
|
||||||
"username": "cfuser12345",
|
|
||||||
"telephone": "+1 123-123-1234",
|
|
||||||
"country": "US",
|
|
||||||
"zipcode": "12345",
|
|
||||||
"created_on": "2014-01-01T05:20:00Z",
|
|
||||||
"modified_on": "2014-01-01T05:20:00Z",
|
|
||||||
"two_factor_authentication_enabled": false
|
|
||||||
}
|
|
||||||
}');
|
|
||||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
$mock->method('patch')->willReturn($response);
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('patch')
|
->method('patch')
|
||||||
->with($this->equalTo('user'), $this->equalTo([]), $this->equalTo(['email' => 'user2@example.com']));
|
->with($this->equalTo('user'), $this->equalTo(['email' => 'user2@example.com']));
|
||||||
|
|
||||||
$user = new \Cloudflare\API\Endpoints\User($mock);
|
$user = new \Cloudflare\API\Endpoints\User($mock);
|
||||||
$user->updateUserDetails(['email' => "user2@example.com"]);
|
$user->updateUserDetails(['email' => 'user2@example.com']);
|
||||||
|
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
221
tests/Endpoints/WAFTest.php
Normal file
221
tests/Endpoints/WAFTest.php
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: junade
|
||||||
|
* Date: 23/10/2017
|
||||||
|
* Time: 13:34
|
||||||
|
*/
|
||||||
|
|
||||||
|
class WAFTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testgetPackages()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackages.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/waf/packages'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'match' => 'all',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetPackageInfo()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageInfo.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/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b')
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b');
|
||||||
|
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id);
|
||||||
|
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetRules()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackageRules.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/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'match' => 'all',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $waf->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetRuleInfo()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageRuleInfo.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/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023')
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023');
|
||||||
|
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testupdateRule()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePackageRule.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$details = [
|
||||||
|
'mode' => 'on',
|
||||||
|
];
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
|
||||||
|
$this->equalTo($details)
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->updateRule('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023', 'on');
|
||||||
|
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
|
||||||
|
|
||||||
|
foreach ($details as $property => $value) {
|
||||||
|
$this->assertEquals($result->{ $property }, $value);
|
||||||
|
}
|
||||||
|
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroups()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listPackageGroups.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/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups'),
|
||||||
|
$this->equalTo([
|
||||||
|
'page' => 1,
|
||||||
|
'per_page' => 20,
|
||||||
|
'match' => 'all',
|
||||||
|
'order' => 'status',
|
||||||
|
'direction' => 'desc'
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('result', $result);
|
||||||
|
$this->assertObjectHasAttribute('result_info', $result);
|
||||||
|
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id);
|
||||||
|
$this->assertEquals(1, $result->result_info->page);
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result[0]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testgetGroupInfo()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPackageGroupInfo.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/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5')
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5');
|
||||||
|
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testupdateGroup()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updatePackageGroup.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('patch')->willReturn($response);
|
||||||
|
|
||||||
|
$details = [
|
||||||
|
'mode' => 'off',
|
||||||
|
];
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('patch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
|
||||||
|
$this->equalTo($details)
|
||||||
|
);
|
||||||
|
|
||||||
|
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
|
||||||
|
$result = $waf->updateGroup('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5', 'off');
|
||||||
|
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
|
||||||
|
|
||||||
|
foreach ($details as $property => $value) {
|
||||||
|
$this->assertEquals($result->{ $property }, $value);
|
||||||
|
}
|
||||||
|
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user