-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathCertificate.php
More file actions
159 lines (144 loc) · 3.86 KB
/
Certificate.php
File metadata and controls
159 lines (144 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Created by PhpStorm.
* User: lukaskammerling
* Date: 28.01.18
* Time: 21:00.
*/
namespace LKDev\HetznerCloud\Models\Certificates;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Contracts\Resource;
use LKDev\HetznerCloud\Models\Model;
class Certificate extends Model implements Resource
{
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $certificate;
/**
* @var string
*/
public $created;
/**
* @var string
*/
public $not_valid_before;
/**
* @var string
*/
public $not_valid_after;
/**
* @var array
*/
public $domain_names;
/**
* @var string
*/
public $fingerprint;
/**
* @var \stdClass
*/
public $used_by;
/**
* @var array
*/
public $labels;
/**
* @var string
*/
public $type;
/**
* Certificate constructor.
*
* @param int $id
* @param string|null $name
* @param string|null $certificate
* @param string|null $created
* @param string|null $not_valid_before
* @param string|null $not_valid_after
* @param array|null $domain_names
* @param string|null $fingerprint
* @param array|null $used_by
* @param array|null $labels
* @param string|null $type
*/
public function __construct(int $id, ?string $name = null, ?string $certificate = null, ?string $created = null, ?string $not_valid_before = null, ?string $not_valid_after = null, ?array $domain_names = null, ?string $fingerprint = null, $used_by = null, $labels = [], ?string $type = null)
{
$this->id = $id;
$this->name = $name;
$this->certificate = $certificate;
$this->created = $created;
$this->not_valid_before = $not_valid_before;
$this->not_valid_after = $not_valid_after;
$this->domain_names = $domain_names;
$this->fingerprint = $fingerprint;
$this->used_by = $used_by;
$this->labels = $labels;
$this->type = $type;
parent::__construct();
}
/**
* Update a ssh key.
*
* @see https://docs.hetzner.cloud/#resources-certificates-put
*
* @param array $data
* @return \LKDev\HetznerCloud\Models\Certificates\Certificate|null
*
* @throws \LKDev\HetznerCloud\APIException
*/
public function update(array $data): ?self
{
$response = $this->httpClient->put('certificates/'.$this->id, [
'json' => $data,
]);
if (! HetznerAPIClient::hasError($response)) {
return self::parse(json_decode((string) $response->getBody())->certificate);
}
return null;
}
/**
* Deletes a SSH key. It cannot be used anymore.
*
* @see https://docs.hetzner.cloud/#resources-certificates-delete
*
* @return bool
*
* @throws \LKDev\HetznerCloud\APIException
*/
public function delete(): bool
{
$response = $this->httpClient->delete('certificates/'.$this->id);
if (! HetznerAPIClient::hasError($response)) {
return true;
}
return false;
}
/**
* @param $input
* @return \LKDev\HetznerCloud\Models\Certificates\Certificate|static
*/
public static function parse($input)
{
return new self($input->id, $input->name, $input->certificate, $input->created, $input->not_valid_before, $input->not_valid_after, $input->domain_names, $input->fingerprint, $input->used_by, $input->labels, $input->type ?? null);
}
/**
* Reload the data of the SSH Key.
*
* @return Certificate
*
* @throws \LKDev\HetznerCloud\APIException
*/
public function reload()
{
return HetznerAPIClient::$instance->certificates()->get($this->id);
}
}