Class: Pandoru::SecretStore::Adapters::MacOS

Inherits:
Base
  • Object
show all
Defined in:
lib/pandoru/secret_store.rb

Overview

macOS Keychain via ‘security`. Account is fixed to the service name; the secret blob is the password slot.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Pandoru::SecretStore::Adapters::Base

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/pandoru/secret_store.rb', line 104

def available?
  RUBY_PLATFORM.include?('darwin') && which?('security')
end

#delete(service) ⇒ Object



120
121
122
123
# File 'lib/pandoru/secret_store.rb', line 120

def delete(service)
  _out, ok = run(['security', 'delete-generic-password', '-s', service])
  ok
end

#nameObject



102
# File 'lib/pandoru/secret_store.rb', line 102

def name = 'macOS Keychain'

#read(service) ⇒ Object



108
109
110
111
# File 'lib/pandoru/secret_store.rb', line 108

def read(service)
  out, ok = run(['security', 'find-generic-password', '-s', service, '-w'])
  ok ? out.chomp : nil
end

#write(service, secret) ⇒ Object



113
114
115
116
117
118
# File 'lib/pandoru/secret_store.rb', line 113

def write(service, secret)
  _out, ok = run(['security', 'add-generic-password', '-U',
                  '-s', service, '-a', service, '-w', secret,
                  '-D', 'application password', '-l', service])
  ok
end