class Aspera::Keychain::MacosSecurity

keychain based on macOS keychain, using ‘security` cmmand line

def delete(options)

def delete(options)
  raise 'options shall be Hash' unless options.is_a?(Hash)
  unsupported=options.keys-[:username,:url]
  raise "unsupported options: #{unsupported}" unless unsupported.empty?
  username=options[:username]
  raise 'options shall have username' if username.nil?
  url=options[:url]
  raise 'delete not implemented'
end

def get(options)

def get(options)
  raise 'options shall be Hash' unless options.is_a?(Hash)
  unsupported=options.keys-[:username,:url]
  raise "unsupported options: #{unsupported}" unless unsupported.empty?
  username=options[:username]
  raise 'options shall have username' if username.nil?
  url=options[:url]
  raise 'options shall have url' if url.nil?
  info=Security::InternetPassword.find(keychain: @keychain, url: url, account: username)
  raise 'not found' if info.nil?
  result=options.clone
  result.merge!({secret: info.password, description: info.attributes['icmt']})
  return result
end

def initialize(name=nil)

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

def list

def list
  raise 'list not implemented'
end

def set(options)

def set(options)
  raise 'options shall be Hash' unless options.is_a?(Hash)
  unsupported=options.keys-[:username,:url,:secret,:description]
  raise "unsupported options: #{unsupported}" unless unsupported.empty?
  username=options[:username]
  raise 'options shall have username' if username.nil?
  url=options[:url]
  raise 'options shall have url' if url.nil?
  secret=options[:secret]
  raise 'options shall have secret' if secret.nil?
  raise 'set not implemented'
  self
end