6

デプロイメントを自動化するためにFabricを使用しています。このプロセスでは、プロンプト機能を使用してユーザーに入力を求めます。特に、パスワードを要求する必要があり、Python getpassを使用するように、ユーザーが入力した値を非表示にします。とargspromptの処理のために使用したいと思います。keyvalidate

これを行うためのFabric組み込みの方法はありますか、またはプロンプトソースを変更する必要がありますか(最終的にはプルリクエストを送信します)?

4

1 に答える 1

6

prompt_for_passwordで使用できる場合がありますfabric.network

def prompt_for_password(prompt=None, no_colon=False, stream=None):
    """
    Prompts for and returns a new password if required; otherwise, returns
    None.

    A trailing colon is appended unless ``no_colon`` is True.

    If the user supplies an empty password, the user will be re-prompted until
    they enter a non-empty password.

    ``prompt_for_password`` autogenerates the user prompt based on the current
    host being connected to. To override this, specify a string value for
    ``prompt``.

    ``stream`` is the stream the prompt will be printed to; if not given,
    defaults to ``sys.stderr``.
    """
    from fabric.state import env
    handle_prompt_abort("a connection or sudo password")
    stream = stream or sys.stderr
    # Construct prompt
    default = "[%s] Login password for '%s'" % (env.host_string, env.user)
    password_prompt = prompt if (prompt is not None) else default
    if not no_colon:
        password_prompt += ": "
    # Get new password value
    new_password = getpass.getpass(password_prompt, stream)
    # Otherwise, loop until user gives us a non-empty password (to prevent
    # returning the empty string, and to avoid unnecessary network overhead.)
    while not new_password:
        print("Sorry, you can't enter an empty password. Please try again.")
        new_password = getpass.getpass(password_prompt, stream)
    return new_password

これは、ファブリックが ssh のパスワードを取得する方法のように見えます。次に、これをenv使用するように設定します。

def set_password(password):
    from fabric.state import env
    env.password = env.passwords[env.host_string] = password

キーは設定することで簡単に交換できenvますが、自分で検証する必要があるようです...

于 2012-11-01T15:23:55.690 に答える