Skip to content

Commit 0e6edfb

Browse files
committed
Added maskPrivateToken() method.
1 parent f6833a4 commit 0e6edfb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/org/gitlab4j/api/utils/HttpRequestUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,19 @@ public static String getReaderContentAsString(Reader reader) throws IOException
144144

145145
return (out.toString());
146146
}
147+
148+
/**
149+
* Masks the PRIVATE-TOKEN header value with "********".
150+
*
151+
* @param s a String containing HTTP request info, usually logging info
152+
* @return a String with the PRIVATE-TOKEN header value masked with asterisks
153+
*/
154+
public static String maskPrivateToken(String s) {
155+
156+
if (s == null || s.isEmpty()) {
157+
return (s);
158+
}
159+
160+
return (s.replaceAll("PRIVATE\\-TOKEN\\: [\\S]*", "PRIVATE-TOKEN: ********"));
161+
}
147162
}

0 commit comments

Comments
 (0)