Show More
@@ -1,414 +1,421 b'' | |||
|
1 | 1 | .. _api: |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | API |
|
5 | 5 | === |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | Starting from RhodeCode version 1.2 a simple API was implemented. |
|
9 | 9 | There's a single schema for calling all api methods. API is implemented |
|
10 | 10 | with JSON protocol both ways. An url to send API request in RhodeCode is |
|
11 | 11 | <your_server>/_admin/api |
|
12 | 12 | |
|
13 | 13 | |
|
14 | API access can also be turned on for each view decorated with `@LoginRequired` | |
|
15 | decorator. To enable API access simple change standard login decorator into | |
|
16 | `@LoginRequired(api_access=True)`. After such a change view can be accessed | |
|
17 | by adding a GET parameter to url `?api_key=<api_key>`. By default it's only | |
|
18 | enabled on RSS/ATOM feed views. | |
|
19 | ||
|
20 | ||
|
14 | 21 | All clients are required to send JSON-RPC spec JSON data:: |
|
15 | 22 | |
|
16 | 23 | { |
|
17 | 24 | "id:<id>, |
|
18 | 25 | "api_key":"<api_key>", |
|
19 | 26 | "method":"<method_name>", |
|
20 | 27 | "args":{"<arg_key>":"<arg_val>"} |
|
21 | 28 | } |
|
22 | 29 | |
|
23 | 30 | Example call for autopulling remotes repos using curl:: |
|
24 | 31 | curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' |
|
25 | 32 | |
|
26 | 33 | Simply provide |
|
27 | 34 | - *id* A value of any type, which is used to match the response with the request that it is replying to. |
|
28 | 35 | - *api_key* for access and permission validation. |
|
29 | 36 | - *method* is name of method to call |
|
30 | 37 | - *args* is an key:value list of arguments to pass to method |
|
31 | 38 | |
|
32 | 39 | .. note:: |
|
33 | 40 | |
|
34 | 41 | api_key can be found in your user account page |
|
35 | 42 | |
|
36 | 43 | |
|
37 | 44 | RhodeCode API will return always a JSON-RPC response:: |
|
38 | 45 | |
|
39 | 46 | { |
|
40 | 47 | "id":<id>, |
|
41 | 48 | "result": "<result>", |
|
42 | 49 | "error": null |
|
43 | 50 | } |
|
44 | 51 | |
|
45 | 52 | All responses from API will be `HTTP/1.0 200 OK`, if there's an error while |
|
46 | 53 | calling api *error* key from response will contain failure description |
|
47 | 54 | and result will be null. |
|
48 | 55 | |
|
49 | 56 | API METHODS |
|
50 | 57 | +++++++++++ |
|
51 | 58 | |
|
52 | 59 | |
|
53 | 60 | pull |
|
54 | 61 | ---- |
|
55 | 62 | |
|
56 | 63 | Pulls given repo from remote location. Can be used to automatically keep |
|
57 | 64 | remote repos up to date. This command can be executed only using api_key |
|
58 | 65 | belonging to user with admin rights |
|
59 | 66 | |
|
60 | 67 | INPUT:: |
|
61 | 68 | |
|
62 | 69 | api_key : "<api_key>" |
|
63 | 70 | method : "pull" |
|
64 | 71 | args : { |
|
65 | 72 | "repo" : "<repo_name>" |
|
66 | 73 | } |
|
67 | 74 | |
|
68 | 75 | OUTPUT:: |
|
69 | 76 | |
|
70 | 77 | result : "Pulled from <repo_name>" |
|
71 | 78 | error : null |
|
72 | 79 | |
|
73 | 80 | |
|
74 | 81 | get_users |
|
75 | 82 | --------- |
|
76 | 83 | |
|
77 | 84 | Lists all existing users. This command can be executed only using api_key |
|
78 | 85 | belonging to user with admin rights. |
|
79 | 86 | |
|
80 | 87 | INPUT:: |
|
81 | 88 | |
|
82 | 89 | api_key : "<api_key>" |
|
83 | 90 | method : "get_users" |
|
84 | 91 | args : { } |
|
85 | 92 | |
|
86 | 93 | OUTPUT:: |
|
87 | 94 | |
|
88 | 95 | result: [ |
|
89 | 96 | { |
|
90 | 97 | "id" : "<id>", |
|
91 | 98 | "username" : "<username>", |
|
92 | 99 | "firstname": "<firstname>", |
|
93 | 100 | "lastname" : "<lastname>", |
|
94 | 101 | "email" : "<email>", |
|
95 | 102 | "active" : "<bool>", |
|
96 | 103 | "admin" :Β "<bool>", |
|
97 | 104 | "ldap" : "<ldap_dn>" |
|
98 | 105 | }, |
|
99 | 106 | β¦ |
|
100 | 107 | ] |
|
101 | 108 | error: null |
|
102 | 109 | |
|
103 | 110 | create_user |
|
104 | 111 | ----------- |
|
105 | 112 | |
|
106 | 113 | Creates new user in RhodeCode. This command can be executed only using api_key |
|
107 | 114 | belonging to user with admin rights. |
|
108 | 115 | |
|
109 | 116 | INPUT:: |
|
110 | 117 | |
|
111 | 118 | api_key : "<api_key>" |
|
112 | 119 | method : "create_user" |
|
113 | 120 | args : { |
|
114 | 121 | "username" : "<username>", |
|
115 | 122 | "password" : "<password>", |
|
116 | 123 | "firstname" : "<firstname>", |
|
117 | 124 | "lastname" : "<lastname>", |
|
118 | 125 | "email" : "<useremail>" |
|
119 | 126 | "active" : "<bool> = True", |
|
120 | 127 | "admin" : "<bool> = False", |
|
121 | 128 | "ldap_dn" : "<ldap_dn> = None" |
|
122 | 129 | } |
|
123 | 130 | |
|
124 | 131 | OUTPUT:: |
|
125 | 132 | |
|
126 | 133 | result: { |
|
127 | 134 | "msg" : "created new user <username>" |
|
128 | 135 | } |
|
129 | 136 | error: null |
|
130 | 137 | |
|
131 | 138 | get_users_groups |
|
132 | 139 | ---------------- |
|
133 | 140 | |
|
134 | 141 | Lists all existing users groups. This command can be executed only using api_key |
|
135 | 142 | belonging to user with admin rights. |
|
136 | 143 | |
|
137 | 144 | INPUT:: |
|
138 | 145 | |
|
139 | 146 | api_key : "<api_key>" |
|
140 | 147 | method : "get_users_groups" |
|
141 | 148 | args : { } |
|
142 | 149 | |
|
143 | 150 | OUTPUT:: |
|
144 | 151 | |
|
145 | 152 | result : [ |
|
146 | 153 | { |
|
147 | 154 | "id" : "<id>", |
|
148 | 155 | "name" : "<name>", |
|
149 | 156 | "active": "<bool>", |
|
150 | 157 | "members" : [ |
|
151 | 158 | { |
|
152 | 159 | "id" : "<userid>", |
|
153 | 160 | "username" : "<username>", |
|
154 | 161 | "firstname": "<firstname>", |
|
155 | 162 | "lastname" : "<lastname>", |
|
156 | 163 | "email" : "<email>", |
|
157 | 164 | "active" : "<bool>", |
|
158 | 165 | "admin" :Β "<bool>", |
|
159 | 166 | "ldap" : "<ldap_dn>" |
|
160 | 167 | }, |
|
161 | 168 | β¦ |
|
162 | 169 | ] |
|
163 | 170 | } |
|
164 | 171 | ] |
|
165 | 172 | error : null |
|
166 | 173 | |
|
167 | 174 | get_users_group |
|
168 | 175 | --------------- |
|
169 | 176 | |
|
170 | 177 | Gets an existing users group. This command can be executed only using api_key |
|
171 | 178 | belonging to user with admin rights. |
|
172 | 179 | |
|
173 | 180 | INPUT:: |
|
174 | 181 | |
|
175 | 182 | api_key : "<api_key>" |
|
176 | 183 | method : "get_users_group" |
|
177 | 184 | args : { |
|
178 | 185 | "group_name" : "<name>" |
|
179 | 186 | } |
|
180 | 187 | |
|
181 | 188 | OUTPUT:: |
|
182 | 189 | |
|
183 | 190 | result : None if group not exist |
|
184 | 191 | { |
|
185 | 192 | "id" : "<id>", |
|
186 | 193 | "name" : "<name>", |
|
187 | 194 | "active": "<bool>", |
|
188 | 195 | "members" : [ |
|
189 | 196 | { "id" : "<userid>", |
|
190 | 197 | "username" : "<username>", |
|
191 | 198 | "firstname": "<firstname>", |
|
192 | 199 | "lastname" : "<lastname>", |
|
193 | 200 | "email" : "<email>", |
|
194 | 201 | "active" : "<bool>", |
|
195 | 202 | "admin" :Β "<bool>", |
|
196 | 203 | "ldap" : "<ldap_dn>" |
|
197 | 204 | }, |
|
198 | 205 | β¦ |
|
199 | 206 | ] |
|
200 | 207 | } |
|
201 | 208 | error : null |
|
202 | 209 | |
|
203 | 210 | create_users_group |
|
204 | 211 | ------------------ |
|
205 | 212 | |
|
206 | 213 | Creates new users group. This command can be executed only using api_key |
|
207 | 214 | belonging to user with admin rights |
|
208 | 215 | |
|
209 | 216 | INPUT:: |
|
210 | 217 | |
|
211 | 218 | api_key : "<api_key>" |
|
212 | 219 | method : "create_users_group" |
|
213 | 220 | args: { |
|
214 | 221 | "name": "<name>", |
|
215 | 222 | "active":"<bool> = True" |
|
216 | 223 | } |
|
217 | 224 | |
|
218 | 225 | OUTPUT:: |
|
219 | 226 | |
|
220 | 227 | result: { |
|
221 | 228 | "id": "<newusersgroupid>", |
|
222 | 229 | "msg": "created new users group <name>" |
|
223 | 230 | } |
|
224 | 231 | error: null |
|
225 | 232 | |
|
226 | 233 | add_user_to_users_group |
|
227 | 234 | ----------------------- |
|
228 | 235 | |
|
229 | 236 | Adds a user to a users group. This command can be executed only using api_key |
|
230 | 237 | belonging to user with admin rights |
|
231 | 238 | |
|
232 | 239 | INPUT:: |
|
233 | 240 | |
|
234 | 241 | api_key : "<api_key>" |
|
235 | 242 | method : "add_user_users_group" |
|
236 | 243 | args: { |
|
237 | 244 | "group_name" : "<groupname>", |
|
238 | 245 | "username" : "<username>" |
|
239 | 246 | } |
|
240 | 247 | |
|
241 | 248 | OUTPUT:: |
|
242 | 249 | |
|
243 | 250 | result: { |
|
244 | 251 | "id": "<newusersgroupmemberid>", |
|
245 | 252 | "msg": "created new users group member" |
|
246 | 253 | } |
|
247 | 254 | error: null |
|
248 | 255 | |
|
249 | 256 | get_repos |
|
250 | 257 | --------- |
|
251 | 258 | |
|
252 | 259 | Lists all existing repositories. This command can be executed only using api_key |
|
253 | 260 | belonging to user with admin rights |
|
254 | 261 | |
|
255 | 262 | INPUT:: |
|
256 | 263 | |
|
257 | 264 | api_key : "<api_key>" |
|
258 | 265 | method : "get_repos" |
|
259 | 266 | args: { } |
|
260 | 267 | |
|
261 | 268 | OUTPUT:: |
|
262 | 269 | |
|
263 | 270 | result: [ |
|
264 | 271 | { |
|
265 | 272 | "id" : "<id>", |
|
266 | 273 | "name" : "<name>" |
|
267 | 274 | "type" : "<type>", |
|
268 | 275 | "description" : "<description>" |
|
269 | 276 | }, |
|
270 | 277 | β¦ |
|
271 | 278 | ] |
|
272 | 279 | error: null |
|
273 | 280 | |
|
274 | 281 | get_repo |
|
275 | 282 | -------- |
|
276 | 283 | |
|
277 | 284 | Gets an existing repository. This command can be executed only using api_key |
|
278 | 285 | belonging to user with admin rights |
|
279 | 286 | |
|
280 | 287 | INPUT:: |
|
281 | 288 | |
|
282 | 289 | api_key : "<api_key>" |
|
283 | 290 | method : "get_repo" |
|
284 | 291 | args: { |
|
285 | 292 | "name" : "<name>" |
|
286 | 293 | } |
|
287 | 294 | |
|
288 | 295 | OUTPUT:: |
|
289 | 296 | |
|
290 | 297 | result: None if repository not exist |
|
291 | 298 | { |
|
292 | 299 | "id" : "<id>", |
|
293 | 300 | "name" : "<name>" |
|
294 | 301 | "type" : "<type>", |
|
295 | 302 | "description" : "<description>", |
|
296 | 303 | "members" : [ |
|
297 | 304 | { "id" : "<userid>", |
|
298 | 305 | "username" : "<username>", |
|
299 | 306 | "firstname": "<firstname>", |
|
300 | 307 | "lastname" : "<lastname>", |
|
301 | 308 | "email" : "<email>", |
|
302 | 309 | "active" : "<bool>", |
|
303 | 310 | "admin" :Β "<bool>", |
|
304 | 311 | "ldap" : "<ldap_dn>", |
|
305 | 312 | "permission" : "repository.(read|write|admin)" |
|
306 | 313 | }, |
|
307 | 314 | β¦ |
|
308 | 315 | { |
|
309 | 316 | "id" : "<usersgroupid>", |
|
310 | 317 | "name" : "<usersgroupname>", |
|
311 | 318 | "active": "<bool>", |
|
312 | 319 | "permission" : "repository.(read|write|admin)" |
|
313 | 320 | }, |
|
314 | 321 | β¦ |
|
315 | 322 | ] |
|
316 | 323 | } |
|
317 | 324 | error: null |
|
318 | 325 | |
|
319 | 326 | get_repo_nodes |
|
320 | 327 | -------------- |
|
321 | 328 | |
|
322 | 329 | returns a list of nodes and it's children in a flat list for a given path |
|
323 | 330 | at given revision. It's possible to specify ret_type to show only files or |
|
324 | 331 | dirs. This command can be executed only using api_key belonging to user |
|
325 | 332 | with admin rights |
|
326 | 333 | |
|
327 | 334 | INPUT:: |
|
328 | 335 | |
|
329 | 336 | api_key : "<api_key>" |
|
330 | 337 | method : "get_repo_nodes" |
|
331 | 338 | args: { |
|
332 | 339 | "repo_name" : "<name>", |
|
333 | 340 | "revision" : "<revision>", |
|
334 | 341 | "root_path" : "<root_path>", |
|
335 | 342 | "ret_type" : "<ret_type>" = 'all' |
|
336 | 343 | } |
|
337 | 344 | |
|
338 | 345 | OUTPUT:: |
|
339 | 346 | |
|
340 | 347 | result: [ |
|
341 | 348 | { |
|
342 | 349 | "name" : "<name>" |
|
343 | 350 | "type" : "<type>", |
|
344 | 351 | }, |
|
345 | 352 | β¦ |
|
346 | 353 | ] |
|
347 | 354 | error: null |
|
348 | 355 | |
|
349 | 356 | |
|
350 | 357 | |
|
351 | 358 | create_repo |
|
352 | 359 | ----------- |
|
353 | 360 | |
|
354 | 361 | Creates a repository. This command can be executed only using api_key |
|
355 | 362 | belonging to user with admin rights. |
|
356 | 363 | If repository name contains "/", all needed repository groups will be created. |
|
357 | 364 | For example "foo/bar/baz" will create groups "foo", "bar" (with "foo" as parent), |
|
358 | 365 | and create "baz" repository with "bar" as group. |
|
359 | 366 | |
|
360 | 367 | INPUT:: |
|
361 | 368 | |
|
362 | 369 | api_key : "<api_key>" |
|
363 | 370 | method : "create_repo" |
|
364 | 371 | args: { |
|
365 | 372 | "name" : "<name>", |
|
366 | 373 | "owner_name" : "<ownername>", |
|
367 | 374 | "description" : "<description> = ''", |
|
368 | 375 | "repo_type" : "<type> = 'hg'", |
|
369 | 376 | "private" : "<bool> = False" |
|
370 | 377 | } |
|
371 | 378 | |
|
372 | 379 | OUTPUT:: |
|
373 | 380 | |
|
374 | 381 | result: None |
|
375 | 382 | error: null |
|
376 | 383 | |
|
377 | 384 | add_user_to_repo |
|
378 | 385 | ---------------- |
|
379 | 386 | |
|
380 | 387 | Add a user to a repository. This command can be executed only using api_key |
|
381 | 388 | belonging to user with admin rights. |
|
382 | 389 | If "perm" is None, user will be removed from the repository. |
|
383 | 390 | |
|
384 | 391 | INPUT:: |
|
385 | 392 | |
|
386 | 393 | api_key : "<api_key>" |
|
387 | 394 | method : "add_user_to_repo" |
|
388 | 395 | args: { |
|
389 | 396 | "repo_name" : "<reponame>", |
|
390 | 397 | "username" : "<username>", |
|
391 | 398 | "perm" : "(None|repository.(read|write|admin))", |
|
392 | 399 | } |
|
393 | 400 | |
|
394 | 401 | OUTPUT:: |
|
395 | 402 | |
|
396 | 403 | result: None |
|
397 | 404 | error: null |
|
398 | 405 | |
|
399 | 406 | add_users_group_to_repo |
|
400 | 407 | ----------------------- |
|
401 | 408 | |
|
402 | 409 | Add a users group to a repository. This command can be executed only using |
|
403 | 410 | api_key belonging to user with admin rights. If "perm" is None, group will |
|
404 | 411 | be removed from the repository. |
|
405 | 412 | |
|
406 | 413 | INPUT:: |
|
407 | 414 | |
|
408 | 415 | api_key : "<api_key>" |
|
409 | 416 | method : "add_users_group_to_repo" |
|
410 | 417 | args: { |
|
411 | 418 | "repo_name" : "<reponame>", |
|
412 | 419 | "group_name" : "<groupname>", |
|
413 | 420 | "perm" : "(None|repository.(read|write|admin))", |
|
414 | 421 | } No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now