开发者

fabric and svn password

Assuming that I开发者_运维技巧 cannot run something like this with Fabric:

run("svn update --password 'password' .")

how's the proper way to pass to Fabric the password for the remote interactive command line?

The problem is that the repo is checked out as svn+ssh and I don't have a http/https/svn option


Try SSHkey. It allows you to connect to the server without password. In this case, you will have to setup a sshkey between your remote server and the repo.

At remote server: Generate key pair

 $ ssh-keygen -t dsa

Leave the passphase empty! This will generate 2 files

  • ~/.ssh/id_dsa (private key)
  • ~/.ssh/id_dsa.pub (public key)

Then, append the content in id_dsa.pub to ~/.ssh/authorized_keys at repo server.

Your remote server will be able to update the source tree without any password required.


If yout just want to hide your password from log, you can use something like this:

from fabric.state import output

def xrun(command, hidden='', *args, **kwargs):
    old_state = output.running
    output.running = False
    print '[%s] run: %s' % (env.host_string, command)
    run(command + hidden, *args, **kwargs)
    output.running = command

xrun('svn update', '--password "your password"')


We had a problem similar to this a while back and actually proposed a new feature for Fabric, but the developer we spoke to suggested this instead.

import getpass
password = getpass.getpass('Enter SVN Password: ')
run("svn update --password '%s'" % password)

This will prompt you for a password when the time comes for fabric to run this command.

I believe that will display your password in the fabric log, however, so a better option would be to get SVN to prompt you for the password and echo the password into it.

run('echo %s | svn update --password' % password)

I don't use SVN though, so I'm afraid I'm not sure if that is possible. I hope someone else can help there!


My standard answer for automating interactive command lines is "use Expect", but you're using Python, so I will slightly refine that to "use Pexpect".

It might take a bit of thought to integrate Pexpect within Fabric, or perhaps you will just end up falling back to Pexpect alone for this particular case. But it's definitely the way I would go.


You might need to supply the user as well? If not, you may have better luck exporting your repo and making a tar of it (locally) to upload+deploy on the server. If you run the svn commands locally, you'll be able to get prompted for your username and/or password.


You should take a look at the Fabric's env documentation. There states that you should make something like this:

from fabric.api import env

env.user = 'your_user'
env.password = 'your_password'

Hope it helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜