How to check if a svn command needs authentication

Is there any possible way to check if a SVN update needs authentication or not?

Scenario : I have written a ruby GUI app which updates SVN repositories (from a static path) in a scheduled manner. This executes as a windows service. Also have tortoisesvn installed.

In ruby when I execute

svn update local_path_to_repository --username user --password password in my script then it works fine as I am passing the username & password with the update command.

But, tortoisesvn saves the password (by caching password, using standard Windows cryptography services to encrypt the password on disk) when I checkout the repository for the first time so I don't necessarily need to pass the username and password every time. Thus I just have svn update local_path_to_repository in my script.

Issue: This works fine until I change my LDAP password. Once my LDAP password is changed all the repository fails to get updated as it is requesting for the new password but there is no user interface for passing the new password.

I need to build the username and password UI only when svn updates needs those credentials but not always. How do I achieve this?

Update : Reading from the SVN book. I Understood that:

  • The client checks whether the user specified any credentials as command-line options (--username and/or --password). If not, or if these options fail to authenticate successfully, then
  • The client looks up the server's hostname, port, and realm in the runtime auth/ area, to see if the user already has the appropriate credentials cached. If not, or if the cached credentials fail to authenticate, then
  • Finally, the client resorts to prompting the user (unless instructed not to do so via the --non-interactive option or its client-specific equivalents).
  • But I did not find a way to check if authentication is required.

    Can anyone please help me!


    So I finally found a work around by doing:

    output = `svn update "#{repo_path}" --non-interactive 2>&1`
    check_authentication = output.include?("Authentication failed")
    

    if check_authentication returns true meaning authentication has failed then I build the GUI for entering the new password and send it to the user.

    链接地址: http://www.djcxy.com/p/24476.html

    上一篇: 在Python装饰器中引发异常是否是一种很好的模式?

    下一篇: 如何检查一个svn命令是否需要验证