Module: SystemKeychain::Store::Mac

Defined in:
lib/system_keychain/store/mac.rb

Class Method Summary collapse

Class Method Details

.get(url) ⇒ Object



10
11
12
13
14
15
# File 'lib/system_keychain/store/mac.rb', line 10

def self.get(url)
  match = `security find-generic-password -s #{Shellwords.escape(url)} -g 2>&1`.match(/password: "([^"]*)".*acct"<blob>="([^"]*)"/m)
  return nil unless match
  pass, user = match.captures
  return [user, pass]
end

.is_validObject



6
7
8
# File 'lib/system_keychain/store/mac.rb', line 6

def self.is_valid
  `which security` == "/usr/bin/security\n"
end

.remove(url) ⇒ Object



17
18
19
# File 'lib/system_keychain/store/mac.rb', line 17

def self.remove(url)
  `security delete-generic-password -s #{Shellwords.escape(url)}`
end

.save(url, user, pass, description = url) ⇒ Object



21
22
23
# File 'lib/system_keychain/store/mac.rb', line 21

def self.save(url, user, pass, description = url)
  `security add-generic-password -l #{Shellwords.escape(description)} -s #{Shellwords.escape(url)} -a #{Shellwords.escape(user)} -p #{Shellwords.escape(pass)}`
end