From 010c9911edd3ef1a15da5eecc971e3ca3f928d3a Mon Sep 17 00:00:00 2001 From: Dru Sellers Date: Thu, 22 Nov 2018 10:59:08 -0600 Subject: [PATCH] Provide configuration help --- lib/searchyll.rb | 7 +++++-- lib/searchyll/configuration.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/searchyll.rb b/lib/searchyll.rb index d9f5bef..35e9f0a 100644 --- a/lib/searchyll.rb +++ b/lib/searchyll.rb @@ -11,12 +11,15 @@ Jekyll::Hooks.register(:site, :pre_render) do |site| config = Searchyll::Configuration.new(site) - if config.elasticsearch_url && !config.elasticsearch_url.empty? + if config.valid? puts "setting up indexer hook with url #{config.elasticsearch_url.inspect}" indexers[site] = Searchyll::Indexer.new(config) indexers[site].start else - puts 'No ElasticSearch URL provided, skipping indexing...' + puts 'Invalid Elasticsearch configuration provided, skipping indexing...' + config.reasons.each do |r| + puts " #{r}" + end end end diff --git a/lib/searchyll/configuration.rb b/lib/searchyll/configuration.rb index 45d1a62..9cb7738 100644 --- a/lib/searchyll/configuration.rb +++ b/lib/searchyll/configuration.rb @@ -1,6 +1,7 @@ module Searchyll class Configuration attr_accessor :site + def initialize(site) self.site = site end @@ -11,6 +12,38 @@ def elasticsearch_url ((site.config||{})['elasticsearch']||{})['url'] end + def valid? + elasticsearch_url && !elasticsearch_url.empty? && elasticsearch_url.start_with?('http') + end + + def reasons + reasons = [] + if elasticsearch_url && elasticsearch_url.empty? + reasons << 'No Elasticsearch url configured' + reasons << ' Looked in ENV[BONSAI_URL]' + reasons << ' Looked in ENV[ELASTICSEARCH_URL]' + reasons << ' Looked in _config.elasticsearch.url' + elsif ! elasticsearch_url.start_with? 'http' + reasons << "Elasticsearch url must start with 'http' or 'https'" + reasons << " Current Value: #{elasticsearch_url}" + reasons << " Current Source: #{elasticsearch_url_source}" + end + + reasons + end + + def elasticsearch_url_source + if ENV['BONSAI_URL'] + 'ENV[BONSAI_URL]' + elsif ENV['ELASTICSEARCH_URL'] + 'ENV[ELASTICSEARCH_URL]' + elsif ((site.config||{})['elasticsearch']||{})['url'] + 'CONFIG' + else + 'NOT FOUND' + end + end + # Getter for the number of primary shards def elasticsearch_number_of_shards site.config['elasticsearch']['number_of_shards'] || 1