Module: Wisco::Commands::Status

Defined in:
lib/wisco/commands/status.rb

Class Method Summary collapse

Class Method Details

.check_credentials(connector_path) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/wisco/commands/status.rb', line 92

def check_credentials(connector_path)
  plaintext = File.exist?(File.join(connector_path, 'settings.yaml'))
  encrypted = File.exist?(File.join(connector_path, 'settings.yaml.enc'))
  present   = plaintext || encrypted

  {
    'present'   => present,
    'encrypted' => present && !plaintext
  }
end

.load_connector_info(full_path, target_dir) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/wisco/commands/status.rb', line 79

def load_connector_info(full_path, target_dir)
  unless File.exist?(full_path)
    return { valid: false, title: nil, error: "Connector file not found: #{full_path}" }
  end

  begin
    connector = Wisco::Connector.load_connector_from_config(target_dir)
    { valid: true, title: connector[:title]&.to_s, error: nil }
  rescue StandardError => e
    { valid: false, title: nil, error: e.message.strip }
  end
end

.resolve_hostname(profile_name, config) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/wisco/commands/status.rb', line 70

def resolve_hostname(profile_name, config)
  if profile_name
    profile = Wisco::Profiles.get(profile_name)
    profile&.dig('hostname')
  else
    config.dig('workato_developer_api', 'hostname')
  end
end

.run(target_dir) ⇒ Object



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
# File 'lib/wisco/commands/status.rb', line 12

def run(target_dir)
  target_dir  = File.expand_path(target_dir)
  config_path = Wisco.config_path(target_dir)

  unless File.exist?(config_path)
    puts JSON.pretty_generate(uninitialised_payload)
    return
  end

  config         = Wisco::Config.load_config(config_path)
  connector_path = config.dig('connector', 'path')
  connector_file = config.dig('connector', 'file')

  if connector_path.nil? || connector_file.nil?
    puts JSON.pretty_generate(uninitialised_payload)
    return
  end

  profile_name = config.dig('workato_developer_api', 'profile').to_s
  profile_name = nil if profile_name.empty?
  hostname     = resolve_hostname(profile_name, config)

  full_connector_path = File.join(connector_path, connector_file)
  connector_info      = load_connector_info(full_connector_path, target_dir)
  credentials         = check_credentials(connector_path)

  payload = {
    'wisco_version' => Wisco::VERSION,
    'initialized'   => true,
    'config_path'   => config_path,
    'profile'       => { 'name' => profile_name },
    'hostname'      => hostname,
    'connection'    => config['connection'],
    'connector'     => {
      'path'  => full_connector_path,
      'valid' => connector_info[:valid],
      'title' => connector_info[:title],
      'error' => connector_info[:error]
    },
    'credentials'   => credentials
  }

  puts JSON.pretty_generate(payload)
end

.uninitialised_payloadObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/wisco/commands/status.rb', line 57

def uninitialised_payload
  {
    'wisco_version' => Wisco::VERSION,
    'initialized'   => false,
    'config_path'   => nil,
    'profile'       => nil,
    'hostname'      => nil,
    'connection'    => nil,
    'connector'     => nil,
    'credentials'   => nil
  }
end