Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'gems/click_house-client/lib/click_house/client/configuration.rb')
-rw-r--r--gems/click_house-client/lib/click_house/client/configuration.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/gems/click_house-client/lib/click_house/client/configuration.rb b/gems/click_house-client/lib/click_house/client/configuration.rb
new file mode 100644
index 00000000000..882b37993dc
--- /dev/null
+++ b/gems/click_house-client/lib/click_house/client/configuration.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+module ClickHouse
+ module Client
+ class Configuration
+ # Configuration options:
+ #
+ # *register_database* (method): registers a database, the following arguments are required:
+ # - database: database name
+ # - url: URL and port to the HTTP interface
+ # - username
+ # - password
+ # - variables (optional): configuration for the client
+ #
+ # *http_post_proc*: A callable object for invoking the HTTP request.
+ # The object must handle the following parameters: url, headers, body
+ # and return a Gitlab::ClickHouse::Client::Response object.
+ #
+ # *json_parser*: object for parsing JSON strings, it should respond to the "parse" method
+ #
+ # Example:
+ #
+ # Gitlab::ClickHouse::Client.configure do |c|
+ # c.register_database(:main,
+ # database: 'gitlab_clickhouse_test',
+ # url: 'http://localhost:8123',
+ # username: 'default',
+ # password: 'clickhouse',
+ # variables: {
+ # join_use_nulls: 1 # treat JOINs as per SQL standard
+ # }
+ # )
+ #
+ # c.http_post_proc = lambda do |url, headers, body|
+ # options = {
+ # headers: headers,
+ # body: body,
+ # allow_local_requests: false
+ # }
+ #
+ # response = Gitlab::HTTP.post(url, options)
+ # Gitlab::ClickHouse::Client::Response.new(response.body, response.code)
+ # end
+ #
+ # c.json_parser = JSON
+ # end
+ attr_accessor :http_post_proc, :json_parser
+ attr_reader :databases
+
+ def initialize
+ @databases = {}
+ @http_post_proc = nil
+ @json_parser = JSON
+ end
+
+ def register_database(name, **args)
+ raise ConfigurationError, "The database '#{name}' is already registered" if @databases.key?(name)
+
+ @databases[name] = Database.new(**args)
+ end
+
+ def validate!
+ raise ConfigurationError, "The 'http_post_proc' option is not configured" unless @http_post_proc
+ raise ConfigurationError, "The 'json_parser' option is not configured" unless @json_parser
+ end
+ end
+ end
+end