Class: Gitlab::Redis::ConfigGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/redis/config_generator.rb

Constant Summary collapse

CommandExecutionError =
Class.new(StandardError)
InvalidPathError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component = 'Redis') ⇒ ConfigGenerator

Returns a new instance of ConfigGenerator.



43
44
45
# File 'lib/gitlab/redis/config_generator.rb', line 43

def initialize(component = 'Redis')
  @component = component
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



9
10
11
# File 'lib/gitlab/redis/config_generator.rb', line 9

def component
  @component
end

Class Method Details

.parse_client_tls_options(config) ⇒ Object



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
# File 'lib/gitlab/redis/config_generator.rb', line 11

def self.parse_client_tls_options(config)
  return config unless config&.key?(:ssl_params)

  # Only cert_file and key_file are handled in this method. ca_file and
  # ca_path are Strings, so they can be passed as-is. cert_store is not
  # currently supported. Note that this is no longer needed now that
  # redis-client does this conversion for us with the cert and key parameters,
  # but preserve this for backwards compatibility.
  cert_file = config[:ssl_params].delete(:cert_file)
  key_file = config[:ssl_params].delete(:key_file)

  if cert_file
    unless ::File.exist?(cert_file)
      raise InvalidPathError,
        "Certificate file #{cert_file} specified in Redis configuration does not exist."
    end

    config[:ssl_params][:cert] = OpenSSL::X509::Certificate.new(File.read(cert_file))
  end

  if key_file
    unless ::File.exist?(key_file)
      raise InvalidPathError,
        "Key file #{key_file} specified in Redis configuration does not exist."
    end

    config[:ssl_params][:key] = OpenSSL::PKey.read(File.read(key_file))
  end

  config
end

Instance Method Details

#generate(original_config) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gitlab/redis/config_generator.rb', line 47

def generate(original_config)
  command = original_config.delete(:config_command)
  config = if command.present?
             config_from_command = generate_yaml_from_command(command)
             config_from_command.present? ? original_config.deep_merge(config_from_command) : original_config
           else
             original_config
           end

  self.class.parse_client_tls_options(config)
end