-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter SharedKey and client_secret, add custom << method. Added some spaces back into replacement strings, and added some specs. Reworked to subclass Formatter.
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Vmdb::Loggers | ||
class AzureLogger < VMDBLogger | ||
def initialize(*loggers) | ||
super | ||
|
||
# pulled from Ruby's `Logger::Formatter`, which is what it defaults to when it is `nil` | ||
@datetime_format = "%Y-%m-%dT%H:%M:%S.%6N " | ||
@formatter = Vmdb::Loggers::AzureLogger::Formatter.new | ||
end | ||
|
||
def <<(msg) | ||
msg = msg.strip | ||
log(level, msg) | ||
msg.size | ||
end | ||
|
||
class Formatter < VMDBLogger::Formatter | ||
def call(severity, datetime, progname, msg) | ||
msg = msg.sub(/Bearer(.*?)\"/, 'Bearer [FILTERED] "') | ||
msg = msg.sub(/SharedKey(.*?)\"/, 'SharedKey [FILTERED] "') | ||
msg = msg.sub(/client_secret=(.*?)&/, "client_secret=[FILTERED]&") | ||
super(severity, datetime, progname, msg) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe Vmdb::Loggers::AzureLogger do | ||
before do | ||
@log_stream = StringIO.new | ||
@log = described_class.new(@log_stream) | ||
end | ||
|
||
context "azure" do | ||
it "filters out bearer tokens" do | ||
@log.log(@log.level, 'Bearer abcd1234 "stuff"') | ||
@log_stream.rewind | ||
expect(@log_stream.read).to match(Regexp.quote('Bearer [FILTERED] "stuff"')) | ||
end | ||
|
||
it "filters out sharedkey tokens" do | ||
@log.log(@log.level, 'SharedKey xxx123 "stuff"') | ||
@log_stream.rewind | ||
expect(@log_stream.read).to match(Regexp.quote('SharedKey [FILTERED] "stuff"')) | ||
end | ||
|
||
it "filters out client secret tokens" do | ||
@log.log(@log.level, 'client_secret=abc123&management=yadayada') | ||
@log_stream.rewind | ||
expect(@log_stream.read).to match(Regexp.quote('client_secret=[FILTERED]&management=yadayada')) | ||
end | ||
end | ||
end |