Skip to content

Commit 1639102

Browse files
authored
Support LogStream filters (#494)
* Support LogStream filters * Updated test schemas
1 parent 611d0b4 commit 1639102

5 files changed

Lines changed: 126 additions & 4 deletions

File tree

src/main/java/com/auth0/json/mgmt/logstreams/LogStream.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.*;
44

5+
import java.util.List;
56
import java.util.Map;
67

78
/**
@@ -22,6 +23,9 @@ public class LogStream {
2223
@JsonProperty("sink")
2324
private Map<String, Object> sink;
2425

26+
@JsonProperty("filters")
27+
private List<LogStreamFilter> filters;
28+
2529
/**
2630
* Creates a new LogStream instance and sets the type, which cannot be changed once set.
2731
*
@@ -119,4 +123,22 @@ public Map<String, Object> getSink() {
119123
public void setSink(Map<String, Object> sink) {
120124
this.sink = sink;
121125
}
126+
127+
/**
128+
* @return the log stream filters
129+
*/
130+
@JsonProperty("filters")
131+
public List<LogStreamFilter> getFilters() {
132+
return filters;
133+
}
134+
135+
/**
136+
* Set the log stream filters.
137+
*
138+
* @param filters the filters to set for the log stream.
139+
*/
140+
@JsonProperty("filters")
141+
public void setFilters(List<LogStreamFilter> filters) {
142+
this.filters = filters;
143+
}
122144
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.auth0.json.mgmt.logstreams;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
/**
9+
* Represents an Auth0 Log Stream Filter object. Related to the {@linkplain com.auth0.client.mgmt.LogStreamsEntity}
10+
*/
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
@JsonInclude(JsonInclude.Include.NON_NULL)
13+
public class LogStreamFilter {
14+
15+
@JsonProperty("type")
16+
private String type;
17+
@JsonProperty("name")
18+
private String name;
19+
20+
/**
21+
* Create a new instance.
22+
*
23+
* @param type the log stream filter type.
24+
* @param name the log stream filter name.
25+
*/
26+
@JsonCreator
27+
public LogStreamFilter(@JsonProperty("type") String type, @JsonProperty("name") String name) {
28+
this.type = type;
29+
this.name = name;
30+
}
31+
32+
/**
33+
* @return the log stream filter type.
34+
*/
35+
@JsonProperty("type")
36+
public String getType() {
37+
return type;
38+
}
39+
40+
/**
41+
* Set the log stream filter type.
42+
* @param type the log stream filter type.
43+
*/
44+
@JsonProperty("type")
45+
public void setType(String type) {
46+
this.type = type;
47+
}
48+
49+
/**
50+
* @return the log stream filter name.
51+
*/
52+
@JsonProperty("name")
53+
public String getName() {
54+
return name;
55+
}
56+
57+
@JsonProperty("name")
58+
public void setName(String name) {
59+
this.name = name;
60+
}
61+
}

src/test/java/com/auth0/client/mgmt/LogStreamsEntityTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import com.auth0.client.MockServer;
44
import com.auth0.json.mgmt.logstreams.LogStream;
5+
import com.auth0.json.mgmt.logstreams.LogStreamFilter;
56
import com.auth0.net.Request;
67
import com.auth0.net.client.HttpMethod;
78
import okhttp3.mockwebserver.RecordedRequest;
89
import org.junit.Test;
910

11+
import java.util.Collections;
1012
import java.util.HashMap;
1113
import java.util.List;
1214
import java.util.Map;
@@ -39,6 +41,7 @@ public void shouldListLogStreams() throws Exception {
3941
assertThat(response, everyItem(hasProperty("type", is(notNullValue()))));
4042
assertThat(response, everyItem(hasProperty("status", is(notNullValue()))));
4143
assertThat(response, everyItem(hasProperty("sink", is(notNullValue()))));
44+
assertThat(response, everyItem(hasProperty("filters", is(notNullValue()))));
4245
}
4346

4447
@Test
@@ -72,11 +75,14 @@ public void shouldGetLogStream() throws Exception {
7275
assertThat(response, hasProperty("type", is(notNullValue())));
7376
assertThat(response, hasProperty("status", is(notNullValue())));
7477
assertThat(response, hasProperty("sink", is(notNullValue())));
78+
assertThat(response, hasProperty("filters", is(notNullValue())));
7579
}
7680

7781
@Test
7882
public void shouldCreateLogStream() throws Exception {
7983
LogStream logStream = getLogStream("log stream", "http");
84+
LogStreamFilter filter = new LogStreamFilter("category", "auth.ancillary.success");
85+
logStream.setFilters(Collections.singletonList(filter));
8086

8187
Request<LogStream> request = api.logStreams().create(logStream);
8288
assertThat(request, is(notNullValue()));
@@ -90,17 +96,20 @@ public void shouldCreateLogStream() throws Exception {
9096
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
9197

9298
Map<String, Object> body = bodyFromRequest(recordedRequest);
93-
assertThat(body.size(), is(3));
99+
assertThat(body.size(), is(4));
94100
assertThat(body, hasEntry("name", "log stream"));
95101
assertThat(body, hasEntry("type", "http"));
96102
assertThat(body, hasEntry("sink", logStream.getSink()));
103+
assertThat(body, hasKey("filters"));
104+
assertThat(body.get("filters"), is(notNullValue()));
97105

98106
assertThat(response, is(notNullValue()));
99107
assertThat(response, hasProperty("id", is(notNullValue())));
100108
assertThat(response, hasProperty("name", is(notNullValue())));
101109
assertThat(response, hasProperty("type", is(notNullValue())));
102110
assertThat(response, hasProperty("status", is(notNullValue())));
103111
assertThat(response, hasProperty("sink", is(notNullValue())));
112+
assertThat(response, hasProperty("filters", is(notNullValue())));
104113

105114
}
106115

src/test/resources/mgmt/log_stream.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@
99
"httpContentType": "application/json",
1010
"httpAuthorization": "abc123",
1111
"httpEndpoint": "https//me.org"
12-
}
12+
},
13+
"filters": [
14+
{
15+
"type": "category",
16+
"name": "auth.ancillary.success"
17+
},
18+
{
19+
"type": "category",
20+
"name": "auth.ancillary.fail"
21+
}
22+
]
1323
}

src/test/resources/mgmt/log_streams_list.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@
99
"httpContentType": "application/json",
1010
"httpAuthorization": "abc123",
1111
"httpEndpoint": "https//me.org"
12-
}
12+
},
13+
"filters": [
14+
{
15+
"type": "category",
16+
"name": "auth.ancillary.success"
17+
},
18+
{
19+
"type": "category",
20+
"name": "auth.ancillary.fail"
21+
}
22+
]
1323
},
1424
{
1525
"id": "456",
@@ -21,6 +31,16 @@
2131
"datadogApiKey": "abc123",
2232
"httpAuthorization": "abc123",
2333
"httpEndpoint": "https//me.org"
24-
}
34+
},
35+
"filters": [
36+
{
37+
"type": "category",
38+
"name": "auth.ancillary.success"
39+
},
40+
{
41+
"type": "category",
42+
"name": "auth.ancillary.fail"
43+
}
44+
]
2545
}
2646
]

0 commit comments

Comments
 (0)