7

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

4

6 回答 6

7

试试 SSH 密钥。它允许您在没有密码的情况下连接到服务器。在这种情况下,您必须在远程服务器和 repo 之间设置一个 sshkey。

在远程服务器:生成密钥对

 $ ssh-keygen -t dsa

将密码阶段留空!这将生成2个文件

  • ~/.ssh/id_dsa(私钥)
  • ~/.ssh/id_dsa.pub(公钥)

然后,将 id_dsa.pub 中的内容附加到 repo 服务器的 ~/.ssh/authorized_keys 中。

您的远程服务器无需任何密码即可更新源代码树。

于 2010-04-07T15:13:26.957 回答
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"')
于 2011-01-26T18:47:43.980 回答
2

不久前我们遇到了类似的问题,实际上为 Fabric 提出了一个新功能,但我们与之交谈的开发人员提出了这个建议。

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

当结构需要运行此命令时,这将提示您输入密码。

但是,我相信这会在结构日志中显示您的密码,因此更好的选择是让 SVN 提示您输入密码并将密码回显到其中。

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

不过我不使用 SVN,所以恐怕我不确定这是否可能。我希望其他人可以在那里提供帮助!

于 2010-04-06T09:41:44.490 回答
2

我对自动化交互式命令行的标准答案是“使用 Expect”,但您使用的是 Python,所以我会稍微改进一下“使用Pexpect ”。

将 Pexpect 集成到 Fabric 中可能需要一些思考,或者您可能最终会在这种特殊情况下单独使用 Pexpect。但这绝对是我要走的路。

于 2010-04-06T22:04:36.093 回答
0

您应该查看Fabric 的 env 文档。那里说你应该做这样的事情:

from fabric.api import env

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

希望能帮助到你!

于 2010-04-08T15:23:26.957 回答
0

您可能还需要提供用户?如果没有,您可能会更幸运地导出您的 repo 并(本地)对其进行 tar 以在服务器上上传+部署。如果您在本地运行 svn 命令,系统会提示您输入用户名和/或密码。

于 2010-04-01T15:39:12.517 回答