Class: Ironclad::Source::OnePassword

Inherits:
Object
  • Object
show all
Defined in:
lib/ironclad/source/one_password.rb

Overview

Reads a secret from 1Password via the ‘op` CLI.

Instance Method Summary collapse

Constructor Details

#initialize(account = nil) ⇒ OnePassword

Returns a new instance of OnePassword.



9
10
11
# File 'lib/ironclad/source/one_password.rb', line 9

def initialize( = nil)
  @account = 
end

Instance Method Details

#read(reference) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ironclad/source/one_password.rb', line 13

def read(reference)
  cmd = ['op', 'read', reference]
  cmd.push('--account', @account) if @account

  out, err, status = Open3.capture3(*cmd)
  unless status.success?
    message = 'Could not read the credentials key from 1Password. ' \
              'Authorize the prompt and retry, or run: op signin'
    detail = err.strip
    message += " (#{detail})" unless detail.empty?
    raise Error, message
  end

  out.chomp
end