Class: Aspera::Keychain::MacosSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/keychain/macos_security.rb

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, _password = nil) ⇒ MacosSystem

Returns a new instance of MacosSystem.

[View source]

126
127
128
129
# File 'lib/aspera/keychain/macos_security.rb', line 126

def initialize(name=nil, _password=nil)
  @keychain = name.nil? ? MacosSecurity::Keychain.default_keychain : MacosSecurity::Keychain.by_name(name)
  raise "no such keychain #{name}" if @keychain.nil?
end

Instance Method Details

#delete(options) ⇒ Object

[View source]

157
158
159
160
161
162
# File 'lib/aspera/keychain/macos_security.rb', line 157

def delete(options)
  Aspera.assert_type(options, Hash){'options'}
  unsupported = options.keys - %i[label]
  Aspera.assert(unsupported.empty?){"unsupported options: #{unsupported}"}
  raise 'delete not implemented, use macos keychain app'
end

#get(options) ⇒ Object

[View source]

140
141
142
143
144
145
146
147
148
149
150
# File 'lib/aspera/keychain/macos_security.rb', line 140

def get(options)
  Aspera.assert_type(options, Hash){'options'}
  unsupported = options.keys - %i[label]
  Aspera.assert(unsupported.empty?){"unsupported options: #{unsupported}"}
  info = @keychain.password(:find, :generic, label: options[:label])
  raise 'not found' if info.nil?
  result = options.clone
  result[:secret] = info['password']
  result[:description] = info['icmt'] # cspell: disable-line
  return result
end

#listObject

[View source]

152
153
154
155
# File 'lib/aspera/keychain/macos_security.rb', line 152

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

[View source]

131
132
133
134
135
136
137
138
# File 'lib/aspera/keychain/macos_security.rb', line 131

def set(options)
  Aspera.assert_type(options, Hash){'options'}
  unsupported = options.keys - %i[label username password url description]
  Aspera.assert(unsupported.empty?){"unsupported options: #{unsupported}"}
  @keychain.password(
    :add, :generic, service: options[:label],
    account: options[:username] || 'none', password: options[:password], comment: options[:description])
end