Class: Exportation::Keychain
- Inherits:
-
Object
- Object
- Exportation::Keychain
- Defined in:
- lib/exportation.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
- .find_or_create_keychain(name, password, output_directory = './') ⇒ Object
- .list_keychains ⇒ Object
- .login_keychain(password) ⇒ Object
Instance Method Summary collapse
- #add_to_keychain_list! ⇒ Object
- #import_certificate(cer_path) ⇒ Object
- #import_private_key(key_path, password) ⇒ Object
-
#initialize(options) ⇒ Keychain
constructor
A new instance of Keychain.
- #remove_keychain_from_list! ⇒ Object
- #unlock!(seconds = 3600) ⇒ Object
Constructor Details
#initialize(options) ⇒ Keychain
Returns a new instance of Keychain.
122 123 124 125 |
# File 'lib/exportation.rb', line 122 def initialize() @path = [:path] @password = [:password] end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
120 121 122 |
# File 'lib/exportation.rb', line 120 def password @password end |
#path ⇒ Object
Returns the value of attribute path.
120 121 122 |
# File 'lib/exportation.rb', line 120 def path @path end |
Class Method Details
.find_or_create_keychain(name, password, output_directory = './') ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/exportation.rb', line 127 def self.find_or_create_keychain(name, password, output_directory='./') path = chain_path(name, output_directory) unless File.exists? path `security create-keychain -p '#{password}' #{path}` end Keychain.new(path: path, password: password) end |
.list_keychains ⇒ Object
142 143 144 145 146 |
# File 'lib/exportation.rb', line 142 def self.list_keychains # Gets a list of all the user's keychains in an array # The keychain are paths wrapped in double quotes (`security list-keychains -d user`).scan(/(?:\w|"[^"]*")+/) end |
Instance Method Details
#add_to_keychain_list! ⇒ Object
164 165 166 167 168 |
# File 'lib/exportation.rb', line 164 def add_to_keychain_list! # Adds the keychain to the search list keychains = (Keychain.list_keychains - ["\"#{@path}\""]).join(' ') `security list-keychains -d user -s #{keychains} \"#{@path}\"` end |
#import_certificate(cer_path) ⇒ Object
148 149 150 151 |
# File 'lib/exportation.rb', line 148 def import_certificate(cer_path) # Imports a certificate into the keychain `security import #{cer_path} -k #{@path} -T /usr/bin/codesign` end |
#import_private_key(key_path, password) ⇒ Object
153 154 155 156 |
# File 'lib/exportation.rb', line 153 def import_private_key(key_path, password) # Imports a private key into the keychain `security import #{key_path} -k #{@path} -P '#{password}' -T /usr/bin/codesign` end |
#remove_keychain_from_list! ⇒ Object
170 171 172 173 174 |
# File 'lib/exportation.rb', line 170 def remove_keychain_from_list! # Removes the keychain from the search list keychains = (Keychain.list_keychains - ["\"#{@path}\""]).join(' ') `security list-keychains -d user -s #{keychains}` end |
#unlock!(seconds = 3600) ⇒ Object
158 159 160 161 162 |
# File 'lib/exportation.rb', line 158 def unlock!(seconds=3600) # Unlocks the keychain `security unlock-keychain -p '#{@password}' #{@path}` `security -v set-keychain-settings -t #{seconds} -l #{@path}` end |