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

Commit 1ed918f

Browse files
committed
Updated Load Balancer methods to match final API documentation
1 parent 0af7a7a commit 1ed918f

6 files changed

Lines changed: 363 additions & 82 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jamesryanbell/cloudflare",
33
"description": "CloudFlare API - PHP",
44
"license": "MIT",
5-
"version": "1.9.0",
5+
"version": "1.10.0",
66
"keywords": ["cloudflare", "api"],
77
"authors": [
88
{
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
namespace Cloudflare\User\LoadBalancers;
4+
5+
use Cloudflare\Api;
6+
use Cloudflare\Organizations;
7+
8+
/**
9+
* CloudFlare API wrapper
10+
*
11+
* CTM Monitors
12+
* Cloud Traffic Manager Monitor
13+
*
14+
* @author James Bell <james@james-bell.co.uk>
15+
*
16+
* @version 1
17+
*/
18+
class Monitors extends Api
19+
{
20+
/**
21+
* List monitors
22+
* List configured monitors for a user
23+
*
24+
* @param string $organization_identifier
25+
*/
26+
public function monitors($organization_identifier)
27+
{
28+
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/monitors');
29+
}
30+
31+
/**
32+
* Create a monitor
33+
* Create a configured monitor
34+
*
35+
* @param string $organization_identifier
36+
* @param string $expected_body A case-insensitive substring to match in the body of the probe
37+
* response to declare an origin as up
38+
* @param string $expected_codes The expected HTTP response code or code range for the probe
39+
* @param string|null $method The HTTP method to use for the health check.
40+
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
41+
* @param string|null $path The endpoint path to health check against.
42+
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
43+
* time, but will increase load on the origins as we check from multiple locations.
44+
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
45+
* as unhealthy. Retries are attempted immediately.
46+
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
47+
* a Host header by default. The User-Agent header cannot be overridden.
48+
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
49+
* 'HTTP' and 'HTTPS'.
50+
* @param string|null $description Object description
51+
*/
52+
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)
53+
{
54+
$data = [
55+
'expected_body' => $expected_body,
56+
'expected_codes' => $expected_codes,
57+
'method' => $method,
58+
'timeout' => $timeout,
59+
'path' => $path,
60+
'interval' => $interval,
61+
'retries' => $retries,
62+
'header' => $header,
63+
'type' => $type,
64+
'description' => $description,
65+
];
66+
67+
return $this->post('/organizations/'.$organization_identifier.'/load_balancers/monitors', $data);
68+
}
69+
70+
/**
71+
* Monitor details
72+
* List a single configured CTM monitor for a user
73+
*
74+
* @param string $organization_identifier
75+
* @param string $identifier
76+
*/
77+
public function details($organization_identifier, $identifier)
78+
{
79+
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/monitors/'.$identifier);
80+
}
81+
82+
/**
83+
* Modify a monitor
84+
* Modify a configured monitor
85+
*
86+
* @param string $organization_identifier
87+
* @param string $identifier
88+
* @param string $expected_body A case-insensitive substring to match in the body of the probe
89+
* response to declare an origin as up
90+
* @param string $expected_codes The expected HTTP response code or code range for the probe
91+
* @param string|null $method The HTTP method to use for the health check.
92+
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
93+
* @param string|null $path The endpoint path to health check against.
94+
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
95+
* time, but will increase load on the origins as we check from multiple locations.
96+
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
97+
* as unhealthy. Retries are attempted immediately.
98+
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
99+
* a Host header by default. The User-Agent header cannot be overridden.
100+
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
101+
* 'HTTP' and 'HTTPS'.
102+
* @param string|null $description Object description
103+
*/
104+
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)
105+
{
106+
$data = [
107+
'expected_body' => $expected_body,
108+
'expected_codes' => $expected_codes,
109+
'method' => $method,
110+
'timeout' => $timeout,
111+
'path' => $path,
112+
'interval' => $interval,
113+
'retries' => $retries,
114+
'header' => $header,
115+
'type' => $type,
116+
'description' => $description,
117+
];
118+
119+
return $this->patch('/organizations/'.$organization_identifier.'/load_balancers/monitors/'.$identifier, $data);
120+
}
121+
122+
/**
123+
* Delete a monitor
124+
* Delete a configured monitor
125+
*
126+
* @param string $organization_identifier
127+
* @param string $identifier
128+
*/
129+
public function delete_monitor($organization_identifier, $identifier)
130+
{
131+
return $this->delete('/organizations/'.$organization_identifier.'/load_balancers/monitors/'.$identifier);
132+
}
133+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
namespace Cloudflare\User\LoadBalancers;
4+
5+
use Cloudflare\Api;
6+
use Cloudflare\Organizations;
7+
8+
/**
9+
* CloudFlare API wrapper
10+
*
11+
* CTM Pool
12+
* User-level Cloud Traffic Manager Pool
13+
*
14+
* @author James Bell <james@james-bell.co.uk>
15+
*
16+
* @version 1
17+
*/
18+
class Pools extends Api
19+
{
20+
/**
21+
* List pools
22+
* List configured pools
23+
*
24+
* @param string $organization_identifier
25+
*/
26+
public function pools($organization_identifier)
27+
{
28+
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/pools');
29+
}
30+
31+
/**
32+
* Create a pool
33+
* Create a new pool
34+
*
35+
* @param string $organization_identifier
36+
* @param string $name Object name
37+
* @param array $origins A list of origins contained in the pool.
38+
* Traffic destined to the pool is balanced across all
39+
* available origins contained in the pool (as long as the pool
40+
* is considered available).
41+
* @param string|null $description Object description
42+
* @param bool|null $enabled Whether this pool is enabled or not.
43+
* @param string|null $monitor ID of the monitor object to use for monitoring the health
44+
* status of origins inside this pool.
45+
* @param string|null $notification_email ID of the notifier object to use for notifications relating
46+
* to the health status of origins inside this pool.
47+
*/
48+
public function create($organization_identifier, $name, $origins, $description = null, $enabled = null, $monitor = null, $notification_email = null)
49+
{
50+
$data = [
51+
'name' => $name,
52+
'origins' => $origins,
53+
'description' => $description,
54+
'enabled' => $enabled,
55+
'monitor' => $monitor,
56+
'notification_email' => $notification_email,
57+
];
58+
59+
return $this->post('/organizations/'.$organization_identifier.'/load_balancers/pools', $data);
60+
}
61+
62+
/**
63+
* Pool details
64+
* Fetch a single configured pool
65+
*
66+
* @param string $organization_identifier
67+
* @param string $identifier
68+
*/
69+
public function details($organization_identifier, $identifier)
70+
{
71+
return $this->get('/organizations/'.$organization_identifier.'/load_balancers/pools/'.$identifier);
72+
}
73+
74+
/**
75+
* Modify a pool
76+
* Modify a configured pool
77+
*
78+
* @param string $organization_identifier
79+
* @param string $identifier
80+
* @param string $name Object name
81+
* @param array $origins A list of origins contained in the pool.
82+
* Traffic destined to the pool is balanced across all
83+
* available origins contained in the pool (as long as the pool
84+
* is considered available).
85+
* @param string|null $description Object description
86+
* @param bool|null $enabled Whether this pool is enabled or not.
87+
* @param string|null $monitor ID of the monitor object to use for monitoring the health
88+
* status of origins inside this pool.
89+
* @param string|null $notification_email ID of the notifier object to use for notifications relating
90+
* to the health status of origins inside this pool.
91+
*/
92+
public function update($organization_identifier, $identifier, $name, $origins, $description = null, $enabled = null, $monitor = null, $notification_email = null)
93+
{
94+
$data = [
95+
'name' => $name,
96+
'origins' => $origins,
97+
'description' => $description,
98+
'enabled' => $enabled,
99+
'monitor' => $monitor,
100+
'notification_email' => $notification_email,
101+
];
102+
103+
return $this->patch('/organizations/'.$organization_identifier.'/load_balancers/pools/'.$identifier, $data);
104+
}
105+
106+
/**
107+
* Delete a pool
108+
* Delete a configured pool
109+
*
110+
* @param string $identifier
111+
*/
112+
public function delete_pool($organization_identifier, $identifier)
113+
{
114+
return $this->delete('/organizations/'.$organization_identifier.'/load_balancers/pools/'.$identifier);
115+
}
116+
}

src/CloudFlare/User/LoadBalancers/Monitors.php

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,34 @@ public function monitors()
3030
* Create a monitor
3131
* Create a configured monitor
3232
*
33-
* @param string $expected A case-insensitive substring to match in the body of the probe
33+
* @param string $expected_body A case-insensitive substring to match in the body of the probe
3434
* response to declare an origin as up
35-
* @param string $type Monitor type
3635
* @param string $expected_codes The expected HTTP response code or code range for the probe
37-
* @param string|null $method The HTTP method for the probe
38-
* @param string|null $path The endpoint path to probe
39-
* @param int|null $interval The interval in seconds for each PoP to send a probe request
40-
* @param int|null $retries The number of retries before declaring the origins to be dead
41-
* @param array|null $headers The HTTP headers to use in the probe
42-
* @param int|null $probe_timeout Timeout in seconds for each probe request
36+
* @param string|null $method The HTTP method to use for the health check.
37+
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
38+
* @param string|null $path The endpoint path to health check against.
39+
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
40+
* time, but will increase load on the origins as we check from multiple locations.
41+
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
42+
* as unhealthy. Retries are attempted immediately.
43+
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
44+
* a Host header by default. The User-Agent header cannot be overridden.
45+
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
46+
* 'HTTP' and 'HTTPS'.
4347
* @param string|null $description Object description
4448
*/
45-
public function create($expected, $type, $expected_codes, $method = null, $path = null, $interval = null, $retries = null, $headers = null, $probe_timeout = null, $description = null)
49+
public function create($expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
4650
{
4751
$data = [
48-
'expected' => $expected,
49-
'type' => $type,
52+
'expected_body' => $expected_body,
5053
'expected_codes' => $expected_codes,
5154
'method' => $method,
55+
'timeout' => $timeout,
5256
'path' => $path,
5357
'interval' => $interval,
5458
'retries' => $retries,
55-
'headers' => $headers,
56-
'probe_timeout' => $probe_timeout,
59+
'header' => $header,
60+
'type' => $type,
5761
'description' => $description,
5862
];
5963

@@ -76,30 +80,34 @@ public function details($identifier)
7680
* Modify a configured monitor
7781
*
7882
* @param string $identifier
79-
* @param string|null $expected A case-insensitive substring to match in the body of the probe
83+
* @param string $expected_body A case-insensitive substring to match in the body of the probe
8084
* response to declare an origin as up
81-
* @param string|null $type Monitor type
82-
* @param string|null $expected_codes The expected HTTP response code or code range for the probe
83-
* @param string|null $method The HTTP method for the probe
84-
* @param string|null $path The endpoint path to probe
85-
* @param int|null $interval The interval in seconds for each PoP to send a probe request
86-
* @param int|null $retries The number of retries before declaring the origins to be dead
87-
* @param array|null $headers The HTTP headers to use in the probe
88-
* @param int|null $probe_timeout Timeout in seconds for each probe request
85+
* @param string $expected_codes The expected HTTP response code or code range for the probe
86+
* @param string|null $method The HTTP method to use for the health check.
87+
* @param int|null $timeout The timeout (in seconds) before marking the health check as failed
88+
* @param string|null $path The endpoint path to health check against.
89+
* @param int|null $interval The interval between each health check. Shorter intervals may improve failover
90+
* time, but will increase load on the origins as we check from multiple locations.
91+
* @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin
92+
* as unhealthy. Retries are attempted immediately.
93+
* @param array|null $header The HTTP request headers to send in the health check. It is recommended you set
94+
* a Host header by default. The User-Agent header cannot be overridden.
95+
* @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are
96+
* 'HTTP' and 'HTTPS'.
8997
* @param string|null $description Object description
9098
*/
91-
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)
99+
public function update($identifier, $expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null)
92100
{
93101
$data = [
94-
'expected' => $expected,
95-
'type' => $type,
102+
'expected_body' => $expected_body,
96103
'expected_codes' => $expected_codes,
97104
'method' => $method,
105+
'timeout' => $timeout,
98106
'path' => $path,
99107
'interval' => $interval,
100108
'retries' => $retries,
101-
'headers' => $headers,
102-
'probe_timeout' => $probe_timeout,
109+
'header' => $header,
110+
'type' => $type,
103111
'description' => $description,
104112
];
105113

0 commit comments

Comments
 (0)