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

Returns a new instance of Get.



13
14
15
16
17
# File 'lib/zanzibar/actions/get.rb', line 13

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

Instance Attribute Details

#scrt_idObject

Returns the value of attribute scrt_id.



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

def scrt_id
  @scrt_id
end

#zanibar_optionsObject

Returns the value of attribute zanibar_options.



10
11
12
# File 'lib/zanzibar/actions/get.rb', line 10

def zanibar_options
  @zanibar_options
end

Instance Method Details

#construct_optionsObject



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

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'
end

#construct_wsdlObject



45
46
47
48
49
50
51
# File 'lib/zanzibar/actions/get.rb', line 45

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

#ensure_optionsObject



53
54
55
56
# File 'lib/zanzibar/actions/get.rb', line 53

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

#fetch_secret(scrt_id, label = nil) ⇒ Object



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

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

  if label
    scrt.download_secret_file(scrt_id: scrt_id,
                              type: label)
  else
    scrt.get_password(scrt_id)
  end
end

#runObject



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

def run
  construct_options
  ensure_options

  fetch_secret(@scrt_id, options['filelabel'])
end