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