简体   繁体   中英

SVN User authentication using Command Line or Python

I need to verify if some user is valid SVN user or not in my application. I want to achieve this using SVN commandline tools/Tortoise SVN Commndline or Python in windows. I looked up PySVN but it seems to me that there is no way to authenticate a current user in that library. Please suggest some way of doing the same.

Thank You

查看pysvn.Client.callback_*的文档,您将看到您必须提供的方法可以处理提示密码和错误的提示(如果它们不匹配)。

You can use pysvn to authenticate using the callback_get_login .

According to the documentation :

callback_get_login is called each time subversion needs a username and password in the realm to access a repository and has no cached credentials.

It seems quite hard to make it work. I came up with following result:

def get_prepared_svn_client(self, username, pwd):
    client=pysvn.Client()
    class OneAttemptLogin:
        """ 
        if login failed, pysvn goes into infinite loop.
        this class is used as callback; it allows only one login attempt
        """
        def __init__(self, username, pwd):
            self.attempt_tried=False
            self.username=username
            self.pwd=pwd
        def __call__(self, x,y,z):
            if not self.attempt_tried:
                self.attempt_tried=True
                return (True, self.username, self.pwd, False)
            else:
                return (False, "xx", "xx", False)
    client.callback_get_login=OneAttemptLogin(username, pwd)
    client.set_auth_cache(False)
    client.set_store_passwords(False)
    client.set_default_username('')
    client.set_default_password('')
    client.set_interactive(False)
    return client

What it does:

  1. it uses one-attempt callback. Because pysvn will try the same credentials over and over if they won't work, we need to stop it.
  2. No credentials will be preserved (you can omit it if it's not desired behaviour)

  3. Clear default username and password, so cache will not be used

  4. disable prompt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM