Skip to content
This repository was archived by the owner on Dec 23, 2017. It is now read-only.

Commit ea761a4

Browse files
committed
Return a 404 if there is no opt-out configuration
1 parent 48af772 commit ea761a4

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/main/java/org/graylog/plugins/usagestatistics/UsageStatsOptOutResource.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javax.validation.constraints.NotNull;
3030
import javax.ws.rs.Consumes;
3131
import javax.ws.rs.GET;
32+
import javax.ws.rs.NotFoundException;
3233
import javax.ws.rs.POST;
3334
import javax.ws.rs.Path;
3435
import javax.ws.rs.Produces;
@@ -53,7 +54,13 @@ public UsageStatsOptOutResource(UsageStatsOptOutService usageStatsOptOutService)
5354
@ApiResponse(code = 500, message = "Internal Server Error")
5455
})
5556
public UsageStatsOptOutState getOptOutState() {
56-
return usageStatsOptOutService.getOptOutState();
57+
final UsageStatsOptOutState optOutState = usageStatsOptOutService.getOptOutState();
58+
59+
if (optOutState == null) {
60+
throw new NotFoundException();
61+
}
62+
63+
return optOutState;
5764
}
5865

5966
@POST

src/main/java/org/graylog/plugins/usagestatistics/UsageStatsOptOutService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ public UsageStatsOptOutService(ClusterConfigService clusterConfigService,
6060
this.objectMapper = objectMapper;
6161
}
6262

63+
@Nullable
6364
public UsageStatsOptOutState getOptOutState() {
64-
return clusterConfigService.getOrDefault(UsageStatsOptOutState.class, UsageStatsOptOutState.create(false));
65+
return clusterConfigService.get(UsageStatsOptOutState.class);
6566
}
6667

6768
public void setOptOutState(final UsageStatsOptOutState optOutState) {

src/test/java/org/graylog/plugins/usagestatistics/UsageStatsOptOutServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void tearDown() throws Exception {
8484
@Test
8585
public void testGetOptOutState() throws Exception {
8686
clusterConfigService.clear();
87-
assertThat(optOutService.getOptOutState().isOptOut()).isFalse();
87+
assertThat(optOutService.getOptOutState()).isNull();
8888

8989
clusterConfigService.write(UsageStatsOptOutState.create(false));
9090
assertThat(optOutService.getOptOutState().isOptOut()).isFalse();

0 commit comments

Comments
 (0)