|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the bitbucket-api package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Alexandru G. <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Bitbucket\API\Users; |
|
13
|
|
|
|
|
14
|
|
|
use Bitbucket\API\Api; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Manipulate the ssh-keys on an individual or team account. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Alexandru G. <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class SshKeys extends Api |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Gets a list of the keys associated with an account. |
|
26
|
|
|
* |
|
27
|
|
|
* @access public |
|
28
|
|
|
* @param string $account The name of an individual or team account. |
|
29
|
|
|
* @return ResponseInterface |
|
30
|
|
|
*/ |
|
31
|
1 |
|
public function all($account) |
|
32
|
|
|
{ |
|
33
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
|
34
|
1 |
|
sprintf('/users/%s/ssh-keys', $account) |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Create a key on the specified account. |
|
40
|
|
|
* |
|
41
|
|
|
* @access public |
|
42
|
|
|
* @param string $account The name of an individual or team account. |
|
43
|
|
|
* @param string $key The key value. |
|
44
|
|
|
* @param string $label A label for the key. (optional) |
|
45
|
|
|
* @return ResponseInterface |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function create($account, $key, $label = null) |
|
48
|
|
|
{ |
|
49
|
1 |
|
$params = array('key' => $key); |
|
50
|
|
|
|
|
51
|
1 |
|
if (!is_null($label)) { |
|
52
|
1 |
|
$params['label'] = $label; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->post( |
|
56
|
1 |
|
sprintf('/users/%s/ssh-keys', $account), |
|
57
|
1 |
|
$params |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Updates a key on the specified account. |
|
63
|
|
|
* |
|
64
|
|
|
* @access public |
|
65
|
|
|
* @param string $account The name of an individual or team account. |
|
66
|
|
|
* @param int $keyId Key identifier. |
|
67
|
|
|
* @param string $key The key value. |
|
68
|
|
|
* @return ResponseInterface |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function update($account, $keyId, $key) |
|
71
|
|
|
{ |
|
72
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->put( |
|
73
|
1 |
|
sprintf('/users/%s/ssh-keys/%d', $account, $keyId), |
|
74
|
1 |
|
array('key' => $key) |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Gets the content of the specified keyId. |
|
80
|
|
|
* |
|
81
|
|
|
* @access public |
|
82
|
|
|
* @param string $account The name of an individual or team account. |
|
83
|
|
|
* @param int $keyId Key identifier. |
|
84
|
|
|
* @return ResponseInterface |
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function get($account, $keyId) |
|
87
|
|
|
{ |
|
88
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
|
89
|
1 |
|
sprintf('/users/%s/ssh-keys/%d', $account, $keyId) |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Deletes the key specified by the keyId value |
|
95
|
|
|
* |
|
96
|
|
|
* @access public |
|
97
|
|
|
* @param string $account The name of an individual or team account. |
|
98
|
|
|
* @param int $keyId Key identifier. |
|
99
|
|
|
* @return ResponseInterface |
|
100
|
|
|
*/ |
|
101
|
1 |
|
public function delete($account, $keyId) |
|
102
|
|
|
{ |
|
103
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->delete( |
|
104
|
1 |
|
sprintf('/users/%s/ssh-keys/%d', $account, $keyId) |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|