diff --git a/docs/api/api.rst b/docs/api/api.rst --- a/docs/api/api.rst +++ b/docs/api/api.rst @@ -7,7 +7,7 @@ API Starting from RhodeCode version 1.2 a simple API was implemented. There's a single schema for calling all api methods. API is implemented -with JSON protocol both ways. An url to send API request in RhodeCode is +with JSON protocol both ways. An url to send API request to RhodeCode is /_admin/api API ACCESS FOR WEB VIEWS @@ -59,6 +59,47 @@ All responses from API will be `HTTP/1.0 calling api *error* key from response will contain failure description and result will be null. + +API CLIENT +++++++++++ + +From version 1.4 RhodeCode adds a script that allows to easily +communicate with API. After installing RhodeCode a `rhodecode-api` script +will be available. + +To get started quickly simply run:: + + rhodecode-api _create_config --apikey= --apihost= + +This will create a file named .config in the directory you executed it storing +json config file with credentials. You can skip this step and always provide +both of the arguments to be able to communicate with server + + +after that simply run any api command for example get_repo:: + + rhodecode-api get_repo + + calling {"api_key": "", "id": 75, "args": {}, "method": "get_repo"} to http://127.0.0.1:5000 + rhodecode said: + {'error': 'Missing non optional `repoid` arg in JSON DATA', + 'id': 75, + 'result': None} + +Ups looks like we forgot to add an argument + +Let's try again now giving the repoid as parameters:: + + rhodecode-api get_repo repoid:rhodecode + + calling {"api_key": "", "id": 39, "args": {"repoid": "rhodecode"}, "method": "get_repo"} to http://127.0.0.1:5000 + rhodecode said: + {'error': None, + 'id': 39, + 'result': } + + + API METHODS +++++++++++ @@ -76,12 +117,64 @@ INPUT:: api_key : "" method : "pull" args : { - "repo_name" : "" + "repoid" : "" + } + +OUTPUT:: + + id : + result : "Pulled from ``" + error : null + + +rescan_repos +------------ + +Dispatch rescan repositories action. If remove_obsolete is set +RhodeCode will delete repos that are in database but not in the filesystem. +This command can be executed only using api_key belonging to user with admin +rights. + +INPUT:: + + id : + api_key : "" + method : "rescan_repos" + args : { + "remove_obsolete" : "" } OUTPUT:: - result : "Pulled from " + id : + result : "{'added': [], + 'removed': []}" + error : null + + +lock +---- + +Set locking state on given repository by given user. +This command can be executed only using api_key belonging to user with admin +rights. + +INPUT:: + + id : + api_key : "" + method : "lock" + args : { + "repoid" : "" + "userid" : "", + "locked" : "" + + } + +OUTPUT:: + + id : + result : "User `` set lock state for repo `` to `true|false`" error : null @@ -104,13 +197,15 @@ INPUT:: OUTPUT:: + id : result: None if user does not exist or { - "id" : "", + "user_id" : "", "username" : "", "firstname": "", "lastname" : "", "email" : "", + "emails": "", "active" : "", "admin" :  "", "ldap_dn" : "", @@ -143,13 +238,15 @@ INPUT:: OUTPUT:: + id : result: [ { - "id" : "", + "user_id" : "", "username" : "", "firstname": "", "lastname" : "", "email" : "", + "emails": "", "active" : "", "admin" :  "", "ldap_dn" : "", @@ -174,20 +271,32 @@ INPUT:: method : "create_user" args : { "username" : "", + "email" : "", "password" : "", - "email" : "", - "firstname" : " = None", - "lastname" : " = None", - "active" : " = True", - "admin" : " = False", - "ldap_dn" : " = None" + "firstname" : " = Optional(None)", + "lastname" : " = Optional(None)", + "active" : " = Optional(True)", + "admin" : " = Optional(False)", + "ldap_dn" : " = Optional(None)" } OUTPUT:: + id : result: { - "id" : "", - "msg" : "created new user " + "msg" : "created new user ``", + "user": { + "user_id" : "", + "username" : "", + "firstname": "", + "lastname" : "", + "email" : "", + "emails": "", + "active" : "", + "admin" :  "", + "ldap_dn" : "", + "last_login": "", + }, } error: null @@ -195,7 +304,7 @@ OUTPUT:: update_user ----------- -updates current one if such user exists. This command can +updates given user if such user exists. This command can be executed only using api_key belonging to user with admin rights. @@ -206,21 +315,60 @@ INPUT:: method : "update_user" args : { "userid" : "", - "username" : "", - "password" : "", - "email" : "", - "firstname" : "", - "lastname" : "", - "active" : "", - "admin" : "", - "ldap_dn" : "" + "username" : " = Optional", + "email" : " = Optional", + "password" : " = Optional", + "firstname" : " = Optional", + "lastname" : " = Optional", + "active" : " = Optional", + "admin" : " = Optional", + "ldap_dn" : " = Optional" } OUTPUT:: + id : result: { - "id" : "", - "msg" : "updated user " + "msg" : "updated user ID: ", + "user": { + "user_id" : "", + "username" : "", + "firstname": "", + "lastname" : "", + "email" : "", + "emails": "", + "active" : "", + "admin" :  "", + "ldap_dn" : "", + "last_login": "", + }, + } + error: null + + +delete_user +----------- + + +deletes givenuser if such user exists. This command can +be executed only using api_key belonging to user with admin rights. + + +INPUT:: + + id : + api_key : "" + method : "delete_user" + args : { + "userid" : "", + } + +OUTPUT:: + + id : + result: { + "msg" : "deleted user ID: ", + "user": null } error: null @@ -238,25 +386,29 @@ INPUT:: api_key : "" method : "get_users_group" args : { - "group_name" : "" + "usersgroupid" : "" } OUTPUT:: + id : result : None if group not exist { - "id" : "", - "group_name" : "", - "active": "", + "users_group_id" : "", + "group_name" : "", + "active": "", "members" : [ - { "id" : "", + { + "user_id" : "", "username" : "", "firstname": "", "lastname" : "", "email" : "", + "emails": "", "active" : "", "admin" :  "", - "ldap" : "" + "ldap_dn" : "", + "last_login": "", }, … ] @@ -280,25 +432,29 @@ INPUT:: OUTPUT:: + id : result : [ { - "id" : "", - "group_name" : "", - "active": "", - "members" : [ - { - "id" : "", - "username" : "", - "firstname": "", - "lastname" : "", - "email" : "", - "active" : "", - "admin" :  "", - "ldap" : "" - }, - … - ] - } + "users_group_id" : "", + "group_name" : "", + "active": "", + "members" : [ + { + "user_id" : "", + "username" : "", + "firstname": "", + "lastname" : "", + "email" : "", + "emails": "", + "active" : "", + "admin" :  "", + "ldap_dn" : "", + "last_login": "", + }, + … + ] + }, + … ] error : null @@ -317,14 +473,34 @@ INPUT:: method : "create_users_group" args: { "group_name": "", - "active":" = True" + "active":" = Optional(True)" } OUTPUT:: + id : result: { - "id": "", - "msg": "created new users group " + "msg": "created new users group ``", + "users_group": { + "users_group_id" : "", + "group_name" : "", + "active": "", + "members" : [ + { + "user_id" : "", + "username" : "", + "firstname": "", + "lastname" : "", + "email" : "", + "emails": "", + "active" : "", + "admin" :  "", + "ldap_dn" : "", + "last_login": "", + }, + … + ] + }, } error: null @@ -343,16 +519,16 @@ INPUT:: api_key : "" method : "add_user_users_group" args: { - "group_name" : "", - "username" : "" + "usersgroupid" : "", + "userid" : "", } OUTPUT:: + id : result: { - "id": "", "success": True|False # depends on if member is in group - "msg": "added member to users group | + "msg": "added member `` to users group `` | User is already in that group" } error: null @@ -372,12 +548,13 @@ INPUT:: api_key : "" method : "remove_user_from_users_group" args: { - "group_name" : "", - "username" : "" + "usersgroupid" : "", + "userid" : "", } OUTPUT:: + id : result: { "success": True|False, # depends on if member is in group "msg": "removed member from users group | @@ -405,23 +582,32 @@ INPUT:: OUTPUT:: + id : result: None if repository does not exist or { - "id" : "", + "repo_id" : "", "repo_name" : "" - "type" : "", + "repo_type" : "", + "clone_uri" : "", + "private": : "", + "created_on" : "", "description" : "", + "landing_rev": "", + "owner": "", + "fork_of": "", "members" : [ { "type": "user", - "id" : "", - "username" : "", - "firstname": "", - "lastname" : "", - "email" : "", - "active" : "", - "admin" :  "", - "ldap" : "", + "user_id" : "", + "username" : "", + "firstname": "", + "lastname" : "", + "email" : "", + "emails": "", + "active" : "", + "admin" :  "", + "ldap_dn" : "", + "last_login": "", "permission" : "repository.(read|write|admin)" }, … @@ -454,12 +640,19 @@ INPUT:: OUTPUT:: + id : result: [ { - "id" : "", + "repo_id" : "", "repo_name" : "" - "type" : "", - "description" : "" + "repo_type" : "", + "clone_uri" : "", + "private": : "", + "created_on" : "", + "description" : "", + "landing_rev": "", + "owner": "", + "fork_of": "", }, … ] @@ -481,14 +674,15 @@ INPUT:: api_key : "" method : "get_repo_nodes" args: { - "repo_name" : "", + "repoid" : "" "revision" : "", "root_path" : "", - "ret_type" : "" = 'all' + "ret_type" : " = Optional('all')" } OUTPUT:: + id : result: [ { "name" : "" @@ -516,18 +710,31 @@ INPUT:: method : "create_repo" args: { "repo_name" : "", - "owner_name" : "", - "description" : " = ''", - "repo_type" : " = 'hg'", - "private" : " = False", - "clone_uri" : " = None", + "owner" : "", + "repo_type" : "", + "description" : " = Optional('')", + "private" : " = Optional(False)", + "clone_uri" : " = Optional(None)", + "landing_rev" : " = Optional('tip')", } OUTPUT:: + id : result: { - "id": "", - "msg": "Created new repository ", + "msg": "Created new repository ``", + "repo": { + "repo_id" : "", + "repo_name" : "" + "repo_type" : "", + "clone_uri" : "", + "private": : "", + "created_on" : "", + "description" : "", + "landing_rev": "", + "owner": "", + "fork_of": "", + }, } error: null @@ -545,13 +752,15 @@ INPUT:: api_key : "" method : "delete_repo" args: { - "repo_name" : "", + "repoid" : "" } OUTPUT:: + id : result: { - "msg": "Deleted repository ", + "msg": "Deleted repository ``", + "success": true } error: null @@ -570,15 +779,17 @@ INPUT:: api_key : "" method : "grant_user_permission" args: { - "repo_name" : "", - "username" : "", + "repoid" : "" + "userid" : "" "perm" : "(repository.(none|read|write|admin))", } OUTPUT:: + id : result: { - "msg" : "Granted perm: for user: in repo: " + "msg" : "Granted perm: `` for user: `` in repo: ``", + "success": true } error: null @@ -596,14 +807,16 @@ INPUT:: api_key : "" method : "revoke_user_permission" args: { - "repo_name" : "", - "username" : "", + "repoid" : "" + "userid" : "" } OUTPUT:: + id : result: { - "msg" : "Revoked perm for user: in repo: " + "msg" : "Revoked perm for user: `` in repo: ``", + "success": true } error: null @@ -622,15 +835,17 @@ INPUT:: api_key : "" method : "grant_users_group_permission" args: { - "repo_name" : "", - "group_name" : "", + "repoid" : "" + "usersgroupid" : "" "perm" : "(repository.(none|read|write|admin))", } OUTPUT:: + id : result: { - "msg" : "Granted perm: for group: in repo: " + "msg" : "Granted perm: `` for group: `` in repo: ``", + "success": true } error: null @@ -647,13 +862,15 @@ INPUT:: api_key : "" method : "revoke_users_group_permission" args: { - "repo_name" : "", - "users_group" : "", + "repoid" : "" + "usersgroupid" : "" } OUTPUT:: + id : result: { - "msg" : "Revoked perm for group: in repo: " + "msg" : "Revoked perm for group: `` in repo: ``", + "success": true } error: null \ No newline at end of file