diff --git a/src/SSL/DcvClient.php b/src/SSL/DcvClient.php index b1756183..0e956e21 100644 --- a/src/SSL/DcvClient.php +++ b/src/SSL/DcvClient.php @@ -5,9 +5,12 @@ use UKFast\SDK\Client as BaseClient; use UKFast\SDK\Exception\ApiException; use UKFast\SDK\SSL\Entities\Certificate; +use UKFast\SDK\SSL\Entities\Dcv; class DcvClient extends BaseClient { + const MAP = []; + protected $basePath = 'ssl/'; /** @@ -19,9 +22,33 @@ class DcvClient extends BaseClient */ public function validate(Certificate $certificate) { - $url = 'v1/dcv/' . urlencode($certificate->id) . '/validate'; - $this->post($url); + $body = null; + $hostnames = []; + + if (empty($certificate->commonName) === false) { + $hostnames[] = $certificate->commonName; + } + + if (is_array($certificate->alternativeNames) && empty($certificate->alternativeNames) === false) { + $hostnames[] = array_merge($hostnames, $certificate->alternativeNames); + } + + if (empty($hostnames) === false) { + $body = json_encode([ + 'hostnames' => $hostnames, + ]); + } + + $this->post('v1/dcv/' . urlencode($certificate->id) . '/validate', $body); return true; } + + public function getHostnames(Certificate $certificate) + { + $response = $this->get('v1/dcv/' . urlencode($certificate->id) . '/hostnames'); + $body = $this->decodeJson($response->getBody()->getContents()); + + return new Dcv($this->apiToFriendly($body->data, static::MAP)); + } } diff --git a/src/SSL/Entities/Dcv.php b/src/SSL/Entities/Dcv.php new file mode 100644 index 00000000..bf7053c2 --- /dev/null +++ b/src/SSL/Entities/Dcv.php @@ -0,0 +1,13 @@ +