Module: AgentCliRuntime::Probe

Defined in:
lib/agent_cli_runtime/probe.rb

Class Method Summary collapse

Class Method Details

.all(home: nil, env: ENV) ⇒ Object



63
64
65
66
67
# File 'lib/agent_cli_runtime/probe.rb', line 63

def all(home: nil, env: ENV)
  Profiles.names.map do |provider|
    call(provider, home: home, env: env)
  end.freeze
end

.call(profile, home: nil, env: ENV) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/agent_cli_runtime/probe.rb', line 5

def call(profile, home: nil, env: ENV)
  resolved = Profiles.resolve(profile)
  executable = resolved.bin(env:)
  installed = resolved.binary_installed?(env:)
  version = nil
  diagnostic = nil

  if installed
    begin
      version = resolved.check_version!(env:)
    rescue Error => e
      diagnostic = Redactor.diagnostic(e)
    end
  else
    diagnostic = Redactor.diagnostic(
      "#{resolved.name} binary not runnable: #{executable}"
    )
  end

  auth =
    if installed
      resolved.auth_configuration(home: home, env: env)
    else
      AuthConfiguration.new(status: :not_checked)
    end
  diagnostic ||= auth.diagnostic
  ready = installed &&
          !version.nil? &&
          auth.status != :missing

  ProbeResult.new(
    provider: resolved.name,
    ready: ready,
    installed: installed,
    executable: executable,
    version: version,
    minimum_version: resolved.min_version,
    auth_configuration: auth,
    capability_evidence: capability_evidence(
      resolved, installed: installed, version: version, auth: auth
    ),
    diagnostic: diagnostic
  )
rescue StandardError => e
  resolved ||= Profiles.resolve(profile)
  ProbeResult.new(
    provider: resolved.name,
    ready: false,
    installed: false,
    executable: resolved.bin(env:),
    version: nil,
    minimum_version: resolved.min_version,
    auth_configuration: AuthConfiguration.new(status: :not_checked),
    capability_evidence: [],
    diagnostic: Redactor.diagnostic(e)
  )
end