Certificates.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Cloudflare;
  3. /**
  4. * CloudFlare API wrapper
  5. *
  6. * CloudFlare CA
  7. * API to create CloudFlare-issued SSL certificates that can be installed on your origin server.
  8. * Use your Certificates API Key as your User Service Key when calling these endpoints
  9. * (see the section on request headers for details)
  10. *
  11. * @author James Bell <james@james-bell.co.uk>
  12. *
  13. * @version 1
  14. */
  15. class Certificates extends Api
  16. {
  17. /**
  18. * List Certificates
  19. * List all existing CloudFlare-issued Certificates for a given zone. Use your Certificates API Key as your
  20. * User Service Key when calling this endpoint
  21. */
  22. public function certificates($page = null, $per_page = null, $direction = null)
  23. {
  24. $data = [
  25. 'page' => $page,
  26. 'per_page' => $per_page,
  27. 'direction' => $direction,
  28. ];
  29. return $this->get('certificates', $data);
  30. }
  31. /**
  32. * Create Certificate
  33. * Create a CloudFlare-signed certificate. Use your Certificates API Key as your User Service Key when
  34. * calling this endpoint
  35. *
  36. * @param array $hostnames Array of hostnames or wildcard names (e.g., *.example.com) bound to the certificate
  37. * @param string $request_type Signature type desired on certificate ("origin-rsa" (rsa), "origin-ecc" (ecdsa), or "keyless-certificate" (for Keyless SSL servers)
  38. * @param string $csr The Certificate Signing Request (CSR). Must be newline-encoded.
  39. * @param int|null $requested_validity The number of days for which the certificate should be valid
  40. */
  41. public function create($hostnames, $request_type, $csr, $requested_validity = null)
  42. {
  43. $data = [
  44. 'hostnames' => $hostnames,
  45. 'request_type' => $request_type,
  46. 'csr' => $csr,
  47. 'requested_validity' => $requested_validity,
  48. ];
  49. return $this->post('certificates', $data);
  50. }
  51. /**
  52. * Certificate Details
  53. * Get an existing certificate by its serial number. Use your Certificates API Key as your User Service Key
  54. * when calling this endpoint
  55. *
  56. * @param string $identifier API item identifier tag
  57. */
  58. public function details($identifier)
  59. {
  60. return $this->get('certificates/'.$identifier);
  61. }
  62. /**
  63. * Revoke certificate
  64. * Revoke a created certificate for a zone. Use your Certificates API Key as your User Service Key when
  65. * calling this endpoint
  66. *
  67. * @param string $identifier API item identifier tag
  68. */
  69. public function revoke($identifier)
  70. {
  71. return $this->delete('certificates/'.$identifier);
  72. }
  73. }