Class: RightScale::ExternalParameterGatherer

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/instance/cook/external_parameter_gatherer.rb

Overview

Provides access to RightLink agent audit methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundle, options) ⇒ ExternalParameterGatherer

Initialize parameter gatherer

Parameters

bundle<RightScale::ExecutableBundle>

the bundle for which to gather inputs

options

Command server listen port

options

Command protocol cookie

Return

true

Always return true



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/instance/cook/external_parameter_gatherer.rb', line 43

def initialize(bundle, options)
  @serializer = Serializer.new
  @audit = AuditStub.instance
  @cookie = options[:cookie]
  @listen_port = options[:listen_port]
  @thread_name = options[:thread_name]
  @executables_inputs = {}

  bundle.executables.each do |exe|
    externals = exe.external_inputs
    next if externals.nil? || externals.empty?
    @executables_inputs[exe] = externals.dup
  end
end

Instance Attribute Details

#failure_messageObject (readonly)

Failure title and message if any



32
33
34
# File 'lib/instance/cook/external_parameter_gatherer.rb', line 32

def failure_message
  @failure_message
end

#failure_titleObject (readonly)

Failure title and message if any



32
33
34
# File 'lib/instance/cook/external_parameter_gatherer.rb', line 32

def failure_title
  @failure_title
end

Instance Method Details

#runObject

TODO docs



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/instance/cook/external_parameter_gatherer.rb', line 59

def run
  if done?
    #we might not have ANY external parameters!
    report_success
    return true
  end

  @audit.create_new_section('Retrieving credentials')

  #Preflight to check validity of cred objects
  ok = true
  @executables_inputs.each_pair do |exe, inputs|
    inputs.each_pair do |name, location|
      next if location.is_a?(RightScale::SecureDocumentLocation)
      msg = "The provided credential (#{location.class.name}) is incompatible with this version of RightLink"
      report_failure('Cannot process external input', msg)
      ok = false
    end
  end

  return false unless ok

  @executables_inputs.each_pair do |exe, inputs|
    inputs.each_pair do |name, location|
      payload = {
        :ticket => location.ticket,
        :namespace => location.namespace,
        :names => [location.name]
      }
      options = {
        :targets => location.targets
      }
      self.send_idempotent_request('/vault/read_documents', payload, options) do |data|
        handle_response(exe, name, location, data)
      end
    end
  end
rescue Exception => e
  report_failure('Credential gathering failed', "The following execption occured while gathering credentials", e)
end