2014-01-15 123 views
1

我需要驗證一些用戶是否是有效的SVN用戶,或者不在我的應用程序中。我想在Windows中使用SVN命令行工具/ Tortoise SVN Commndline或Python來實現這一點。我查閱了PySVN,但在我看來,無法驗證該庫中的當前用戶。 請建議一些相同的方法。使用命令行或Python進行SVN用戶身份驗證

謝謝

回答

0

看看爲pysvn.Client.callback_*的文件,你會看到,你有方法來提供手柄提示輸入密碼和錯誤,如果它們不匹配。

+0

是的,但只有在緩存中沒有用戶名密碼時纔會調用回調。我無法找到任何可以提供用戶名密碼信息並獲得結果的方法。如果我錯了,請糾正我。 –

0

您可以使用pysvn使用callback_get_login進行身份驗證。

按照documentation

callback_get_login被稱爲每次顛覆需要用戶名和密碼 的境界來訪問存儲庫並沒有緩存 憑證。

+0

請參閱我對史蒂夫巴恩斯的回答的評論。 –

0

使它工作似乎相當困難。我想出了以下結果:

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 

做些什麼:

  1. 它使用一個嘗試回調。因爲pysvn會一遍又一遍嘗試相同的 憑證,如果它們不起作用,我們需要停止它。
  2. 無憑據將被保留(可以忽略它,如果它不是 所需的行爲)

  3. 清除默認的用戶名和密碼,所以緩存不會被使用

  4. 禁用提示