Class: Gitlab::EncryptedRedisCommand

Inherits:
EncryptedCommandBase show all
Defined in:
lib/gitlab/encrypted_redis_command.rb

Constant Summary collapse

DISPLAY_NAME =
"Redis"
EDIT_COMMAND_NAME =
"gitlab:redis:secret:edit"

Class Method Summary collapse

Methods inherited from EncryptedCommandBase

edit, editor_args, show, validate_config, validate_contents, write

Class Method Details

.all_redis_instance_class_namesObject



9
10
11
12
13
# File 'lib/gitlab/encrypted_redis_command.rb', line 9

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

.encrypted_file_templateObject



47
48
49
50
51
# File 'lib/gitlab/encrypted_redis_command.rb', line 47

def encrypted_file_template
  "    # password: '123'\n  YAML\nend\n"

.encrypted_secrets(**args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/encrypted_redis_command.rb', line 26

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 = "      Specified instance name \#{args[:instance_name]} does not exist.\n      The available instances are \#{all_redis_instance_class_names.join(', ')}.\"\n      MSG\n\n      raise error_message\n    end\n  else\n    instance_class = Gitlab::Redis::Cache\n  end\n\n  instance_class.encrypted_secrets\nend\n"

.normalized_instance_name(instance) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/encrypted_redis_command.rb', line 15

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