Class: Aspera::Secret::Store::MacosSystem
- Defined in:
- lib/aspera/secret/store/macos_security.rb
Overview
Vault backend implementation wrapping macOS system keychain
Constant Summary collapse
- PARAMETERS =
%i[name].freeze
Constants inherited from Base
Base::CONTENT_KEYS, Base::REFERENCE_OPTIONS
Instance Method Summary collapse
-
#all ⇒ Object
Overview of all secrets (not supported on macOS due to OS restrictions).
-
#delete(label:) ⇒ Hash?
Delete a secret by label.
-
#get(label:, exception: true) ⇒ Hash?
Retrieve a secret by label.
-
#info ⇒ Hash
Vault information metadata.
-
#initialize(name: nil) ⇒ MacosSystem
constructor
A new instance of MacosSystem.
-
#set(options) ⇒ Hash?
Store a secret in the keychain.
Methods inherited from Base
arguments, #assert_new_label, check_parameters, #check_reference, error_reason, #ids, #list_folder, #read_fields, #read_reference, #validate_set, #write_reference
Constructor Details
#initialize(name: nil) ⇒ MacosSystem
Returns a new instance of MacosSystem.
223 224 225 226 227 228 229 |
# File 'lib/aspera/secret/store/macos_security.rb', line 223 def initialize(name: nil) super() raise Error, 'type system: only on macOS' unless Environment.instance.os.eql?(Environment::OS_MACOS) @keychain_name = name.nil? ? 'default keychain' : name @keychain = name.nil? ? MacosSecurity::Keychain.default : MacosSecurity::Keychain.by_name(name) Aspera.assert(!@keychain.nil?, type: Error) { "no such keychain #{name}" } end |
Instance Method Details
#all ⇒ Object
Overview of all secrets (not supported on macOS due to OS restrictions)
240 241 242 243 |
# File 'lib/aspera/secret/store/macos_security.rb', line 240 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:) ⇒ Hash?
Delete a secret by label
277 278 279 |
# File 'lib/aspera/secret/store/macos_security.rb', line 277 def delete(label:) @keychain.password(:delete, :generic, label: label) end |
#get(label:, exception: true) ⇒ Hash?
Retrieve a secret by label
260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/aspera/secret/store/macos_security.rb', line 260 def get(label:, exception: true) info = @keychain.password(:find, :generic, label: label) if info.nil? raise NotFound, "Secret '#{label}' not found" if exception return end return { label: label, username: (info['acct'] unless info['acct'].eql?(NO_ACCOUNT)), password: info['password'], description: info['icmt'] }.compact end |
#info ⇒ Hash
Returns Vault information metadata.
232 233 234 235 236 |
# File 'lib/aspera/secret/store/macos_security.rb', line 232 def info return { keychain: @keychain_name } end |
#set(options) ⇒ Hash?
Store a secret in the keychain
248 249 250 251 252 253 254 |
# File 'lib/aspera/secret/store/macos_security.rb', line 248 def set() validate_set() @keychain.password( :add, :generic, service: [:label], account: [:username] || NO_ACCOUNT, password: [:password], comment: [:description] ) end |