Changeset - 9793473d74be
[Not reviewed]
Bradley M. Kuhn - 11 years ago 2014-07-03 01:04:39
bkuhn@sfconservancy.org
Rename helper tools (and fix inconsistent naming)
8 files changed with 40 insertions and 40 deletions:
0 comments (0 inline, 0 general)
docs/api/api.rst
Show inline comments
 
@@ -79,12 +79,12 @@ API CLIENT
 
++++++++++
 

	
 
From version 1.4 RhodeCode adds a script that allows to easily
 
communicate with API. After installing RhodeCode a `rhodecode-api` script
 
communicate with API. After installing RhodeCode a `kallithea-api` script
 
will be available.
 

	
 
To get started quickly simply run::
 

	
 
  rhodecode-api _create_config --apikey=<youapikey> --apihost=<your.kallithea.server>
 
  kallithea-api _create_config --apikey=<youapikey> --apihost=<your.kallithea.server>
 

	
 
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
 
@@ -93,7 +93,7 @@ both of the arguments to be able to comm
 

	
 
after that simply run any api command for example get_repo::
 

	
 
 rhodecode-api get_repo
 
 kallithea-api get_repo
 

	
 
 calling {"api_key": "<apikey>", "id": 75, "args": {}, "method": "get_repo"} to http://127.0.0.1:5000
 
 rhodecode said:
 
@@ -105,7 +105,7 @@ Ups looks like we forgot to add an argum
 

	
 
Let's try again now giving the repoid as parameters::
 

	
 
    rhodecode-api get_repo repoid:rhodecode
 
    kallithea-api get_repo repoid:rhodecode
 

	
 
    calling {"api_key": "<apikey>", "id": 39, "args": {"repoid": "rhodecode"}, "method": "get_repo"} to http://127.0.0.1:5000
 
    rhodecode said:
kallithea/bin/kallithea_api.py
Show inline comments
 
file renamed from kallithea/bin/rhodecode_api.py to kallithea/bin/kallithea_api.py
 
@@ -32,10 +32,10 @@ from kallithea.bin.base import json, api
 

	
 
def argparser(argv):
 
    usage = (
 
      "rhodecode-api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
 
      "kallithea-api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
 
      "[--config=CONFIG] [--save-config] "
 
      "METHOD <key:val> <key2:val> ...\n"
 
      "Create config file: rhodecode-api --apikey=<key> --apihost=http://your.kallithea.server --save-config"
 
      "Create config file: kallithea-api --apikey=<key> --apihost=http://your.kallithea.server --save-config"
 
    )
 

	
 
    parser = argparse.ArgumentParser(description='RhodeCode API cli',
kallithea/bin/kallithea_backup.py
Show inline comments
 
file renamed from kallithea/bin/rhodecode_backup.py to kallithea/bin/kallithea_backup.py
 
@@ -39,7 +39,7 @@ logging.basicConfig(level=logging.DEBUG,
 
class BackupManager(object):
 
    def __init__(self, repos_location, rsa_key, backup_server):
 
        today = datetime.datetime.now().weekday() + 1
 
        self.backup_file_name = "rhodecode_repos.%s.tar.gz" % today
 
        self.backup_file_name = "repos.%s.tar.gz" % today
 

	
 
        self.id_rsa_path = self.get_id_rsa(rsa_key)
 
        self.repos_path = self.get_repos_path(repos_location)
kallithea/bin/kallithea_config.py
Show inline comments
 
modified file chmod 100644 => 100755
 
file renamed from kallithea/bin/rhodecode_config.py to kallithea/bin/kallithea_config.py
 
@@ -12,7 +12,7 @@
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
"""
 
kallithea.bin.rhodecode_config
 
kallithea.bin.kallithea_config
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
configuration generator for RhodeCode
 
@@ -35,7 +35,7 @@ here = os.path.dirname(os.path.abspath(_
 

	
 
def argparser(argv):
 
    usage = (
 
      "rhodecode-config [-h] [--filename=FILENAME] [--template=TEMPLATE] \n"
 
      "kallithea-config [-h] [--filename=FILENAME] [--template=TEMPLATE] \n"
 
      "VARS optional specify extra template variable that will be available in "
 
      "template. Use comma separated key=val format eg.\n"
 
      "key1=val1,port=5000,host=127.0.0.1,elements='a\,b\,c'\n"
kallithea/bin/kallithea_gist.py
Show inline comments
 
file renamed from kallithea/bin/rhodecode_gist.py to kallithea/bin/kallithea_gist.py
 
@@ -12,7 +12,7 @@
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
"""
 
kallithea.bin.rhodecode_gist
 
kallithea.bin.kallithea_gist
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
Gist CLI client for RhodeCode
 
@@ -35,10 +35,10 @@ from kallithea.bin.base import json, api
 

	
 
def argparser(argv):
 
    usage = (
 
      "rhodecode-gist [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
 
      "kallithea-gist [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
 
      "[--config=CONFIG] [--save-config] [GIST OPTIONS] "
 
      "[filename or stdin use - for terminal stdin ]\n"
 
      "Create config file: rhodecode-gist --apikey=<key> --apihost=http://your.kallithea.server --save-config"
 
      "Create config file: kallithea-gist --apikey=<key> --apihost=http://your.kallithea.server --save-config"
 
    )
 

	
 
    parser = argparse.ArgumentParser(description='RhodeCode Gist cli',
kallithea/bin/ldap_sync.py
Show inline comments
 
modified file chmod 100644 => 100755
 
@@ -45,7 +45,7 @@ class InvalidResponseIDError(Exception):
 
    """ Request and response don't have the same UUID. """
 

	
 

	
 
class RhodecodeResponseError(Exception):
 
class ResponseError(Exception):
 
    """ Response has an error, something went wrong with request execution. """
 

	
 

	
 
@@ -57,7 +57,7 @@ class UserNotInGroupError(Exception):
 
    """ User is not a member of the target group. """
 

	
 

	
 
class RhodecodeAPI(object):
 
class API(object):
 

	
 
    def __init__(self, url, key):
 
        self.url = url
 
@@ -72,7 +72,7 @@ class RhodecodeAPI(object):
 
            "args": args
 
        }
 

	
 
    def rhodecode_api_post(self, method, args):
 
    def post(self, method, args):
 
        """Send a generic API post to Rhodecode.
 

	
 
        This will generate the UUID for validation check after the
 
@@ -92,7 +92,7 @@ class RhodecodeAPI(object):
 
            raise InvalidResponseIDError("UUID does not match.")
 

	
 
        if response["error"] is not None:
 
            raise RhodecodeResponseError(response["error"])
 
            raise ResponseError(response["error"])
 

	
 
        return response["result"]
 

	
 
@@ -102,7 +102,7 @@ class RhodecodeAPI(object):
 
            "group_name": name,
 
            "active": str(active)
 
        }
 
        self.rhodecode_api_post("create_user_group", args)
 
        self.post("create_user_group", args)
 

	
 
    def add_membership(self, group, username):
 
        """Add specific user to a group."""
 
@@ -110,7 +110,7 @@ class RhodecodeAPI(object):
 
            "usersgroupid": group,
 
            "userid": username
 
        }
 
        result = self.rhodecode_api_post("add_user_to_user_group", args)
 
        result = self.post("add_user_to_user_group", args)
 
        if not result["success"]:
 
            raise UserAlreadyInGroupError("User %s already in group %s." %
 
                                          (username, group))
 
@@ -121,7 +121,7 @@ class RhodecodeAPI(object):
 
            "usersgroupid": group,
 
            "userid": username
 
        }
 
        result = self.rhodecode_api_post("remove_user_from_user_group", args)
 
        result = self.post("remove_user_from_user_group", args)
 
        if not result["success"]:
 
            raise UserNotInGroupError("User %s not in group %s." %
 
                                      (username, group))
 
@@ -129,7 +129,7 @@ class RhodecodeAPI(object):
 
    def get_group_members(self, name):
 
        """Get the list of member usernames from a user group."""
 
        args = {"usersgroupid": name}
 
        members = self.rhodecode_api_post("get_user_group", args)['members']
 
        members = self.post("get_user_group", args)['members']
 
        member_list = []
 
        for member in members:
 
            member_list.append(member["username"])
 
@@ -138,12 +138,12 @@ class RhodecodeAPI(object):
 
    def get_group(self, name):
 
        """Return group info."""
 
        args = {"usersgroupid": name}
 
        return self.rhodecode_api_post("get_user_group", args)
 
        return self.post("get_user_group", args)
 

	
 
    def get_user(self, username):
 
        """Return user info."""
 
        args = {"userid": username}
 
        return self.rhodecode_api_post("get_user", args)
 
        return self.post("get_user", args)
 

	
 

	
 
class LdapClient(object):
 
@@ -202,7 +202,7 @@ class LdapSync(object):
 
                                      config.get("default", "ldap_user"),
 
                                      config.get("default", "ldap_key"),
 
                                      config.get("default", "base_dn"))
 
        self.rhodocode_api = RhodecodeAPI(config.get("default", "api_url"),
 
        self.rhodocode_api = API(config.get("default", "api_url"),
 
                                          config.get("default", "api_key"))
 

	
 
    def update_groups_from_ldap(self):
 
@@ -211,7 +211,7 @@ class LdapSync(object):
 
        groups = self.ldap_client.get_groups()
 
        for group in groups:
 
            try:
 
                self.rhodecode_api.create_repo_group(group)
 
                self.kallithea_api.create_repo_group(group)
 
                added += 1
 
            except Exception:
 
                existing += 1
 
@@ -219,25 +219,25 @@ class LdapSync(object):
 
        return added, existing
 

	
 
    def update_memberships_from_ldap(self, group):
 
        """Update memberships in rhodecode based on the LDAP groups."""
 
        """Update memberships based on the LDAP groups."""
 
        groups = self.ldap_client.get_groups()
 
        group_users = self.ldap_client.get_group_users(groups, group)
 

	
 
        # Delete memberships first from each group which are not part
 
        # of the group any more.
 
        rhodecode_members = self.rhodecode_api.get_group_members(group)
 
        for rhodecode_member in rhodecode_members:
 
            if rhodecode_member not in group_users:
 
        members = self.kallithea_api.get_group_members(group)
 
        for member in members:
 
            if member not in group_users:
 
                try:
 
                    self.rhodocode_api.remove_membership(group,
 
                                                         rhodecode_member)
 
                                                         member)
 
                except UserNotInGroupError:
 
                    pass
 

	
 
        # Add memberships.
 
        for member in group_users:
 
            try:
 
                self.rhodecode_api.add_membership(group, member)
 
                self.kallithea_api.add_membership(group, member)
 
            except UserAlreadyInGroupError:
 
                # TODO: handle somehow maybe..
 
                pass
 
@@ -252,5 +252,5 @@ if __name__ == '__main__':
 
        # How should we handle this.. Either sync users as well at this step,
 
        # or just ignore those who don't exist. If we want the second case,
 
        # we need to find a way to recognize the right exception (we always get
 
        # RhodecodeResponseError with no error code so maybe by return msg (?)
 
        # ResponseError with no error code so maybe by return msg (?)
 
        sync.update_memberships_from_ldap(gr)
kallithea/tests/scripts/create_rc.sh
Show inline comments
 
@@ -6,12 +6,12 @@ API_KEY=`psql -R " " -A -U postgres -h l
 
echo "run those after running server"
 
paster serve rc.ini --pid-file=rc.pid --daemon
 
sleep 3
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo1 password:qweqwe email:demo1@example.com
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo2 password:qweqwe email:demo2@example.com
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo3 password:qweqwe email:demo3@example.com
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user_group group_name:demo12
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo1
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo2
 
kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo1 password:qweqwe email:demo1@example.com
 
kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo2 password:qweqwe email:demo2@example.com
 
kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo3 password:qweqwe email:demo3@example.com
 
kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user_group group_name:demo12
 
kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo1
 
kallithea-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo2
 
echo "killing server"
 
kill `cat rc.pid`
 
rm rc.pid
setup.py
Show inline comments
 
@@ -158,9 +158,9 @@ setup(
 
    paster_plugins=['PasteScript', 'Pylons'],
 
    entry_points="""
 
    [console_scripts]
 
    rhodecode-api =    kallithea.bin.rhodecode_api:main
 
    rhodecode-gist =   kallithea.bin.rhodecode_gist:main
 
    rhodecode-config = kallithea.bin.rhodecode_config:main
 
    kallithea-api =    kallithea.bin.kallithea_api:main
 
    kallithea-gist =   kallithea.bin.kallithea_gist:main
 
    kallithea-config = kallithea.bin.kallithea_config:main
 

	
 
    [paste.app_factory]
 
    main = kallithea.config.middleware:make_app
0 comments (0 inline, 0 general)