deploy_keys.md 6.29 KB
Newer Older
1
# Deploy Keys API
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
2

3 4
## List all deploy keys

5
Get a list of all deploy keys across all projects of the GitLab instance. This endpoint requires admin access.
6 7 8 9 10 11

```
GET /deploy_keys
```

```bash
12
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/deploy_keys"
13 14 15 16 17 18 19 20 21
```

Example response:

```json
[
  {
    "id": 1,
    "title": "Public key",
22
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",    
23 24 25 26 27
    "created_at": "2013-10-02T10:12:29Z"
  },
  {
    "id": 3,
    "title": "Another Public key",
28
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",    
29 30 31 32 33 34
    "created_at": "2013-10-02T11:12:29Z"
  }
]
```

## List project deploy keys
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
35 36 37 38

Get a list of a project's deploy keys.

```
39
GET /projects/:id/deploy_keys
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
40 41
```

42 43
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
44
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
45 46

```bash
47
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/5/deploy_keys"
48
```
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
49

50
Example response:
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
51 52 53 54 55

```json
[
  {
    "id": 1,
Johannes's avatar
Johannes committed
56 57
    "title": "Public key",
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",
58 59
    "created_at": "2013-10-02T10:12:29Z",
    "can_push": false
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
60 61 62
  },
  {
    "id": 3,
Johannes's avatar
Johannes committed
63 64
    "title": "Another Public key",
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",
65 66
    "created_at": "2013-10-02T11:12:29Z",
    "can_push": false
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
67 68 69 70
  }
]
```

71
## Single deploy key
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
72 73 74 75

Get a single key.

```
76
GET /projects/:id/deploy_keys/:key_id
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
77 78 79 80
```

Parameters:

81 82
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
83
| `id`      | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
84 85 86
| `key_id`  | integer | yes | The ID of the deploy key |

```bash
87
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/5/deploy_keys/11"
88 89 90
```

Example response:
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
91 92 93 94

```json
{
  "id": 1,
Johannes's avatar
Johannes committed
95 96
  "title": "Public key",
  "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",
97 98
  "created_at": "2013-10-02T10:12:29Z",
  "can_push": false
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
99 100 101
}
```

102
## Add deploy key
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
103 104

Creates a new deploy key for a project.
105 106

If the deploy key already exists in another project, it will be joined to current
107
project only if original one is accessible by the same user.
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
108 109

```
110
POST /projects/:id/deploy_keys
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
111 112
```

113 114
| Attribute  | Type | Required | Description |
| ---------  | ---- | -------- | ----------- |
115
| `id`       | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
116 117 118
| `title`    | string  | yes | New deploy key's title |
| `key`      | string  | yes | New deploy key |
| `can_push` | boolean | no  | Can deploy key push to the project's repository |
119 120

```bash
121
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" --header "Content-Type: application/json" --data '{"title": "My deploy key", "key": "ssh-rsa AAAA...", "can_push": "true"}' "https://gitlab.example.com/api/v4/projects/5/deploy_keys/"
122
```
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
123

124 125 126 127 128 129 130
Example response:

```json
{
   "key" : "ssh-rsa AAAA...",
   "id" : 12,
   "title" : "My deploy key",
131
   "can_push": true,
132 133 134
   "created_at" : "2015-08-29T12:44:31.550Z"
}
```
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
135

136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
## Update deploy key

Updates a deploy key for a project.

```
PUT /projects/:id/deploy_keys/:key_id
```

| Attribute  | Type | Required | Description |
| ---------  | ---- | -------- | ----------- |
| `id`       | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `title`    | string  | no | New deploy key's title |
| `can_push` | boolean | no  | Can deploy key push to the project's repository |

```bash
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" --header "Content-Type: application/json" --data '{"title": "New deploy key", "can_push": true}' "https://gitlab.example.com/api/v4/projects/5/deploy_keys/11"
```

Example response:

```json
{
   "id": 11,
   "title": "New deploy key",
   "key": "ssh-rsa AAAA...",
   "created_at": "2015-08-29T12:44:31.550Z",
   "can_push": true
}
```

166
## Delete deploy key
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
167

168
Removes a deploy key from the project. If the deploy key is used only for this project, it will be deleted from the system.
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
169 170

```
171
DELETE /projects/:id/deploy_keys/:key_id
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
172 173
```

174 175
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
176
| `id`      | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
177 178 179
| `key_id`  | integer | yes | The ID of the deploy key |

```bash
180
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/5/deploy_keys/13"
181
```
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
182

183 184 185 186
## Enable a deploy key

Enables a deploy key for a project so this can be used. Returns the enabled key, with a status code 201 when successful.

187
```bash
188
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/deploy_keys/13/enable
189 190 191 192
```

| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
193
| `id`      | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
194 195 196 197 198 199 200 201 202 203 204 205
| `key_id`  | integer | yes | The ID of the deploy key |

Example response:

```json
{
   "key" : "ssh-rsa AAAA...",
   "id" : 12,
   "title" : "My deploy key",
   "created_at" : "2015-08-29T12:44:31.550Z"
}
```