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

configuration.rb « client « click_house « lib « click_house-client « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 882b37993dc83a804ca9f9ad1fdc5815fbd2dc3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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