Compare commits
1 Commits
1.1.0
...
revert-49-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67c34b789e |
@@ -18,7 +18,7 @@ Each API call is provided via a similarly named function within various classes
|
|||||||
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
|
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
|
||||||
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
|
||||||
- [ ] Virtual DNS Management
|
- [ ] Virtual DNS Management
|
||||||
- [x] Custom hostnames
|
- [ ] Custom hostnames
|
||||||
- [x] Zone Lockdown and User-Agent Block rules
|
- [x] Zone Lockdown and User-Agent Block rules
|
||||||
- [ ] Organization Administration
|
- [ ] Organization Administration
|
||||||
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
|
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
|
||||||
|
|||||||
@@ -132,11 +132,9 @@ class PageRulesActions implements Configurations
|
|||||||
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
|
throw new ConfigurationsException('Status Codes can only be 301 or 302.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addConfigurationOption("forwarding_url", [
|
$this->addConfigurationOption('forwarding_url', [
|
||||||
'value' => [
|
'status_code' => $statusCode,
|
||||||
'status_code' => $statusCode,
|
'url' => $forwardingUrl,
|
||||||
'url' => $forwardingUrl,
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,19 +299,9 @@ class PageRulesActions implements Configurations
|
|||||||
|
|
||||||
private function addConfigurationOption(string $setting, array $configuration)
|
private function addConfigurationOption(string $setting, array $configuration)
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Transforms an, optionally nested, array in to a collection of
|
|
||||||
* stdClass objects.
|
|
||||||
*
|
|
||||||
* @var array $array
|
|
||||||
*/
|
|
||||||
$getArrayAsObject = function (array $array) {
|
|
||||||
return json_decode(json_encode($array));
|
|
||||||
};
|
|
||||||
|
|
||||||
$configuration['id'] = $setting;
|
$configuration['id'] = $setting;
|
||||||
|
|
||||||
array_push($this->configs, $getArrayAsObject($configuration));
|
$this->configs[] = (object) $configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBoolAsOnOrOff(bool $value): string
|
private function getBoolAsOnOrOff(bool $value): string
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: junade
|
|
||||||
* Date: 18/03/2018
|
|
||||||
* Time: 21:46
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Cloudflare\API\Endpoints;
|
|
||||||
|
|
||||||
use Cloudflare\API\Adapter\Adapter;
|
|
||||||
|
|
||||||
class CustomHostnames implements API
|
|
||||||
{
|
|
||||||
private $adapter;
|
|
||||||
|
|
||||||
public function __construct(Adapter $adapter)
|
|
||||||
{
|
|
||||||
$this->adapter = $adapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
|
||||||
*
|
|
||||||
* @param string $zoneID
|
|
||||||
* @param string $hostname
|
|
||||||
* @param string $sslMethod
|
|
||||||
* @param string $sslType
|
|
||||||
* @return \stdClass
|
|
||||||
*/
|
|
||||||
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv'): \stdClass
|
|
||||||
{
|
|
||||||
$options = [
|
|
||||||
'hostname' => $hostname,
|
|
||||||
'ssl' => (object)[
|
|
||||||
'method' => $sslMethod,
|
|
||||||
'type' => $sslType
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', [], $options);
|
|
||||||
$body = json_decode($zone->getBody());
|
|
||||||
return $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, []);
|
|
||||||
$body = json_decode($zone->getBody());
|
|
||||||
|
|
||||||
return (object)['result' => $body->result, 'result_info' => $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, [], []);
|
|
||||||
$body = json_decode($zone->getBody());
|
|
||||||
|
|
||||||
return $body->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
|
|
||||||
*
|
|
||||||
* @param string $zoneID
|
|
||||||
* @param string $hostnameID
|
|
||||||
* @param string $sslMethod
|
|
||||||
* @param string $sslType
|
|
||||||
* @return \stdClass
|
|
||||||
*/
|
|
||||||
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = ''): \stdClass
|
|
||||||
{
|
|
||||||
$query = [];
|
|
||||||
|
|
||||||
if (!empty($sslMethod)) {
|
|
||||||
$query['method'] = $sslMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($sslType)) {
|
|
||||||
$query['type'] = $sslType;
|
|
||||||
}
|
|
||||||
|
|
||||||
$options = [
|
|
||||||
'ssl' => (object)$query
|
|
||||||
];
|
|
||||||
|
|
||||||
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, [], $options);
|
|
||||||
$body = json_decode($zone->getBody());
|
|
||||||
return $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, [], []);
|
|
||||||
$body = json_decode($zone->getBody());
|
|
||||||
return $body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,6 @@ class DNS implements API
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @param int $ttl
|
* @param int $ttl
|
||||||
* @param bool $proxied
|
* @param bool $proxied
|
||||||
* @param string $priority
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function addRecord(
|
public function addRecord(
|
||||||
@@ -37,8 +36,7 @@ class DNS implements API
|
|||||||
string $name,
|
string $name,
|
||||||
string $content,
|
string $content,
|
||||||
int $ttl = 0,
|
int $ttl = 0,
|
||||||
bool $proxied = true,
|
bool $proxied = true
|
||||||
string $priority = ''
|
|
||||||
): bool {
|
): bool {
|
||||||
$options = [
|
$options = [
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
@@ -51,10 +49,6 @@ class DNS implements API
|
|||||||
$options['ttl'] = $ttl;
|
$options['ttl'] = $ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($priority)) {
|
|
||||||
$options['priority'] = $priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options);
|
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options);
|
||||||
|
|
||||||
$body = json_decode($user->getBody());
|
$body = json_decode($user->getBody());
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: junade
|
|
||||||
* Date: 18/03/2018
|
|
||||||
* Time: 22:23
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Cloudflare\API\Endpoints\CustomHostnames;
|
|
||||||
|
|
||||||
class CustomHostnamesTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testAddHostname()
|
|
||||||
{
|
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json');
|
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
|
||||||
$mock->method('post')->willReturn($response);
|
|
||||||
|
|
||||||
$mock->expects($this->once())
|
|
||||||
->method('post')
|
|
||||||
->with(
|
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
|
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
|
||||||
'hostname' => 'app.example.com',
|
|
||||||
'ssl' => (object)[
|
|
||||||
'method' => 'http',
|
|
||||||
'type' => 'dv'
|
|
||||||
]
|
|
||||||
])
|
|
||||||
);
|
|
||||||
|
|
||||||
$hostname = new CustomHostnames($mock);
|
|
||||||
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv');
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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'),
|
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateHostname()
|
|
||||||
{
|
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json');
|
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
|
||||||
$mock->method('patch')->willReturn($response);
|
|
||||||
|
|
||||||
$mock->expects($this->once())
|
|
||||||
->method('patch')
|
|
||||||
->with(
|
|
||||||
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
|
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([
|
|
||||||
'ssl' => (object)[
|
|
||||||
'method' => 'http',
|
|
||||||
'type' => 'dv'
|
|
||||||
]
|
|
||||||
])
|
|
||||||
);
|
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
|
|
||||||
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv');
|
|
||||||
|
|
||||||
$this->assertObjectHasAttribute('id', $result);
|
|
||||||
$this->assertObjectHasAttribute('hostname', $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
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'),
|
|
||||||
$this->equalTo([]),
|
|
||||||
$this->equalTo([])
|
|
||||||
);
|
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
|
|
||||||
"hostname": "app.example.com",
|
|
||||||
"ssl": {
|
|
||||||
"status": "pending_validation",
|
|
||||||
"method": "http",
|
|
||||||
"type": "dv",
|
|
||||||
"cname_target": "dcv.digicert.com",
|
|
||||||
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
|
|
||||||
"hostname": "app.example.com",
|
|
||||||
"ssl": {
|
|
||||||
"status": "pending_validation",
|
|
||||||
"method": "http",
|
|
||||||
"type": "dv",
|
|
||||||
"cname_target": "dcv.digicert.com",
|
|
||||||
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": [
|
|
||||||
{
|
|
||||||
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
|
|
||||||
"hostname": "app.example.com",
|
|
||||||
"ssl": {
|
|
||||||
"status": "pending_validation",
|
|
||||||
"method": "http",
|
|
||||||
"type": "dv",
|
|
||||||
"cname_target": "dcv.digicert.com",
|
|
||||||
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"result_info": {
|
|
||||||
"page": 1,
|
|
||||||
"per_page": 20,
|
|
||||||
"count": 1,
|
|
||||||
"total_count": 2000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"success": true,
|
|
||||||
"errors": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"messages": [
|
|
||||||
{}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
|
|
||||||
"hostname": "app.example.com",
|
|
||||||
"ssl": {
|
|
||||||
"status": "pending_validation",
|
|
||||||
"method": "http",
|
|
||||||
"type": "dv",
|
|
||||||
"cname_target": "dcv.digicert.com",
|
|
||||||
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user