• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fluent / fluent-plugin-opensearch / 14873730023

07 May 2025 02:22AM UTC coverage: 91.339% (-0.006%) from 91.345%
14873730023

Pull #156

github

web-flow
Merge 1576e49ae into 4b6ff1a28
Pull Request #156: Fix memory usage

1160 of 1270 relevant lines covered (91.34%)

155.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/lib/fluent/plugin/opensearch_tls.rb
1
# SPDX-License-Identifier: Apache-2.0
2
#
3
# The fluent-plugin-opensearch Contributors require contributions made to
4
# this file be licensed under the Apache-2.0 license or a
5
# compatible open source license.
6
#
7
# Modifications Copyright fluent-plugin-opensearch Contributors. See
8
# GitHub history for details.
9
#
10
# Licensed to Uken Inc. under one or more contributor
11
# license agreements. See the NOTICE file distributed with
12
# this work for additional information regarding copyright
13
# ownership. Uken Inc. licenses this file to you under
14
# the Apache License, Version 2.0 (the "License"); you may
15
# not use this file except in compliance with the License.
16
# You may obtain a copy of the License at
17
#
18
#   http://www.apache.org/licenses/LICENSE-2.0
19
#
20
# Unless required by applicable law or agreed to in writing,
21
# software distributed under the License is distributed on an
22
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
# KIND, either express or implied.  See the License for the
24
# specific language governing permissions and limitations
25
# under the License.
26

27
require 'openssl'
1✔
28
require 'fluent/configurable'
1✔
29
require 'fluent/config/error'
1✔
30

31
module Fluent::Plugin
1✔
32
  module OpenSearchTLS
1✔
33
    SUPPORTED_TLS_VERSIONS = if defined?(OpenSSL::SSL::TLS1_3_VERSION)
1✔
34
                               [:TLSv1, :TLSv1_1, :TLSv1_2, :TLSv1_3].freeze
1✔
35
                             else
36
                               [:SSLv23, :TLSv1, :TLSv1_1, :TLSv1_2].freeze
×
37
                             end
38

39
    DEFAULT_VERSION = :TLSv1_2
1✔
40
    METHODS_MAP = begin
41
                    # When openssl supports OpenSSL::SSL::TLSXXX constants representations, we use them.
42
                    map = {
43
                      TLSv1: OpenSSL::SSL::TLS1_VERSION,
1✔
44
                      TLSv1_1: OpenSSL::SSL::TLS1_1_VERSION,
45
                      TLSv1_2: OpenSSL::SSL::TLS1_2_VERSION
46
                    }
47
                    map[:TLSv1_3] = OpenSSL::SSL::TLS1_3_VERSION if defined?(OpenSSL::SSL::TLS1_3_VERSION)
1✔
48
                    USE_TLS_MINMAX_VERSION = true
1✔
49
                    map.freeze
1✔
50
                  rescue NameError
51
                    map = {
×
52
                      SSLv23: :SSLv23,
53
                      TLSv1: :TLSv1,
54
                      TLSv1_1: :TLSv1_1,
55
                      TLSv1_2: :TLSv1_2,
56
                    }
57
                    USE_TLS_MINMAX_VERSION = false
×
58
                  end
59
    private_constant :METHODS_MAP
1✔
60

61
    module OpenSearchTLSParams
1✔
62
      include Fluent::Configurable
1✔
63

64
      config_param :ssl_version, :enum, list: Fluent::Plugin::OpenSearchTLS::SUPPORTED_TLS_VERSIONS, default: Fluent::Plugin::OpenSearchTLS::DEFAULT_VERSION
1✔
65
      config_param :ssl_min_version, :enum, list: Fluent::Plugin::OpenSearchTLS::SUPPORTED_TLS_VERSIONS, default: nil
1✔
66
      config_param :ssl_max_version, :enum, list: Fluent::Plugin::OpenSearchTLS::SUPPORTED_TLS_VERSIONS, default: nil
1✔
67
    end
68

69
    def self.included(mod)
1✔
70
      mod.include OpenSearchTLSParams
2✔
71
    end
72

73
    def set_tls_minmax_version_config(ssl_version, ssl_max_version, ssl_min_version)
1✔
74
      if USE_TLS_MINMAX_VERSION
428✔
75
        case
76
        when ssl_min_version.nil? && ssl_max_version.nil?
428✔
77
          ssl_min_version = METHODS_MAP[:TLSv1_2]
424✔
78
          ssl_max_version = METHODS_MAP[:TLSv1_3]
424✔
79
        when ssl_min_version && ssl_max_version.nil?
80
          raise Fluent::ConfigError, "When you set 'ssl_min_version', must set 'ssl_max_version' together."
1✔
81
        when ssl_min_version.nil? && ssl_max_version
82
          raise Fluent::ConfigError, "When you set 'ssl_max_version', must set 'ssl_min_version' together."
1✔
83
        else
84
          ssl_min_version = METHODS_MAP[ssl_min_version]
2✔
85
          ssl_max_version = METHODS_MAP[ssl_max_version]
2✔
86
        end
87

88
        {max_version: ssl_max_version, min_version: ssl_min_version}
426✔
89
      else
90
        log.warn "'ssl_min_version' does not have any effect in this environment. Use 'ssl_version' instead." unless ssl_min_version.nil?
×
91
        log.warn "'ssl_max_version' does not have any effect in this environment. Use 'ssl_version' instead." unless ssl_max_version.nil?
×
92
        {version: ssl_version}
×
93
      end
94
    end
95
  end
96
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc