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
|
# File 'lib/gitlab/secret_detection/utils/masker.rb', line 12
def mask_secret(
raw_secret_value,
mask_char: DEFAULT_MASK_CHAR,
visible_chars_count: DEFAULT_VISIBLE_CHAR_COUNT,
mask_chars_count: DEFAULT_MASK_CHAR_COUNT
)
return '' if raw_secret_value.nil? || raw_secret_value.empty?
return raw_secret_value if raw_secret_value.length <= visible_chars_count
chars = raw_secret_value.chars
position = 0
while position < chars.length
position += visible_chars_count
mask_chars_count.times do
break if position >= chars.length
chars[position] = mask_char
position += 1
end
end
chars.join
end
|