##// END OF EJS Templates
Rename helper tools (and fix inconsistent naming)
Bradley M. Kuhn -
r4189:9793473d kallithea-2.2.5-r...
parent child Browse files
Show More
@@ -79,12 +79,12 b' API CLIENT'
79 ++++++++++
79 ++++++++++
80
80
81 From version 1.4 RhodeCode adds a script that allows to easily
81 From version 1.4 RhodeCode adds a script that allows to easily
82 communicate with API. After installing RhodeCode a `rhodecode-api` script
82 communicate with API. After installing RhodeCode a `kallithea-api` script
83 will be available.
83 will be available.
84
84
85 To get started quickly simply run::
85 To get started quickly simply run::
86
86
87 rhodecode-api _create_config --apikey=<youapikey> --apihost=<your.kallithea.server>
87 kallithea-api _create_config --apikey=<youapikey> --apihost=<your.kallithea.server>
88
88
89 This will create a file named .config in the directory you executed it storing
89 This will create a file named .config in the directory you executed it storing
90 json config file with credentials. You can skip this step and always provide
90 json config file with credentials. You can skip this step and always provide
@@ -93,7 +93,7 b' both of the arguments to be able to comm'
93
93
94 after that simply run any api command for example get_repo::
94 after that simply run any api command for example get_repo::
95
95
96 rhodecode-api get_repo
96 kallithea-api get_repo
97
97
98 calling {"api_key": "<apikey>", "id": 75, "args": {}, "method": "get_repo"} to http://127.0.0.1:5000
98 calling {"api_key": "<apikey>", "id": 75, "args": {}, "method": "get_repo"} to http://127.0.0.1:5000
99 rhodecode said:
99 rhodecode said:
@@ -105,7 +105,7 b' Ups looks like we forgot to add an argum'
105
105
106 Let's try again now giving the repoid as parameters::
106 Let's try again now giving the repoid as parameters::
107
107
108 rhodecode-api get_repo repoid:rhodecode
108 kallithea-api get_repo repoid:rhodecode
109
109
110 calling {"api_key": "<apikey>", "id": 39, "args": {"repoid": "rhodecode"}, "method": "get_repo"} to http://127.0.0.1:5000
110 calling {"api_key": "<apikey>", "id": 39, "args": {"repoid": "rhodecode"}, "method": "get_repo"} to http://127.0.0.1:5000
111 rhodecode said:
111 rhodecode said:
@@ -32,10 +32,10 b' from kallithea.bin.base import json, api'
32
32
33 def argparser(argv):
33 def argparser(argv):
34 usage = (
34 usage = (
35 "rhodecode-api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
35 "kallithea-api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
36 "[--config=CONFIG] [--save-config] "
36 "[--config=CONFIG] [--save-config] "
37 "METHOD <key:val> <key2:val> ...\n"
37 "METHOD <key:val> <key2:val> ...\n"
38 "Create config file: rhodecode-api --apikey=<key> --apihost=http://your.kallithea.server --save-config"
38 "Create config file: kallithea-api --apikey=<key> --apihost=http://your.kallithea.server --save-config"
39 )
39 )
40
40
41 parser = argparse.ArgumentParser(description='RhodeCode API cli',
41 parser = argparse.ArgumentParser(description='RhodeCode API cli',
@@ -39,7 +39,7 b' logging.basicConfig(level=logging.DEBUG,'
39 class BackupManager(object):
39 class BackupManager(object):
40 def __init__(self, repos_location, rsa_key, backup_server):
40 def __init__(self, repos_location, rsa_key, backup_server):
41 today = datetime.datetime.now().weekday() + 1
41 today = datetime.datetime.now().weekday() + 1
42 self.backup_file_name = "rhodecode_repos.%s.tar.gz" % today
42 self.backup_file_name = "repos.%s.tar.gz" % today
43
43
44 self.id_rsa_path = self.get_id_rsa(rsa_key)
44 self.id_rsa_path = self.get_id_rsa(rsa_key)
45 self.repos_path = self.get_repos_path(repos_location)
45 self.repos_path = self.get_repos_path(repos_location)
@@ -12,7 +12,7 b''
12 # You should have received a copy of the GNU General Public License
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
14 """
15 kallithea.bin.rhodecode_config
15 kallithea.bin.kallithea_config
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
17
18 configuration generator for RhodeCode
18 configuration generator for RhodeCode
@@ -35,7 +35,7 b' here = os.path.dirname(os.path.abspath(_'
35
35
36 def argparser(argv):
36 def argparser(argv):
37 usage = (
37 usage = (
38 "rhodecode-config [-h] [--filename=FILENAME] [--template=TEMPLATE] \n"
38 "kallithea-config [-h] [--filename=FILENAME] [--template=TEMPLATE] \n"
39 "VARS optional specify extra template variable that will be available in "
39 "VARS optional specify extra template variable that will be available in "
40 "template. Use comma separated key=val format eg.\n"
40 "template. Use comma separated key=val format eg.\n"
41 "key1=val1,port=5000,host=127.0.0.1,elements='a\,b\,c'\n"
41 "key1=val1,port=5000,host=127.0.0.1,elements='a\,b\,c'\n"
@@ -12,7 +12,7 b''
12 # You should have received a copy of the GNU General Public License
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
14 """
15 kallithea.bin.rhodecode_gist
15 kallithea.bin.kallithea_gist
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
17
18 Gist CLI client for RhodeCode
18 Gist CLI client for RhodeCode
@@ -35,10 +35,10 b' from kallithea.bin.base import json, api'
35
35
36 def argparser(argv):
36 def argparser(argv):
37 usage = (
37 usage = (
38 "rhodecode-gist [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
38 "kallithea-gist [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
39 "[--config=CONFIG] [--save-config] [GIST OPTIONS] "
39 "[--config=CONFIG] [--save-config] [GIST OPTIONS] "
40 "[filename or stdin use - for terminal stdin ]\n"
40 "[filename or stdin use - for terminal stdin ]\n"
41 "Create config file: rhodecode-gist --apikey=<key> --apihost=http://your.kallithea.server --save-config"
41 "Create config file: kallithea-gist --apikey=<key> --apihost=http://your.kallithea.server --save-config"
42 )
42 )
43
43
44 parser = argparse.ArgumentParser(description='RhodeCode Gist cli',
44 parser = argparse.ArgumentParser(description='RhodeCode Gist cli',
@@ -45,7 +45,7 b' class InvalidResponseIDError(Exception):'
45 """ Request and response don't have the same UUID. """
45 """ Request and response don't have the same UUID. """
46
46
47
47
48 class RhodecodeResponseError(Exception):
48 class ResponseError(Exception):
49 """ Response has an error, something went wrong with request execution. """
49 """ Response has an error, something went wrong with request execution. """
50
50
51
51
@@ -57,7 +57,7 b' class UserNotInGroupError(Exception):'
57 """ User is not a member of the target group. """
57 """ User is not a member of the target group. """
58
58
59
59
60 class RhodecodeAPI(object):
60 class API(object):
61
61
62 def __init__(self, url, key):
62 def __init__(self, url, key):
63 self.url = url
63 self.url = url
@@ -72,7 +72,7 b' class RhodecodeAPI(object):'
72 "args": args
72 "args": args
73 }
73 }
74
74
75 def rhodecode_api_post(self, method, args):
75 def post(self, method, args):
76 """Send a generic API post to Rhodecode.
76 """Send a generic API post to Rhodecode.
77
77
78 This will generate the UUID for validation check after the
78 This will generate the UUID for validation check after the
@@ -92,7 +92,7 b' class RhodecodeAPI(object):'
92 raise InvalidResponseIDError("UUID does not match.")
92 raise InvalidResponseIDError("UUID does not match.")
93
93
94 if response["error"] is not None:
94 if response["error"] is not None:
95 raise RhodecodeResponseError(response["error"])
95 raise ResponseError(response["error"])
96
96
97 return response["result"]
97 return response["result"]
98
98
@@ -102,7 +102,7 b' class RhodecodeAPI(object):'
102 "group_name": name,
102 "group_name": name,
103 "active": str(active)
103 "active": str(active)
104 }
104 }
105 self.rhodecode_api_post("create_user_group", args)
105 self.post("create_user_group", args)
106
106
107 def add_membership(self, group, username):
107 def add_membership(self, group, username):
108 """Add specific user to a group."""
108 """Add specific user to a group."""
@@ -110,7 +110,7 b' class RhodecodeAPI(object):'
110 "usersgroupid": group,
110 "usersgroupid": group,
111 "userid": username
111 "userid": username
112 }
112 }
113 result = self.rhodecode_api_post("add_user_to_user_group", args)
113 result = self.post("add_user_to_user_group", args)
114 if not result["success"]:
114 if not result["success"]:
115 raise UserAlreadyInGroupError("User %s already in group %s." %
115 raise UserAlreadyInGroupError("User %s already in group %s." %
116 (username, group))
116 (username, group))
@@ -121,7 +121,7 b' class RhodecodeAPI(object):'
121 "usersgroupid": group,
121 "usersgroupid": group,
122 "userid": username
122 "userid": username
123 }
123 }
124 result = self.rhodecode_api_post("remove_user_from_user_group", args)
124 result = self.post("remove_user_from_user_group", args)
125 if not result["success"]:
125 if not result["success"]:
126 raise UserNotInGroupError("User %s not in group %s." %
126 raise UserNotInGroupError("User %s not in group %s." %
127 (username, group))
127 (username, group))
@@ -129,7 +129,7 b' class RhodecodeAPI(object):'
129 def get_group_members(self, name):
129 def get_group_members(self, name):
130 """Get the list of member usernames from a user group."""
130 """Get the list of member usernames from a user group."""
131 args = {"usersgroupid": name}
131 args = {"usersgroupid": name}
132 members = self.rhodecode_api_post("get_user_group", args)['members']
132 members = self.post("get_user_group", args)['members']
133 member_list = []
133 member_list = []
134 for member in members:
134 for member in members:
135 member_list.append(member["username"])
135 member_list.append(member["username"])
@@ -138,12 +138,12 b' class RhodecodeAPI(object):'
138 def get_group(self, name):
138 def get_group(self, name):
139 """Return group info."""
139 """Return group info."""
140 args = {"usersgroupid": name}
140 args = {"usersgroupid": name}
141 return self.rhodecode_api_post("get_user_group", args)
141 return self.post("get_user_group", args)
142
142
143 def get_user(self, username):
143 def get_user(self, username):
144 """Return user info."""
144 """Return user info."""
145 args = {"userid": username}
145 args = {"userid": username}
146 return self.rhodecode_api_post("get_user", args)
146 return self.post("get_user", args)
147
147
148
148
149 class LdapClient(object):
149 class LdapClient(object):
@@ -202,7 +202,7 b' class LdapSync(object):'
202 config.get("default", "ldap_user"),
202 config.get("default", "ldap_user"),
203 config.get("default", "ldap_key"),
203 config.get("default", "ldap_key"),
204 config.get("default", "base_dn"))
204 config.get("default", "base_dn"))
205 self.rhodocode_api = RhodecodeAPI(config.get("default", "api_url"),
205 self.rhodocode_api = API(config.get("default", "api_url"),
206 config.get("default", "api_key"))
206 config.get("default", "api_key"))
207
207
208 def update_groups_from_ldap(self):
208 def update_groups_from_ldap(self):
@@ -211,7 +211,7 b' class LdapSync(object):'
211 groups = self.ldap_client.get_groups()
211 groups = self.ldap_client.get_groups()
212 for group in groups:
212 for group in groups:
213 try:
213 try:
214 self.rhodecode_api.create_repo_group(group)
214 self.kallithea_api.create_repo_group(group)
215 added += 1
215 added += 1
216 except Exception:
216 except Exception:
217 existing += 1
217 existing += 1
@@ -219,25 +219,25 b' class LdapSync(object):'
219 return added, existing
219 return added, existing
220
220
221 def update_memberships_from_ldap(self, group):
221 def update_memberships_from_ldap(self, group):
222 """Update memberships in rhodecode based on the LDAP groups."""
222 """Update memberships based on the LDAP groups."""
223 groups = self.ldap_client.get_groups()
223 groups = self.ldap_client.get_groups()
224 group_users = self.ldap_client.get_group_users(groups, group)
224 group_users = self.ldap_client.get_group_users(groups, group)
225
225
226 # Delete memberships first from each group which are not part
226 # Delete memberships first from each group which are not part
227 # of the group any more.
227 # of the group any more.
228 rhodecode_members = self.rhodecode_api.get_group_members(group)
228 members = self.kallithea_api.get_group_members(group)
229 for rhodecode_member in rhodecode_members:
229 for member in members:
230 if rhodecode_member not in group_users:
230 if member not in group_users:
231 try:
231 try:
232 self.rhodocode_api.remove_membership(group,
232 self.rhodocode_api.remove_membership(group,
233 rhodecode_member)
233 member)
234 except UserNotInGroupError:
234 except UserNotInGroupError:
235 pass
235 pass
236
236
237 # Add memberships.
237 # Add memberships.
238 for member in group_users:
238 for member in group_users:
239 try:
239 try:
240 self.rhodecode_api.add_membership(group, member)
240 self.kallithea_api.add_membership(group, member)
241 except UserAlreadyInGroupError:
241 except UserAlreadyInGroupError:
242 # TODO: handle somehow maybe..
242 # TODO: handle somehow maybe..
243 pass
243 pass
@@ -252,5 +252,5 b" if __name__ == '__main__':"
252 # How should we handle this.. Either sync users as well at this step,
252 # How should we handle this.. Either sync users as well at this step,
253 # or just ignore those who don't exist. If we want the second case,
253 # or just ignore those who don't exist. If we want the second case,
254 # we need to find a way to recognize the right exception (we always get
254 # we need to find a way to recognize the right exception (we always get
255 # RhodecodeResponseError with no error code so maybe by return msg (?)
255 # ResponseError with no error code so maybe by return msg (?)
256 sync.update_memberships_from_ldap(gr)
256 sync.update_memberships_from_ldap(gr)
@@ -6,12 +6,12 b' API_KEY=`psql -R " " -A -U postgres -h l'
6 echo "run those after running server"
6 echo "run those after running server"
7 paster serve rc.ini --pid-file=rc.pid --daemon
7 paster serve rc.ini --pid-file=rc.pid --daemon
8 sleep 3
8 sleep 3
9 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo1 password:qweqwe email:demo1@example.com
9 kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo1 password:qweqwe email:demo1@example.com
10 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo2 password:qweqwe email:demo2@example.com
10 kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo2 password:qweqwe email:demo2@example.com
11 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo3 password:qweqwe email:demo3@example.com
11 kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo3 password:qweqwe email:demo3@example.com
12 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user_group group_name:demo12
12 kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user_group group_name:demo12
13 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo1
13 kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo1
14 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo2
14 kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo2
15 echo "killing server"
15 echo "killing server"
16 kill `cat rc.pid`
16 kill `cat rc.pid`
17 rm rc.pid
17 rm rc.pid
@@ -158,9 +158,9 b' setup('
158 paster_plugins=['PasteScript', 'Pylons'],
158 paster_plugins=['PasteScript', 'Pylons'],
159 entry_points="""
159 entry_points="""
160 [console_scripts]
160 [console_scripts]
161 rhodecode-api = kallithea.bin.rhodecode_api:main
161 kallithea-api = kallithea.bin.kallithea_api:main
162 rhodecode-gist = kallithea.bin.rhodecode_gist:main
162 kallithea-gist = kallithea.bin.kallithea_gist:main
163 rhodecode-config = kallithea.bin.rhodecode_config:main
163 kallithea-config = kallithea.bin.kallithea_config:main
164
164
165 [paste.app_factory]
165 [paste.app_factory]
166 main = kallithea.config.middleware:make_app
166 main = kallithea.config.middleware:make_app
General Comments 0
You need to be logged in to leave comments. Login now