Class: Zanzibar::Actions::Get

Inherits:
Base
  • Object
show all
Defined in:
lib/zanzibar/actions/get.rb

Overview

Fetch a single secret

Instance Attribute Summary collapse

Attributes inherited from Base

#logger, #options

Instance Method Summary collapse

Constructor Details

#initialize(ui, options, scrt_id) ⇒ Get

Initialize the action



20
21
22
23
24
# File 'lib/zanzibar/actions/get.rb', line 20

def initialize(ui, options, scrt_id)
  super(ui, options)
  @scrt_id = scrt_id
  @zanzibar_options = {}
end

Instance Attribute Details

#scrt_idObject

The id of the secret to download



16
17
18
# File 'lib/zanzibar/actions/get.rb', line 16

def scrt_id
  @scrt_id
end

#zanibar_optionsObject

The options to use when initializing our Zanzibar client



12
13
14
# File 'lib/zanzibar/actions/get.rb', line 12

def zanibar_options
  @zanibar_options
end

Instance Method Details

#construct_optionsObject

Coalesce our options and some defaults to ensure we are ready to run



50
51
52
53
54
55
56
57
58
# File 'lib/zanzibar/actions/get.rb', line 50

def construct_options
  @zanzibar_options[:wsdl] = construct_wsdl
  @zanzibar_options[:globals] = { ssl_verify_mode: :none } if options['ignoressl']
  @zanzibar_options[:domain] = options['domain']
  @zanzibar_options[:username] = options['username'] unless options['username'].nil?
  @zanzibar_options[:domain] = options['domain'] ? options['domain'] : 'local'
  @zanzibar_options[:fieldlabel] = options['fieldlabel'] || 'Password'
  @zanzibar_options[:filelabel] = options['filelabel'] if options['filelabel']
end

#construct_wsdlObject

Construct a WSDL URL from the server hostname if necessary



62
63
64
65
66
67
68
# File 'lib/zanzibar/actions/get.rb', line 62

def construct_wsdl
  if options['wsdl'].nil? && options['server']
    DEFAULT_WSDL % options['server']
  else
    options['wsdl']
  end
end

#ensure_optionsObject

Make sure a proper WSDL was constructed

Raises:



72
73
74
75
# File 'lib/zanzibar/actions/get.rb', line 72

def ensure_options
  return if @zanzibar_options[:wsdl]
  raise Error, NO_WSDL_ERROR
end

#fetch_secret(scrt_id) ⇒ Object

Actually download the secret



37
38
39
40
41
42
43
44
45
46
# File 'lib/zanzibar/actions/get.rb', line 37

def fetch_secret(scrt_id)
  scrt = ::Zanzibar::Zanzibar.new(@zanzibar_options)

  if @zanzibar_options[:filelabel]
    scrt.download_secret_file(scrt_id: scrt_id,
                              type: @zanzibar_options[:filelabel])
  else
    scrt.get_fieldlabel_value(scrt_id, @zanzibar_options[:fieldlabel])
  end
end

#runObject

Ensure we have the options we need and download the secret



28
29
30
31
32
33
# File 'lib/zanzibar/actions/get.rb', line 28

def run
  construct_options
  ensure_options

  fetch_secret(@scrt_id)
end