1: <?php
2:
3: namespace Cloudflare\Zone;
4:
5: use Cloudflare\Api;
6: use Cloudflare\Zone;
7:
8: /**
9: * CloudFlare API wrapper
10: *
11: * Custom SSL for a Zone
12: *
13: * @author James Bell <[email protected]>
14: *
15: * @version 1
16: */
17: class CustomSSL extends Api
18: {
19: /**
20: * Default permissions level
21: *
22: * @var array
23: */
24: protected $permission_level = ['read' => '#ssl:read', 'edit' => '#ssl:edit'];
25:
26: /**
27: * List SSL configurations (permission needed: #ssl:edit)
28: * List, search, sort, and filter all of your custom SSL certificates
29: *
30: * @param string $zone_identifier API item identifier tag
31: * @param string|null $status Status of the zone's custom SSL
32: * @param int|null $page Page number of paginated results
33: * @param int|null $per_page Number of zones per page
34: * @param string|null $order Field to order certificates by (status, issuer, priority, expires_on)
35: * @param string|null $direction Direction to order domains (asc, desc)
36: * @param string|null $match Whether to match all search requirements or at least one (any) (any, all)
37: */
38: public function list_certificates($zone_identifier, $status = null, $page = null, $per_page = null, $order = null, $direction = null, $match = null)
39: {
40: $data = [
41: 'status' => $status,
42: 'page' => $page,
43: 'per_page' => $per_page,
44: 'order' => $order,
45: 'direction' => $direction,
46: 'match' => $match,
47: ];
48:
49: return $this->get('zones/'.$zone_identifier.'/custom_certificates', $data);
50: }
51:
52: /**
53: * Create SSL configuration (permission needed: #ssl:edit)
54: * Upload a new SSL certificate for a zone
55: *
56: * @param string $zone_identifier API item identifier tag
57: * @param string $certificate The zone's private key
58: * @param string $private_key The zone's SSL certificate or certificate and the intermediate(s)
59: * @param string|null $bundle_method A ubiquitous bundle is a bundle that has a higher probability of being verified everywhere,
60: * even by clients using outdated or unusual trust stores. An optimal bundle is a bundle with the shortest chain and newest
61: * intermediates. A forced method attempt to use the certificate/chain as defined by the input "ubiquitous"
62: */
63: public function create($zone_identifier, $certificate, $private_key, $bundle_method = null)
64: {
65: $data = [
66: 'certificate' => $certificate,
67: 'private_key' => $private_key,
68: 'bundle_method' => $bundle_method,
69: ];
70:
71: return $this->post('zones/'.$zone_identifier.'/custom_certificates', $data);
72: }
73:
74: /**
75: * SSL configuration details (permission needed: #ssl:read)
76: *
77: * @param string $zone_identifier API item identifier tag
78: * @param string $identifier
79: */
80: public function details($zone_identifier, $identifier)
81: {
82: return $this->get('zones/'.$zone_identifier.'/custom_certificates/'.$identifier);
83: }
84:
85: /**
86: * Create a Keyless SSL configuration (permission needed: #ssl:edit)
87: *
88: * @param string $zone_identifier API item identifier tag
89: * @param string $identifier
90: * @param string $private_key The zone's SSL certificate or certificate and the intermediate(s)
91: * @param string $certificate The zone's private key
92: * @param string|null $bundle_method A ubiquitous bundle is a bundle that has a higher probability of being verified everywhere,
93: * even by clients using outdated or unusual trust stores. An optimal bundle is a bundle with the shortest chain and newest
94: * intermediates. A forced method attempt to use the certificate/chain as defined by the input "ubiquitous"
95: */
96: public function update($zone_identifier, $identifier, $private_key, $certificate, $bundle_method = null)
97: {
98: $data = [
99: 'certificate' => $certificate,
100: 'private_key' => $private_key,
101: 'bundle_method' => $bundle_method,
102: ];
103:
104: return $this->patch('zones/'.$zone_identifier.'/custom_certificates/'.$identifier, $data);
105: }
106:
107: /**
108: * Re-prioritize SSL certificates (permission needed: #ssl:edit)
109: * If a zone has multiple SSL certificates, you can set the order in which they should be used during a request.
110: *
111: * @param string $zone_identifier API item identifier tag
112: * @param array $certificates Array of ordered certificates.
113: */
114: public function prioritize($zone_identifier, array $certificates)
115: {
116: $data = [
117: 'certificates' => $certificates,
118: ];
119:
120: return $this->put('zones/'.$zone_identifier.'/custom_certificates/prioritize'.$identifier, $data);
121: }
122:
123: /**
124: * Delete an SSL certificate (permission needed: #ssl:edit)
125: *
126: * @param string $zone_identifier API item identifier tag
127: * @param string $identifier
128: */
129: public function delete_ssl($zone_identifier, $identifier)
130: {
131: return $this->delete('zones/'.$zone_identifier.'/custom_certificates/'.$identifier);
132: }
133: }
134: