Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

Commit

Permalink
Updated Load Balancer methods to match final API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesryanbell committed Feb 27, 2017
1 parent 0af7a7a commit 1ed918f
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 82 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jamesryanbell/cloudflare",
"description": "CloudFlare API - PHP",
"license": "MIT",
"version": "1.9.0",
"version": "1.10.0",
"keywords": ["cloudflare", "api"],
"authors": [
{
Expand Down
133 changes: 133 additions & 0 deletions src/CloudFlare/Organizations/LoadBalancers/Monitors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

namespace Cloudflare\User\LoadBalancers;

use Cloudflare\Api;
use Cloudflare\Organizations;

/**
* CloudFlare API wrapper
*
* CTM Monitors
* Cloud Traffic Manager Monitor
*
* @author James Bell <james@james-bell.co.uk>
*
* @version 1
*/
class Monitors extends Api
{
/**
* List monitors
* List configured monitors for a user
*
* @param string $organization_identifier
*/
public function monitors($organization_identifier)
{
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/monitors');
}

/**
* Create a monitor
* Create a configured monitor
*
* @param string $organization_identifier
* @param string $expected_body A case-insensitive substring to match in the body of the probe
* response to declare an origin as up
* @param string $expected_codes The expected HTTP response code or code range for the probe
* @param string|null $method The HTTP method to use for the health check.
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
* @param string|null $path The endpoint path to health check against.
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
* time, but will increase load on the origins as we check from multiple locations.
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
* as unhealthy. Retries are attempted immediately.
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
* a Host header by default. The User-Agent header cannot be overridden.
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
* 'HTTP' and 'HTTPS'.
* @param string|null $description Object description
*/
public function create($organization_identifier, $expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
{
$data = [
'expected_body' => $expected_body,
'expected_codes' => $expected_codes,
'method' => $method,
'timeout' => $timeout,
'path' => $path,
'interval' => $interval,
'retries' => $retries,
'header' => $header,
'type' => $type,
'description' => $description,
];

return $this->post('/organizations/'.$organization_identifier.'/load_balancers/monitors', $data);
}

/**
* Monitor details
* List a single configured CTM monitor for a user
*
* @param string $organization_identifier
* @param string $identifier
*/
public function details($organization_identifier, $identifier)
{
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/monitors/'.$identifier);
}

/**
* Modify a monitor
* Modify a configured monitor
*
* @param string $organization_identifier
* @param string $identifier
* @param string $expected_body A case-insensitive substring to match in the body of the probe
* response to declare an origin as up
* @param string $expected_codes The expected HTTP response code or code range for the probe
* @param string|null $method The HTTP method to use for the health check.
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
* @param string|null $path The endpoint path to health check against.
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
* time, but will increase load on the origins as we check from multiple locations.
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
* as unhealthy. Retries are attempted immediately.
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
* a Host header by default. The User-Agent header cannot be overridden.
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
* 'HTTP' and 'HTTPS'.
* @param string|null $description Object description
*/
public function update($organization_identifier, $identifier, $expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
{
$data = [
'expected_body' => $expected_body,
'expected_codes' => $expected_codes,
'method' => $method,
'timeout' => $timeout,
'path' => $path,
'interval' => $interval,
'retries' => $retries,
'header' => $header,
'type' => $type,
'description' => $description,
];

return $this->patch('/organizations/'.$organization_identifier.'/load_balancers/monitors/'.$identifier, $data);
}

/**
* Delete a monitor
* Delete a configured monitor
*
* @param string $organization_identifier
* @param string $identifier
*/
public function delete_monitor($organization_identifier, $identifier)
{
return $this->delete('/organizations/'.$organization_identifier.'/load_balancers/monitors/'.$identifier);
}
}
116 changes: 116 additions & 0 deletions src/CloudFlare/Organizations/LoadBalancers/Pools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace Cloudflare\User\LoadBalancers;

use Cloudflare\Api;
use Cloudflare\Organizations;

/**
* CloudFlare API wrapper
*
* CTM Pool
* User-level Cloud Traffic Manager Pool
*
* @author James Bell <james@james-bell.co.uk>
*
* @version 1
*/
class Pools extends Api
{
/**
* List pools
* List configured pools
*
* @param string $organization_identifier
*/
public function pools($organization_identifier)
{
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/pools');
}

/**
* Create a pool
* Create a new pool
*
* @param string $organization_identifier
* @param string $name Object name
* @param array $origins A list of origins contained in the pool.
* Traffic destined to the pool is balanced across all
* available origins contained in the pool (as long as the pool
* is considered available).
* @param string|null $description Object description
* @param bool|null $enabled Whether this pool is enabled or not.
* @param string|null $monitor ID of the monitor object to use for monitoring the health
* status of origins inside this pool.
* @param string|null $notification_email ID of the notifier object to use for notifications relating
* to the health status of origins inside this pool.
*/
public function create($organization_identifier, $name, $origins, $description = null, $enabled = null, $monitor = null, $notification_email = null)
{
$data = [
'name' => $name,
'origins' => $origins,
'description' => $description,
'enabled' => $enabled,
'monitor' => $monitor,
'notification_email' => $notification_email,
];

return $this->post('/organizations/'.$organization_identifier.'/load_balancers/pools', $data);
}

/**
* Pool details
* Fetch a single configured pool
*
* @param string $organization_identifier
* @param string $identifier
*/
public function details($organization_identifier, $identifier)
{
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/pools/'.$identifier);
}

/**
* Modify a pool
* Modify a configured pool
*
* @param string $organization_identifier
* @param string $identifier
* @param string $name Object name
* @param array $origins A list of origins contained in the pool.
* Traffic destined to the pool is balanced across all
* available origins contained in the pool (as long as the pool
* is considered available).
* @param string|null $description Object description
* @param bool|null $enabled Whether this pool is enabled or not.
* @param string|null $monitor ID of the monitor object to use for monitoring the health
* status of origins inside this pool.
* @param string|null $notification_email ID of the notifier object to use for notifications relating
* to the health status of origins inside this pool.
*/
public function update($organization_identifier, $identifier, $name, $origins, $description = null, $enabled = null, $monitor = null, $notification_email = null)
{
$data = [
'name' => $name,
'origins' => $origins,
'description' => $description,
'enabled' => $enabled,
'monitor' => $monitor,
'notification_email' => $notification_email,
];

return $this->patch('/organizations/'.$organization_identifier.'/load_balancers/pools/'.$identifier, $data);
}

/**
* Delete a pool
* Delete a configured pool
*
* @param string $identifier
*/
public function delete_pool($organization_identifier, $identifier)
{
return $this->delete('/organizations/'.$organization_identifier.'/load_balancers/pools/'.$identifier);
}
}
62 changes: 35 additions & 27 deletions src/CloudFlare/User/LoadBalancers/Monitors.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,34 @@ public function monitors()
* Create a monitor
* Create a configured monitor
*
* @param string $expected A case-insensitive substring to match in the body of the probe
* @param string $expected_body A case-insensitive substring to match in the body of the probe
* response to declare an origin as up
* @param string $type Monitor type
* @param string $expected_codes The expected HTTP response code or code range for the probe
* @param string|null $method The HTTP method for the probe
* @param string|null $path The endpoint path to probe
* @param int|null $interval The interval in seconds for each PoP to send a probe request
* @param int|null $retries The number of retries before declaring the origins to be dead
* @param array|null $headers The HTTP headers to use in the probe
* @param int|null $probe_timeout Timeout in seconds for each probe request
* @param string|null $method The HTTP method to use for the health check.
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
* @param string|null $path The endpoint path to health check against.
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
* time, but will increase load on the origins as we check from multiple locations.
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
* as unhealthy. Retries are attempted immediately.
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
* a Host header by default. The User-Agent header cannot be overridden.
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
* 'HTTP' and 'HTTPS'.
* @param string|null $description Object description
*/
public function create($expected, $type, $expected_codes, $method = null, $path = null, $interval = null, $retries = null, $headers = null, $probe_timeout = null, $description = null)
public function create($expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
{
$data = [
'expected' => $expected,
'type' => $type,
'expected_body' => $expected_body,
'expected_codes' => $expected_codes,
'method' => $method,
'timeout' => $timeout,
'path' => $path,
'interval' => $interval,
'retries' => $retries,
'headers' => $headers,
'probe_timeout' => $probe_timeout,
'header' => $header,
'type' => $type,
'description' => $description,
];

Expand All @@ -76,30 +80,34 @@ public function details($identifier)
* Modify a configured monitor
*
* @param string $identifier
* @param string|null $expected A case-insensitive substring to match in the body of the probe
* @param string $expected_body A case-insensitive substring to match in the body of the probe
* response to declare an origin as up
* @param string|null $type Monitor type
* @param string|null $expected_codes The expected HTTP response code or code range for the probe
* @param string|null $method The HTTP method for the probe
* @param string|null $path The endpoint path to probe
* @param int|null $interval The interval in seconds for each PoP to send a probe request
* @param int|null $retries The number of retries before declaring the origins to be dead
* @param array|null $headers The HTTP headers to use in the probe
* @param int|null $probe_timeout Timeout in seconds for each probe request
* @param string $expected_codes The expected HTTP response code or code range for the probe
* @param string|null $method The HTTP method to use for the health check.
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
* @param string|null $path The endpoint path to health check against.
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
* time, but will increase load on the origins as we check from multiple locations.
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
* as unhealthy. Retries are attempted immediately.
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
* a Host header by default. The User-Agent header cannot be overridden.
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
* 'HTTP' and 'HTTPS'.
* @param string|null $description Object description
*/
public function update($identifier, $expected = null, $type = null, $expected_codes = null, $method = null, $path = null, $interval = null, $retries = null, $headers = null, $probe_timeout = null, $description = null)
public function update($identifier, $expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
{
$data = [
'expected' => $expected,
'type' => $type,
'expected_body' => $expected_body,
'expected_codes' => $expected_codes,
'method' => $method,
'timeout' => $timeout,
'path' => $path,
'interval' => $interval,
'retries' => $retries,
'headers' => $headers,
'probe_timeout' => $probe_timeout,
'header' => $header,
'type' => $type,
'description' => $description,
];

Expand Down

0 comments on commit 1ed918f

Please sign in to comment.