Skip to content

Commit

Permalink
add examples and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-amiaud committed Jul 6, 2023
1 parent 547aeb4 commit eb16909
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plume-admin-api-log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ new OkHttpLoggerInterceptor(
)
```

Example to omit logging requests that matches URL regex `^https://test.coreoz.com/([^/]*)/world`:
Example to omit logging requests that matches URL regex `.+?/([^/]*)/world$`:
```java
new OkHttpLoggerInterceptor(
"Github",
logApiService,
RequestPredicate.alwaysTrue().filterUrlRegex(List.of("^https://test.coreoz.com/([^/]*)/world"))
RequestPredicate.alwaysTrue().filterUrlRegex(List.of(".+?/([^/]*)/world$"))
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ static LogEntryTransformer limitBodySizeTransformer(int bodyCharLengthLimit) {
/**
* Transforms the body of either the request or the response
* to replace values of given object keys through a regex matcher
*
* <p>hideJsonFields(List.of("password"), "***") will replace the JSON body {"login": "john", "password": "azerty"} by {"login": "john", "password": "***"}
*
* @param jsonFieldKeysToHide : a list of keys whose value needs to be hidden
* @param replacement : the replacement for the hidden values
* @return the corresponding {@link LogEntryTransformer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ default RequestPredicate filterEndpointStartsWith(String endpointToFilter) {

/**
* Filters a request by its URL through a URL regex list
*
* <p>filterUrlRegex(List.of(".+?/([^/]*)/world$")) will filter URL like `[base-url]/hello/world` but will allow URL `[base-url]/hello/world/allowed`
*
* @param urlsRegex : the URL regex list to be filtered
*/
default RequestPredicate filterUrlRegex(List<String> urlsRegex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void transformer_must_nullify_body() {
public void transformer_must_nullify_body_if_filtered() {
LogEntryTransformer transformer = LogEntryTransformer.emptyBody()
.applyOnlyToRequests(
RequestPredicate.alwaysTrue().filterUrlRegex(List.of("^https://test.coco.com/([^/]*)/world"))
RequestPredicate.alwaysTrue().filterUrlRegex(List.of(".+?/([^/]*)/world$"))
);


Expand All @@ -298,7 +298,7 @@ public void transformer_must_nullify_body_if_filtered() {
public void transformer_must_nullify_body_if_not_filtered() {
LogEntryTransformer transformer = LogEntryTransformer.emptyBody()
.applyOnlyToRequests(
RequestPredicate.alwaysTrue().filterUrlRegex(List.of("https://test.coco.com/hello/world-fail"))
RequestPredicate.alwaysTrue().filterUrlRegex(List.of(".+?/([^/]*)/world-fail$"))
);

Request request = generatePostRequest("/hello/world", 30);
Expand All @@ -312,7 +312,7 @@ public void transformer_must_nullify_body_if_not_filtered() {
}

private static Request generatePostRequest(String endpoint, int length) {
Builder request = new Request.Builder().url("https://test.coco.com" + endpoint);
Builder request = new Request.Builder().url("https://test.coreoz.com" + endpoint);
if (length == 0) {
return request.get().build();
}
Expand Down

0 comments on commit eb16909

Please sign in to comment.