Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from tobilarscheid/master
Fixes JENKINS-39383, JENKINS-37201 Automatically mask credentials from build log
- Loading branch information
Showing
3 changed files
with
75 additions
and
31 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/com/datapipe/jenkins/vault/MaskingConsoleLogFilter.java
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,37 @@ | ||
package com.datapipe.jenkins.vault; | ||
|
||
import hudson.console.ConsoleLogFilter; | ||
import hudson.console.LineTransformationOutputStream; | ||
import hudson.model.AbstractBuild; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
public class MaskingConsoleLogFilter extends ConsoleLogFilter implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final String charsetName; | ||
private List<String> valuesToMask; | ||
|
||
|
||
public MaskingConsoleLogFilter(final String charsetName, List<String> valuesToMask) { | ||
this.charsetName = charsetName; | ||
this.valuesToMask = valuesToMask; | ||
} | ||
|
||
@Override | ||
public OutputStream decorateLogger(AbstractBuild abstractBuild, final OutputStream logger) throws IOException, InterruptedException { | ||
return new LineTransformationOutputStream() { | ||
@Override | ||
protected void eol(byte[] b, int len) throws IOException { | ||
String logEntry = new String(b, 0, len, charsetName); | ||
for (String value : valuesToMask) { | ||
logEntry = logEntry.replace(value, "****"); | ||
} | ||
logger.write(logEntry.getBytes(charsetName)); | ||
} | ||
}; | ||
} | ||
} |
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