Class: Aspera::Keychain::MacosSystem
- Inherits:
-
Object
- Object
- Aspera::Keychain::MacosSystem
- Defined in:
- lib/aspera/keychain/macos_security.rb
Constant Summary collapse
- OPTIONS =
%i[label username password url description].freeze
Instance Method Summary collapse
- #delete(options) ⇒ Object
- #get(options) ⇒ Object
- #info ⇒ Object
-
#initialize(name: nil) ⇒ MacosSystem
constructor
A new instance of MacosSystem.
- #list ⇒ Object
- #set(options) ⇒ Object
Constructor Details
#initialize(name: nil) ⇒ MacosSystem
Returns a new instance of MacosSystem.
127 128 129 130 131 |
# File 'lib/aspera/keychain/macos_security.rb', line 127 def initialize(name: nil) @keychain_name = name.nil? ? 'default keychain' : name @keychain = name.nil? ? MacosSecurity::Keychain.default : MacosSecurity::Keychain.by_name(name) raise "no such keychain #{name}" if @keychain.nil? end |
Instance Method Details
#delete(options) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/aspera/keychain/macos_security.rb', line 165 def delete() Aspera.assert_type(, Hash){'options'} unsupported = .keys - %i[label] Aspera.assert(unsupported.empty?){"unsupported options: #{unsupported}"} raise 'delete not implemented, use macos keychain app' end |
#get(options) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/aspera/keychain/macos_security.rb', line 153 def get() Aspera.assert_type(, Hash){'options'} unsupported = .keys - %i[label] Aspera.assert(unsupported.empty?){"unsupported options: #{unsupported}"} info = @keychain.password(:find, :generic, label: [:label]) raise 'not found' if info.nil? result = .clone result[:secret] = info['password'] result[:description] = info['icmt'] # cspell: disable-line return result end |
#info ⇒ Object
133 134 135 136 137 |
# File 'lib/aspera/keychain/macos_security.rb', line 133 def info return { keychain: @keychain_name } end |
#list ⇒ Object
139 140 141 142 |
# File 'lib/aspera/keychain/macos_security.rb', line 139 def list # the only way to list is `dump-keychain` which triggers security alert raise 'list not implemented, use macos keychain app' end |
#set(options) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/aspera/keychain/macos_security.rb', line 144 def set() Aspera.assert_type(, Hash){'options'} unsupported = .keys - OPTIONS Aspera.assert(unsupported.empty?){"unsupported options: #{unsupported}, use #{OPTIONS.join(', ')}"} @keychain.password( :add, :generic, service: [:label], account: [:username] || 'none', password: [:password], comment: [:description]) end |