Module: App

Defined in:
lib/app/app.rb,
lib/app/menu.rb,
lib/app/config.rb,
lib/app/version.rb,
lib/app/dispatcher.rb,
lib/app/console_app.rb,
lib/app/preflight_check.rb

Defined Under Namespace

Modules: ConsoleApp Classes: Dispatcher, Menu, MenuItem, PreflightCheck

Constant Summary collapse

DEFAULT_PASSWORD =
'changeme'
Config =
::Settings.tap do |config|
  if ent_search_config = ent_search_es_config
    Utility::Logger.error('Overriding elasticsearch config with ent-search config')
    original_es_config = config[:elasticsearch].to_h
    original_es_config.delete(:cloud_id)
    original_es_config.delete(:hosts)
    original_es_config.delete(:api_key)
    config[:elasticsearch] = original_es_config.merge(ent_search_config)
  end
end
VERSION =
App::Config[:version]
RETRYABLE_CONNECTION_ERRORS =
[
    ::Faraday::ConnectionFailed,
    ::Faraday::ClientError,
    ::Errno::ECONNREFUSED,
    ::SocketError,
    ::Errno::ECONNRESET,
    App::PreflightCheck::UnhealthyCluster,
    ::HTTPClient::KeepAliveDisconnected
]

Class Method Summary collapse

Class Method Details

.ent_search_es_configObject

If it’s on cloud (i.e. EnvVar ENT_SEARCH_CONFIG_PATH is set), elasticsearch config in ent-search will be used.



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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/app/config.rb', line 71

def self.ent_search_es_config
  ent_search_config_path = ENV['ENT_SEARCH_CONFIG_PATH']
  unless ent_search_config_path
    Utility::Logger.info('ENT_SEARCH_CONFIG_PATH is not found, use connector service config.')
    return nil
  end

  Utility::Logger.info("Found ENT_SEARCH_CONFIG_PATH, loading ent-search config from #{ent_search_config_path}")
  ent_search_config = begin
    YAML.load_file(ent_search_config_path)
  rescue StandardError => e
    Utility::Logger.error("Failed to load ent-search config #{ent_search_config_path}: #{e.message}")
    return nil
  end

  unless ent_search_config.is_a?(Hash)
    Utility::Logger.error("Invalid ent-search config: #{ent_search_config.inspect}")
    return nil
  end

  host = ent_search_config['elasticsearch.host'] || ent_search_config.dig('elasticsearch', 'host')
  username = ent_search_config['elasticsearch.username'] || ent_search_config.dig('elasticsearch', 'username')
  password = ent_search_config['elasticsearch.password'] || ent_search_config.dig('elasticsearch', 'password')

  missing_fields = []
  missing_fields << 'elasticsearch.host' unless host
  missing_fields << 'elasticsearch.username' unless username
  missing_fields << 'elasticsearch.password' unless password
  if missing_fields.any?
    Utility::Logger.error("Incomplete elasticsearch config, missing #{missing_fields.join(', ')}")
    return nil
  end

  uri = begin
    URI.parse(host)
  rescue URI::InvalidURIError => e
    Utility::Logger.error("Failed to parse elasticsearch host #{host}: #{e.message}")
    return nil
  end

  unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
    Utility::Logger.error("Invalid elasticsearch host #{host}, it must be a http or https URI.")
    return nil
  end

  headers = ent_search_config['elasticsearch.headers'] || ent_search_config.dig('elasticsearch', 'headers')

  {
    :hosts => [
      {
        scheme: uri.scheme,
        user: username,
        password: password,
        host: uri.host,
        port: uri.port
      }
    ],
    :headers => headers
  }
end