class Boxen::Keychain

Constants

HELPER

The keychain proxy we use to provide isolation and a friendly message in security prompts.

PASSWORD_SERVICE

The service name to use when loading/saving passwords.

TOKEN_SERVICE

The service name to use when loading/saving API keys.

Attributes

login[R]

Public Class Methods

new(login) click to toggle source
# File lib/boxen/keychain.rb, line 19
def initialize(login)
  @login = login
  # Clear the password. We're storing tokens now.
  set PASSWORD_SERVICE, ""
end

Public Instance Methods

token() click to toggle source
# File lib/boxen/keychain.rb, line 25
def token
  get TOKEN_SERVICE
end
token=(token) click to toggle source
# File lib/boxen/keychain.rb, line 29
def token=(token)
  set TOKEN_SERVICE, token
end

Protected Instance Methods

get(service) click to toggle source
# File lib/boxen/keychain.rb, line 37
def get(service)
  cmd = shellescape(HELPER, service, login)

  result = `#{cmd}`.strip
  $?.success? ? result : nil
end
set(service, token) click to toggle source
# File lib/boxen/keychain.rb, line 44
def set(service, token)
  cmd = shellescape(HELPER, service, login, token)

  unless system *cmd
    raise Boxen::Error, "Can't save #{service} in the keychain."
  end

  token
end
shellescape(*args) click to toggle source
# File lib/boxen/keychain.rb, line 54
def shellescape(*args)
  args.map { |s| Shellwords.shellescape s }.join " "
end