Module: Wisco::Config

Defined in:
lib/wisco/config.rb

Class Method Summary collapse

Class Method Details

.ensure_api_config(config, config_path) ⇒ Object

Ensures workato_developer_api hostname and api_token are present in config. Prompts the user for any missing values and saves the updated config.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/wisco/config.rb', line 7

def ensure_api_config(config, config_path)
  api_cfg = config['workato_developer_api'] ||= {}

  if api_cfg['hostname'].nil? || api_cfg['hostname'].strip.empty?
    print 'Workato API hostname not configured. Enter hostname (e.g. app.au.workato.com): '
    api_cfg['hostname'] = $stdin.gets.strip
  end

  if api_cfg['api_token'].nil? || api_cfg['api_token'].strip.empty?
    print 'Workato API token not configured. Enter your API token: '
    api_cfg['api_token'] = $stdin.gets.strip
  end

  save_config(config_path, config)
  config
end

.load_config(path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wisco/config.rb', line 24

def load_config(path)
  return {} unless File.exist?(path)

  begin
    JSON.parse(File.read(path))
  rescue JSON::ParserError => e
    warn "Warning: Existing #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME} contains invalid JSON (#{e.message})."
    warn '         Connector section will be overwritten; other content may be lost.'
    {}
  end
end

.save_config(path, config) ⇒ Object



36
37
38
39
40
41
# File 'lib/wisco/config.rb', line 36

def save_config(path, config)
  File.write(path, JSON.pretty_generate(config) + "\n")
rescue SystemCallError => e
  warn "Error: Could not write #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME}: #{e.message}"
  exit 1
end