|
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\Repositories; |
|
13
|
|
|
|
|
14
|
|
|
use Bitbucket\API; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Manage ssh keys used for deploying product builds. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Alexandru G. <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class Deploykeys extends API\Api |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Get a list of keys |
|
26
|
|
|
* |
|
27
|
|
|
* @access public |
|
28
|
|
|
* @param string $account The team or individual account owning the repository. |
|
29
|
|
|
* @param string $repo The repository identifier. |
|
30
|
|
|
* @return ResponseInterface |
|
31
|
|
|
*/ |
|
32
|
1 |
|
public function all($account, $repo) |
|
33
|
|
|
{ |
|
34
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
|
35
|
1 |
|
sprintf('/repositories/%s/%s/deploy-keys', $account, $repo) |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get the key's content |
|
41
|
|
|
* |
|
42
|
|
|
* TIP: You can use `$this->all()` to obtain assigned `$keyId`. |
|
43
|
|
|
* |
|
44
|
|
|
* @access public |
|
45
|
|
|
* @param string $account The team or individual account owning the repository. |
|
46
|
|
|
* @param string $repo The repository identifier. |
|
47
|
|
|
* @param string $keyId The key identifier assigned by Bitbucket. |
|
48
|
|
|
* @return ResponseInterface |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function get($account, $repo, $keyId) |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->get( |
|
53
|
1 |
|
sprintf('/repositories/%s/%s/deploy-keys/%s', $account, $repo, $keyId) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Add a new key |
|
59
|
|
|
* |
|
60
|
|
|
* @access public |
|
61
|
|
|
* @param string $account The team or individual account owning the repository. |
|
62
|
|
|
* @param string $repo The repository identifier. |
|
63
|
|
|
* @param string $key The content of the key. |
|
64
|
|
|
* @param string $label A display name for the key. (optional) |
|
65
|
|
|
* @return ResponseInterface |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function create($account, $repo, $key, $label = null) |
|
68
|
|
|
{ |
|
69
|
1 |
|
$options = array('key' => $key); |
|
70
|
|
|
|
|
71
|
1 |
|
if (!is_null($label)) { |
|
72
|
1 |
|
$options['label'] = $label; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->post( |
|
76
|
1 |
|
sprintf('/repositories/%s/%s/deploy-keys', $account, $repo), |
|
77
|
1 |
|
$options |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Update an existing key |
|
83
|
|
|
* |
|
84
|
|
|
* Available `$options`: |
|
85
|
|
|
* |
|
86
|
|
|
* <example> |
|
87
|
|
|
* 'label' (string) = A display name for the key. |
|
88
|
|
|
* 'key' (string) = The content of the key. |
|
89
|
|
|
* </example> |
|
90
|
|
|
* |
|
91
|
|
|
* @access public |
|
92
|
|
|
* @param string $account The team or individual account owning the repository. |
|
93
|
|
|
* @param string $repo The repository identifier. |
|
94
|
|
|
* @param string $keyId The key identifier assigned by Bitbucket. |
|
95
|
|
|
* @param array $options The rest of available options |
|
96
|
|
|
* @return ResponseInterface |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function update($account, $repo, $keyId, $options = array()) |
|
99
|
|
|
{ |
|
100
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->put( |
|
101
|
1 |
|
sprintf('/repositories/%s/%s/deploy-keys/%s', $account, $repo, $keyId), |
|
102
|
1 |
|
$options |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Delete a key |
|
108
|
|
|
* |
|
109
|
|
|
* TIP: You can use `$this->all()` to obtain assigned `$keyId`. |
|
110
|
|
|
* |
|
111
|
|
|
* @access public |
|
112
|
|
|
* @param string $account The team or individual account owning the repository. |
|
113
|
|
|
* @param string $repo The repository identifier. |
|
114
|
|
|
* @param string $keyId The key identifier assigned by Bitbucket. |
|
115
|
|
|
* @return ResponseInterface |
|
116
|
|
|
*/ |
|
117
|
1 |
|
public function delete($account, $repo, $keyId) |
|
118
|
|
|
{ |
|
119
|
1 |
|
return $this->getClient()->setApiVersion('2.0')->delete( |
|
120
|
1 |
|
sprintf('/repositories/%s/%s/deploy-keys/%s', $account, $repo, $keyId) |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|