简体   繁体   English

使用命令行或Python的SVN用户身份验证

[英]SVN User authentication using Command Line or Python

I need to verify if some user is valid SVN user or not in my application. 我需要验证我的应用程序中是否有某些用户是有效的SVN用户。 I want to achieve this using SVN commandline tools/Tortoise SVN Commndline or Python in windows. 我想在Windows中使用SVN命令行工具/ Tortoise SVN Commndline或Python实现此目的。 I looked up PySVN but it seems to me that there is no way to authenticate a current user in that library. 我查了一下PySVN,但在我看来,没有办法在该库中对当前用户进行身份验证。 Please suggest some way of doing the same. 请提出一些相同的方法。

Thank You 谢谢

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

You can use pysvn to authenticate using the callback_get_login . 您可以使用pysvn通过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. 每当子版本在领域中需要用户名和密码来访问存储库且没有高速缓存的凭据时,都会调用callback_get_login。

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. 由于pysvn如果无法使用将反复尝试相同的凭据,因此我们需要停止它。
  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 禁用提示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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