Skip to content

Commit

Permalink
Merge pull request #515 from ans-group/mdr-696-add-dcv-functionality
Browse files Browse the repository at this point in the history
Mdr 696 add dcv functionality
  • Loading branch information
phily245 authored May 9, 2023
2 parents cb9dc81 + a66487c commit 8240c42
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/SSL/DcvClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';

/**
Expand All @@ -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));
}
}
13 changes: 13 additions & 0 deletions src/SSL/Entities/Dcv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace UKFast\SDK\SSL\Entities;

use UKFast\SDK\Entity;

/**
* @property string[] $hostnames
*/
class Dcv extends Entity
{
//
}

0 comments on commit 8240c42

Please sign in to comment.