redacting-logger 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/patterns/default.rb +6 -6
- data/lib/redacting_logger.rb +14 -18
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78c93baa4550a4f20001837396543c6571e9da65db5494b28b30c91cc203ebfd
|
4
|
+
data.tar.gz: c273eec893c8fdcf35436e21798ac7eaae74cb636056ab65af58a644cb6185e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0dd47fe1560866faf4ff202a3649c6d69ee7f2b6d1b3c21874b13299e8e9cf8f3c3769d120800c9292909f071e2ff3079f7de39a002eca2852f96087a122666
|
7
|
+
data.tar.gz: 07c6db97cfc003a5de49caa7d1d4cdc7bf76ebd9f7467ec56b580b710c3a13398c08bafa47a832d8a8a09737d75acdef53e76f445c09d614d5ad4fa89484b293
|
data/lib/patterns/default.rb
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
# These patterns are sourced from different places on the internet, some came from https://github.com/l4yton/RegHex
|
5
5
|
module Patterns
|
6
6
|
DEFAULT = [
|
7
|
+
# RubyGems Token
|
8
|
+
# https://guides.rubygems.org/api-key-scopes/
|
9
|
+
/rubygems_[0-9a-f]{48}/,
|
10
|
+
|
7
11
|
# GitHub Personal Access Token
|
8
12
|
# https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
|
9
13
|
/ghp_[A-Za-z0-9]{36,}|[0-9A-Fa-f]{40,}/,
|
@@ -42,11 +46,7 @@ module Patterns
|
|
42
46
|
|
43
47
|
# Vault Tokens
|
44
48
|
# https://github.com/hashicorp/vault/issues/27151
|
45
|
-
/[sbr]\.[a-zA-Z0-9]{24,}/,
|
46
|
-
/hv[sbr]\.[a-zA-Z0-9]{24,}
|
47
|
-
|
48
|
-
# RubyGems Token
|
49
|
-
# https://guides.rubygems.org/api-key-scopes/
|
50
|
-
/rubygems_[0-9a-f]{48}/
|
49
|
+
/[sbr]\.[a-zA-Z0-9]{24,}/, # <= 1.9.x
|
50
|
+
/hv[sbr]\.[a-zA-Z0-9]{24,}/ # >= 1.10
|
51
51
|
].freeze
|
52
52
|
end
|
data/lib/redacting_logger.rb
CHANGED
@@ -30,6 +30,8 @@ class RedactingLogger < Logger
|
|
30
30
|
@redact_patterns = redact_patterns
|
31
31
|
@redacted_msg = redacted_msg
|
32
32
|
@redact_patterns += Patterns::DEFAULT if use_default_patterns
|
33
|
+
|
34
|
+
@redact_patterns = Regexp.union(@redact_patterns)
|
33
35
|
end
|
34
36
|
|
35
37
|
# Adds a message to the log.
|
@@ -40,30 +42,24 @@ class RedactingLogger < Logger
|
|
40
42
|
def add(severity, message = nil, progname = nil)
|
41
43
|
message, progname = yield if block_given?
|
42
44
|
|
43
|
-
|
44
|
-
case message
|
45
|
-
|
46
|
-
when String, Symbol, Numeric
|
47
|
-
message = message.to_s.gsub(pattern, @redacted_msg)
|
45
|
+
case message
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
m.to_s.gsub(pattern, @redacted_msg)
|
52
|
-
end
|
47
|
+
when String, Symbol, Numeric
|
48
|
+
message = message.to_s.gsub(@redact_patterns, @redacted_msg)
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
50
|
+
when Array
|
51
|
+
message = message.map do |m|
|
52
|
+
m.to_s.gsub(@redact_patterns, @redacted_msg)
|
58
53
|
end
|
59
|
-
end
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
when Hash
|
56
|
+
message = message.transform_values do |v|
|
57
|
+
v.to_s.gsub(@redact_patterns, @redacted_msg)
|
64
58
|
end
|
65
59
|
end
|
66
60
|
|
67
|
-
|
61
|
+
progname = progname.to_s.gsub(@redact_patterns, @redacted_msg) if progname
|
62
|
+
|
63
|
+
super
|
68
64
|
end
|
69
65
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redacting-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: logger
|