1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2021. Plesk International GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
|
6
|
|
|
use PleskX\Api\Struct\SecretKey as Struct; |
7
|
|
|
|
8
|
|
|
class SecretKey extends \PleskX\Api\Operator |
9
|
|
|
{ |
10
|
|
|
protected $_wrapperTag = 'secret_key'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param string $ipAddress |
14
|
|
|
* @param string $description |
15
|
|
|
* |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
public function create($ipAddress = '', $description = '') |
19
|
|
|
{ |
20
|
|
|
$packet = $this->_client->getPacket(); |
21
|
|
|
$createTag = $packet->addChild($this->_wrapperTag)->addChild('create'); |
22
|
|
|
|
23
|
|
|
if ('' !== $ipAddress) { |
24
|
|
|
$createTag->addChild('ip_address', $ipAddress); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
if ('' !== $description) { |
28
|
|
|
$createTag->addChild('description', $description); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$response = $this->_client->request($packet); |
32
|
|
|
|
33
|
|
|
return (string) $response->key; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $keyId |
38
|
|
|
* |
39
|
|
|
* @return bool |
40
|
|
|
*/ |
41
|
|
|
public function delete($keyId) |
42
|
|
|
{ |
43
|
|
|
return $this->_delete('key', $keyId, 'delete'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $keyId |
48
|
|
|
* |
49
|
|
|
* @return Struct\Info |
50
|
|
|
*/ |
51
|
|
|
public function get($keyId) |
52
|
|
|
{ |
53
|
|
|
$items = $this->_get($keyId); |
54
|
|
|
|
55
|
|
|
return reset($items); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return Struct\Info[] |
60
|
|
|
*/ |
61
|
|
|
public function getAll() |
62
|
|
|
{ |
63
|
|
|
return $this->_get(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string|null $keyId |
68
|
|
|
* |
69
|
|
|
* @return Struct\Info[] |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function _get($keyId = null) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$packet = $this->_client->getPacket(); |
74
|
|
|
$getTag = $packet->addChild($this->_wrapperTag)->addChild('get_info'); |
75
|
|
|
|
76
|
|
|
$filterTag = $getTag->addChild('filter'); |
77
|
|
|
if (!is_null($keyId)) { |
78
|
|
|
$filterTag->addChild('key', $keyId); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
82
|
|
|
|
83
|
|
|
$items = []; |
84
|
|
|
foreach ($response->xpath('//result/key_info') as $keyInfo) { |
85
|
|
|
$items[] = new Struct\Info($keyInfo); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $items; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|