Class: Aspera::Keychain::MacosSystem

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

Constant Summary

Constants inherited from Base

Base::CONTENT_KEYS

Instance Method Summary collapse

Methods inherited from Base

#ids, #validate_set

Constructor Details

#initialize(name: nil) ⇒ MacosSystem

Returns a new instance of MacosSystem.



127
128
129
130
131
132
# File 'lib/aspera/keychain/macos_security.rb', line 127

def initialize(name: nil)
  super()
  @keychain_name = name.nil? ? 'default keychain' : name
  @keychain = name.nil? ? MacosSecurity::Keychain.default : MacosSecurity::Keychain.by_name(name)
  Aspera.assert(!@keychain.nil?) { "no such keychain #{name}" }
end

Instance Method Details

#all ⇒ Object

Raises:



140
141
142
143
# File 'lib/aspera/keychain/macos_security.rb', line 140

def all
  # the only way to list is `dump-keychain` which triggers security alert
  raise Error, 'overview not implemented, use macos keychain app'
end

#delete(label:) ⇒ Object

Raises:



166
167
168
# File 'lib/aspera/keychain/macos_security.rb', line 166

def delete(label:)
  raise Error, 'delete not implemented, use macos keychain app'
end

#get(label:, exception: true) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/aspera/keychain/macos_security.rb', line 153

def get(label:, exception: true)
  info = @keychain.password(:find, :generic, label: label)
  if info.nil?
    raise "Secret '#{label}' not found" if exception
    return
  end
  return {
    label:       label,
    password:    info['password'],
    description: info['icmt'] # cspell: disable-line
  }
end

#info ⇒ Object



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

def info
  return {
    keychain: @keychain_name
  }
end

#set(options) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/aspera/keychain/macos_security.rb', line 145

def set(options)
  validate_set(options)
  @keychain.password(
    :add, :generic, service: options[:label],
    account: options[:username] || 'none', password: options[:password], comment: options[:description]
  )
end