Module: Browserctl::Commands::PassphrasePrompt

Defined in:
lib/browserctl/commands/passphrase_prompt.rb

Overview

Stdin/stderr passphrase prompting for ‘browserctl state` commands. Honours `BROWSERCTL_STATE_PASSPHRASE` for non-interactive use; otherwise reads from a tty with echo disabled and optional confirmation.

Class Method Summary collapse

Class Method Details

.needed_for?(client, name) ⇒ Boolean

Peek at the manifest first so we only prompt when the bundle is actually encrypted.

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/browserctl/commands/passphrase_prompt.rb', line 27

def needed_for?(client, name)
  info = client.state_info(name)
  return false if info[:error] || info["error"]

  manifest = info[:info] || info["info"] || {}
  manifest[:encrypted] || manifest["encrypted"] || false
end

.read(confirm: false) ⇒ String

Returns:

  • (String)


14
15
16
17
18
19
20
21
22
23
# File 'lib/browserctl/commands/passphrase_prompt.rb', line 14

def read(confirm: false)
  return ENV["BROWSERCTL_STATE_PASSPHRASE"] if ENV["BROWSERCTL_STATE_PASSPHRASE"]

  pass = ask("Passphrase: ")
  if confirm
    confirm_pass = ask("Confirm passphrase: ")
    abort "Passphrases do not match." unless pass == confirm_pass
  end
  pass
end