1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DigitalOceanV2 library. |
5
|
|
|
* |
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DigitalOceanV2\Api; |
13
|
|
|
|
14
|
|
|
use DigitalOceanV2\Entity\Certificate as CertificateEntity; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Jacob Holmes <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Certificate extends AbstractApi |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return CertificateEntity[] |
23
|
|
|
*/ |
24
|
|
|
public function getAll() |
25
|
|
|
{ |
26
|
|
|
$certificates = $this->adapter->get(sprintf('%s/certificates', $this->endpoint, 200)); |
27
|
|
|
|
28
|
|
|
$certificates = json_decode($certificates); |
29
|
|
|
|
30
|
|
|
$this->extractMeta($certificates); |
31
|
|
|
|
32
|
|
|
return array_map(function ($certificates) { |
33
|
|
|
return new CertificateEntity($certificates); |
34
|
|
|
}, $certificates->certificates); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $id |
39
|
|
|
* |
40
|
|
|
* @throws HttpException |
41
|
|
|
* |
42
|
|
|
* @return CertificateEntity |
43
|
|
|
*/ |
44
|
|
|
public function getById($id) |
45
|
|
|
{ |
46
|
|
|
$certificate = $this->adapter->get(sprintf('%s/certificates/%s', $this->endpoint, $id)); |
47
|
|
|
|
48
|
|
|
$certificate = json_decode($certificate); |
49
|
|
|
|
50
|
|
|
return new CertificateEntity($certificate->certificate); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $name |
55
|
|
|
* @param string $privateKey |
56
|
|
|
* @param string $leafCertificate |
57
|
|
|
* @param string $certificateChain |
58
|
|
|
* |
59
|
|
|
* @throws HttpException |
60
|
|
|
* |
61
|
|
|
* @return CertificateEntity |
62
|
|
|
*/ |
63
|
|
|
public function create($name, $privateKey, $leafCertificate, $certificateChain) |
64
|
|
|
{ |
65
|
|
|
$data = [ |
66
|
|
|
'name' => $name, |
67
|
|
|
'private_key' => $privateKey, |
68
|
|
|
'leaf_certificate' => $leafCertificate, |
69
|
|
|
'certificate_chain' => $certificateChain, |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
$certificate = $this->adapter->post(sprintf('%s/certificates', $this->endpoint), $data); |
73
|
|
|
|
74
|
|
|
$certificate = json_decode($certificate); |
75
|
|
|
|
76
|
|
|
return new CertificateEntity($certificate->certificate); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $id |
81
|
|
|
* |
82
|
|
|
* @throws HttpException |
83
|
|
|
*/ |
84
|
|
|
public function delete($id) |
85
|
|
|
{ |
86
|
|
|
$this->adapter->delete(sprintf('%s/certificates/%s', $this->endpoint, $id)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|