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

encrypted_redis_command.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 608edcdb9500a991aa974e5f22246e2a7b0e4877 (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
# frozen_string_literal: true

# rubocop:disable Rails/Output
module Gitlab
  class EncryptedRedisCommand < EncryptedCommandBase
    DISPLAY_NAME = "Redis"
    EDIT_COMMAND_NAME = "gitlab:redis:secret:edit"

    class << self
      def all_redis_instance_class_names
        Gitlab::Redis::ALL_CLASSES.map do |c|
          normalized_instance_name(c)
        end
      end

      def normalized_instance_name(instance)
        if instance.is_a?(Class)
          # Gitlab::Redis::SharedState => sharedstate
          instance.name.demodulize.to_s.downcase
        else
          # Drop all hyphens, underscores, and spaces from the name
          # eg.: shared_state => sharedstate
          instance.gsub(/[-_ ]/, '').downcase
        end
      end

      def encrypted_secrets(**args)
        if args[:instance_name]
          instance_class = Gitlab::Redis::ALL_CLASSES.find do |instance|
            normalized_instance_name(instance) == normalized_instance_name(args[:instance_name])
          end

          unless instance_class
            error_message = <<~MSG
            Specified instance name #{args[:instance_name]} does not exist.
            The available instances are #{all_redis_instance_class_names.join(', ')}."
            MSG

            raise error_message
          end
        else
          instance_class = Gitlab::Redis::Cache
        end

        instance_class.encrypted_secrets
      end

      def encrypted_file_template
        <<~YAML
          # password: '123'
        YAML
      end
    end
  end
end
# rubocop:enable Rails/Output