1
|
|
|
<?php declare (strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace OpenStack\Compute\v2\Models; |
4
|
|
|
|
5
|
|
|
use OpenCloud\Common\Resource\Creatable; |
6
|
|
|
use OpenCloud\Common\Resource\OperatorResource; |
7
|
|
|
use OpenCloud\Common\Resource\Deletable; |
8
|
|
|
use OpenCloud\Common\Resource\Listable; |
9
|
|
|
use OpenCloud\Common\Resource\Retrievable; |
10
|
|
|
use OpenCloud\Common\Transport\Utils; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Represents a Compute v2 Keypair |
14
|
|
|
* |
15
|
|
|
* @property \OpenStack\Compute\v2\Api $api |
16
|
|
|
*/ |
17
|
|
|
class Keypair extends OperatorResource implements Listable, Retrievable, Deletable, Creatable |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** @var string */ |
20
|
|
|
public $fingerprint; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
public $name; |
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
public $publicKey; |
27
|
|
|
|
28
|
|
|
/** @var boolean */ |
29
|
|
|
public $deleted; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
public $userId; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
public $id; |
36
|
|
|
|
37
|
|
|
/** @var \DateTimeImmutable */ |
38
|
|
|
public $createdAt; |
39
|
|
|
|
40
|
|
|
protected $aliases = [ |
41
|
|
|
'public_key' => 'publicKey', |
42
|
|
|
'user_id' => 'userId', |
43
|
|
|
'created_at' => 'createdAt', |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
protected $resourceKey = 'keypair'; |
47
|
|
|
protected $resourcesKey = 'keypairs'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritDoc} |
51
|
|
|
*/ |
52
|
|
|
public function retrieve() |
53
|
|
|
{ |
54
|
|
|
$response = $this->execute($this->api->getKeypair(), ['name' => (string) $this->name]); |
55
|
|
|
$this->populateFromResponse($response); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function create(array $userOptions): Creatable |
59
|
|
|
{ |
60
|
|
|
$response = $this->execute($this->api->postKeypair(), $userOptions); |
61
|
|
|
return $this->populateFromResponse($response); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
|
|
public function populateFromArray(array $array): self |
68
|
|
|
{ |
69
|
|
|
return parent::populateFromArray(Utils::flattenJson($array, $this->resourceKey)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritDoc} |
74
|
|
|
*/ |
75
|
|
|
public function delete() |
76
|
|
|
{ |
77
|
|
|
$this->execute($this->api->deleteKeypair(), ['name' => (string) $this->name]); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|