Class: OSX::Keychain
- Inherits:
-
Object
- Object
- OSX::Keychain
- Defined in:
- lib/keychain_osx/keychain.rb
Instance Attribute Summary collapse
-
#keychain_path ⇒ Object
Returns the value of attribute keychain_path.
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_search_path ⇒ Object
- #delete ⇒ Object
- #import(cert, password) ⇒ Object
-
#initialize(keychain_path, key_password) ⇒ Keychain
constructor
A new instance of Keychain.
- #set_default ⇒ Object
- #unlock(password) ⇒ Object
Constructor Details
#initialize(keychain_path, key_password) ⇒ Keychain
Returns a new instance of Keychain.
10 11 12 13 14 15 |
# File 'lib/keychain_osx/keychain.rb', line 10 def initialize(keychain_path, key_password) @keychain_path = keychain_path create(key_password) unlock(key_password) add_to_search_path end |
Instance Attribute Details
#keychain_path ⇒ Object
Returns the value of attribute keychain_path.
8 9 10 |
# File 'lib/keychain_osx/keychain.rb', line 8 def keychain_path @keychain_path end |
Class Method Details
.temp(&block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/keychain_osx/keychain.rb', line 50 def self.temp(&block) kc = OSX::Keychain.new(KEYCHAIN_LOCATION, TEMP_PASSWORD) kc.unlock(TEMP_PASSWORD) if block_given? # block is given begin yield(kc) ensure kc.delete end else kc.delete end end |
Instance Method Details
#add_to_search_path ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/keychain_osx/keychain.rb', line 37 def add_to_search_path keychains = [] `security list-keychain`.split.map do |keychain| keychains << keychain.strip.gsub(/\"/,'') end keychains << @keychain_path command = "security list-keychain -s #{keychains.join(' ')}" OSX::Command::run(command) end |
#delete ⇒ Object
27 28 29 30 |
# File 'lib/keychain_osx/keychain.rb', line 27 def delete command = "security delete-keychain #{@keychain_path}" OSX::Command::run(command) end |
#import(cert, password) ⇒ Object
22 23 24 25 |
# File 'lib/keychain_osx/keychain.rb', line 22 def import(cert, password) command = "security import '#{cert}' -k \"#{@keychain_path}\" -P #{password} -T /usr/bin/codesign" OSX::Command::run(command) end |