fabric 和 svn 密码
假设我不能用Fabric运行这样的命令:
run("svn update --password 'password' .")
那么,正确的方式是什么,才能把密码传给Fabric,让它在远程的交互式命令行中使用呢?
问题在于这个代码库是通过svn+ssh方式检出的,而我没有http/https/svn的选项。
6 个回答
2
我们之前遇到过类似的问题,实际上还为Fabric提出了一个新功能的建议,但我们和一位开发者讨论后,他建议了另一种方法。
import getpass
password = getpass.getpass('Enter SVN Password: ')
run("svn update --password '%s'" % password)
当Fabric需要执行这个命令时,它会要求你输入密码。
不过,我觉得这样做会把你的密码显示在Fabric的日志里,所以更好的办法是让SVN来提示你输入密码,并把密码传递给它。
run('echo %s | svn update --password' % password)
不过我不使用SVN,所以不太确定这样是否可行。希望其他人能提供帮助!
3
如果你只是想在日志中隐藏你的密码,可以使用类似下面的代码:
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"')
7
试试SSH密钥吧。它可以让你在连接服务器时不用输入密码。这样的话,你需要在你的远程服务器和代码库之间设置一个SSH密钥。
在远程服务器上:生成一对密钥
$ ssh-keygen -t dsa
记得把密码短语留空!这样会生成两个文件:
- ~/.ssh/id_dsa(私钥)
- ~/.ssh/id_dsa.pub(公钥)
然后,把id_dsa.pub里的内容添加到代码库服务器的~/.ssh/authorized_keys文件中。
这样,你的远程服务器就可以在不需要密码的情况下更新源代码了。