Fabric 和 svn 密码

发布于 2024-08-27 13:14:25 字数 185 浏览 7 评论 0原文

假设我无法使用 Fabric 运行类似的操作:

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

将远程交互式命令行的密码传递给 Fabric 的正确方法是什么?

问题是仓库被签出为 svn+ssh 并且我没有 http/https/svn 选项

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

oО清风挽发oО 2024-09-03 13:14:25

尝试 SSHkey。它允许您无需密码即可连接到服务器。
在这种情况下,您必须在远程服务器和存储库之间设置 sshkey。

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

 $ ssh-keygen -t dsa

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

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

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

您的远程服务器将能够更新源代码树,无需任何密码。

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.

从来不烧饼 2024-09-03 13:14:25

如果您只是想在日志中隐藏密码,您可以使用如下内容:

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"')

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"')
不如归去 2024-09-03 13:14:25

不久前我们遇到了类似的问题,实际上为 Fabric 提出了一个新功能,但我们采访的开发人员却建议这样做。

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

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

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

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

不过我不使用 SVN,所以我担心我不确定这是否可能。我希望其他人可以提供帮助!

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!

栀梦 2024-09-03 13:14:25

我对自动化交互式命令行的标准答案是“使用 Expect”,但您使用的是 Python,所以我将稍微改进为“使用 期望"。

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

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.

巴黎夜雨 2024-09-03 13:14:25

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

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.

又爬满兰若 2024-09-03 13:14:25

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

from fabric.api import env

env.user = 'your_user'
env.password = 'your_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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文