|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// --------------------------------------------------------------------- |
|
4
|
|
|
// |
|
5
|
|
|
// Copyright (C) 2018-2024 Artem Rodygin |
|
6
|
|
|
// |
|
7
|
|
|
// You should have received a copy of the MIT License along with |
|
8
|
|
|
// this file. If not, see <https://opensource.org/licenses/MIT>. |
|
9
|
|
|
// |
|
10
|
|
|
// --------------------------------------------------------------------- |
|
11
|
|
|
|
|
12
|
|
|
namespace Linode\Managed\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Linode\Entity; |
|
15
|
|
|
use Linode\Internal\AbstractRepository; |
|
16
|
|
|
use Linode\Managed\ManagedCredential; |
|
17
|
|
|
use Linode\Managed\ManagedCredentialRepositoryInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @codeCoverageIgnore This class was autogenerated. |
|
21
|
|
|
*/ |
|
22
|
|
|
class ManagedCredentialRepository extends AbstractRepository implements ManagedCredentialRepositoryInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function createManagedCredential(array $parameters = []): ManagedCredential |
|
25
|
|
|
{ |
|
26
|
|
|
$response = $this->client->post($this->getBaseUri(), $parameters); |
|
27
|
|
|
$contents = $response->getBody()->getContents(); |
|
28
|
|
|
$json = json_decode($contents, true); |
|
29
|
|
|
|
|
30
|
|
|
return new ManagedCredential($this->client, $json); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function updateManagedCredential(int $credentialId, array $parameters = []): ManagedCredential |
|
34
|
|
|
{ |
|
35
|
|
|
$response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $credentialId), $parameters); |
|
36
|
|
|
$contents = $response->getBody()->getContents(); |
|
37
|
|
|
$json = json_decode($contents, true); |
|
38
|
|
|
|
|
39
|
|
|
return new ManagedCredential($this->client, $json); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function updateManagedCredentialUsernamePassword(int $credentialId, ?string $username, string $password): void |
|
43
|
|
|
{ |
|
44
|
|
|
$parameters = [ |
|
45
|
|
|
'username' => $username, |
|
46
|
|
|
'password' => $password, |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
$this->client->post(sprintf('%s/%s/update', $this->getBaseUri(), $credentialId), $parameters); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function deleteManagedCredential(int $credentialId): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->client->post(sprintf('%s/%s/revoke', $this->getBaseUri(), $credentialId)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function viewManagedSSHKey(): string |
|
58
|
|
|
{ |
|
59
|
|
|
$response = $this->client->get(sprintf('%s/sshkey', $this->getBaseUri())); |
|
60
|
|
|
$contents = $response->getBody()->getContents(); |
|
61
|
|
|
$json = json_decode($contents, true); |
|
62
|
|
|
|
|
63
|
|
|
return $json['ssh_key']; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function getBaseUri(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return '/managed/credentials'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function getSupportedFields(): array |
|
72
|
|
|
{ |
|
73
|
|
|
return [ |
|
74
|
|
|
ManagedCredential::FIELD_ID, |
|
75
|
|
|
ManagedCredential::FIELD_LABEL, |
|
76
|
|
|
ManagedCredential::FIELD_LAST_DECRYPTED, |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function jsonToEntity(array $json): Entity |
|
81
|
|
|
{ |
|
82
|
|
|
return new ManagedCredential($this->client, $json); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|