class OpenSearch::Client
Attributes
transport[RW]
Public Class Methods
new(arguments = {}, &block)
click to toggle source
See OpenSearch::Transport::Client for initializer parameters
# File lib/opensearch.rb, line 40 def initialize(arguments = {}, &block) @verified = false @transport = OpenSearch::Transport::Client.new(arguments, &block) end
Public Instance Methods
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/opensearch.rb, line 45 def method_missing(name, *args, &block) if name == :perform_request verify_open_search unless @verified @transport.perform_request(*args, &block) else super end end
Private Instance Methods
open_search_validation_request()
click to toggle source
# File lib/opensearch.rb, line 91 def open_search_validation_request @transport.perform_request('GET', '/') end
verify_open_search()
click to toggle source
# File lib/opensearch.rb, line 56 def verify_open_search begin response = open_search_validation_request rescue OpenSearch::Transport::Transport::Errors::Unauthorized, OpenSearch::Transport::Transport::Errors::Forbidden @verified = true warn(SECURITY_PRIVILEGES_VALIDATION_WARNING) return end body = if response.headers['content-type'] == 'application/yaml' require 'yaml' YAML.load(response.body) else response.body end version = body.dig('version', 'number') distribution = body.dig('version', 'distribution') verify_version_and_distribution(version, distribution) end
verify_version_and_distribution(version, distribution)
click to toggle source
# File lib/opensearch.rb, line 77 def verify_version_and_distribution(version, distribution) raise OpenSearch::UnsupportedProductError if version.nil? # The client supports all the versions of OpenSearch if distribution == 'opensearch' @verified = true elsif Gem::Version.new(version) >= Gem::Version.new('6.0.0') && Gem::Version.new(version) < Gem::Version.new('8.0.0') @verified = true else raise OpenSearch::UnsupportedProductError end end