Class: Sym::App::KeyChain
Overview
This class forms and shells several commands that wrap Mac OS-X security
command. They provide access to storing generic passwords in the KeyChain Access.
Class Attribute Summary collapse
-
.kind ⇒ Object
Returns the value of attribute kind.
-
.sub_section ⇒ Object
Returns the value of attribute sub_section.
-
.user ⇒ Object
Returns the value of attribute user.
Instance Attribute Summary collapse
-
#key_name ⇒ Object
Returns the value of attribute key_name.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#stderr_disabled ⇒ Object
Returns the value of attribute stderr_disabled.
Class Method Summary collapse
Instance Method Summary collapse
- #add(password) ⇒ Object
- #delete ⇒ Object
- #execute(command) ⇒ Object
- #find ⇒ Object
-
#initialize(key_name, opts = {}) ⇒ KeyChain
constructor
A new instance of KeyChain.
- #stderr_off ⇒ Object
- #stderr_on ⇒ Object
Constructor Details
#initialize(key_name, opts = {}) ⇒ KeyChain
Returns a new instance of KeyChain.
38 39 40 41 42 43 |
# File 'lib/sym/app/keychain.rb', line 38 def initialize(key_name, opts = {}) self.key_name = key_name self.opts = opts self.class.validate! stderr_off end |
Class Attribute Details
.kind ⇒ Object
Returns the value of attribute kind.
14 15 16 |
# File 'lib/sym/app/keychain.rb', line 14 def kind @kind end |
.sub_section ⇒ Object
Returns the value of attribute sub_section.
14 15 16 |
# File 'lib/sym/app/keychain.rb', line 14 def sub_section @sub_section end |
.user ⇒ Object
Returns the value of attribute user.
14 15 16 |
# File 'lib/sym/app/keychain.rb', line 14 def user @user end |
Instance Attribute Details
#key_name ⇒ Object
Returns the value of attribute key_name.
36 37 38 |
# File 'lib/sym/app/keychain.rb', line 36 def key_name @key_name end |
#opts ⇒ Object
Returns the value of attribute opts.
36 37 38 |
# File 'lib/sym/app/keychain.rb', line 36 def opts @opts end |
#stderr_disabled ⇒ Object
Returns the value of attribute stderr_disabled.
36 37 38 |
# File 'lib/sym/app/keychain.rb', line 36 def stderr_disabled @stderr_disabled end |
Class Method Details
.configure {|_self| ... } ⇒ Object
20 21 22 |
# File 'lib/sym/app/keychain.rb', line 20 def configure yield self end |
.get(value) ⇒ Object
16 17 18 |
# File 'lib/sym/app/keychain.rb', line 16 def get(value) self.new(value).find end |
.validate! ⇒ Object
24 25 26 27 |
# File 'lib/sym/app/keychain.rb', line 24 def validate! raise ArgumentError.new( 'User is not defined. Either set $USER in environment, or directly on the class.') unless self.user end |
Instance Method Details
#add(password) ⇒ Object
45 46 47 |
# File 'lib/sym/app/keychain.rb', line 45 def add(password) execute command(:add, "-U -w '#{password}' ") end |
#delete ⇒ Object
53 54 55 |
# File 'lib/sym/app/keychain.rb', line 53 def delete execute command(:delete) end |
#execute(command) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sym/app/keychain.rb', line 57 def execute(command) command += ' 2>/dev/null' if stderr_disabled puts "> #{command.yellow.green}" if opts[:verbose] output = `#{command}` result = $? raise Sym::Errors::KeyChainCommandError.new("Command error: #{result}, command: #{command}") unless result.success? output.chomp rescue Errno::ENOENT => e raise Sym::Errors::KeyChainCommandError.new("Command error: #{e.}, command: #{command}") end |
#find ⇒ Object
49 50 51 |
# File 'lib/sym/app/keychain.rb', line 49 def find execute command(:find, ' -g -w ') end |
#stderr_off ⇒ Object
68 69 70 |
# File 'lib/sym/app/keychain.rb', line 68 def stderr_off self.stderr_disabled = true end |
#stderr_on ⇒ Object
72 73 74 |
# File 'lib/sym/app/keychain.rb', line 72 def stderr_on self.stderr_disabled = false end |