Skip to content

Commit 597267e

Browse files
authored
feat: make nf.ni.ls API key optional (#66)
1 parent c8579aa commit 597267e

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

bungee/pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@
1414
<name>NetworkFilterBungee</name>
1515
<description/>
1616

17-
<repositories>
18-
<repository>
19-
<id>bungeecord-repo</id>
20-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
21-
</repository>
22-
</repositories>
23-
2417
<dependencies>
2518
<dependency>
2619
<groupId>net.md-5</groupId>
2720
<artifactId>bungeecord-api</artifactId>
28-
<version>1.21-R0.1-SNAPSHOT</version>
21+
<version>1.21-R0.1</version>
2922
<scope>provided</scope>
3023
</dependency>
3124

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package ls.ni.networkfilter.common.config.service.types;
22

3-
import jakarta.validation.constraints.NotNull;
43
import lombok.AllArgsConstructor;
54
import lombok.Data;
65
import lombok.NoArgsConstructor;
6+
import org.jetbrains.annotations.Nullable;
77

88
@Data
99
@NoArgsConstructor
1010
@AllArgsConstructor
1111
public class NetworkFilterServiceSettings {
1212

13-
@NotNull
13+
@Nullable
1414
private String key;
1515
}

common/src/main/java/ls/ni/networkfilter/common/filter/types/NetworkFilterFilterService.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ls.ni.networkfilter.common.filter.types;
22

3-
import jakarta.validation.constraints.NotBlank;
3+
import kong.unirest.core.HttpRequestWithBody;
44
import kong.unirest.core.HttpResponse;
55
import kong.unirest.core.JsonNode;
66
import kong.unirest.core.Unirest;
@@ -10,17 +10,18 @@
1010
import ls.ni.networkfilter.common.filter.FilterResult;
1111
import ls.ni.networkfilter.common.filter.FilterService;
1212
import org.jetbrains.annotations.NotNull;
13+
import org.jetbrains.annotations.Nullable;
1314

1415
import java.util.List;
1516
import java.util.Optional;
1617

1718
public class NetworkFilterFilterService implements FilterService {
1819

19-
@NotNull
20+
@Nullable
2021
private final String apiKey;
2122

22-
public NetworkFilterFilterService(@NotNull @NotBlank String apiKey) {
23-
this.apiKey = apiKey;
23+
public NetworkFilterFilterService(@Nullable String apiKey) {
24+
this.apiKey = apiKey != null && !apiKey.isBlank() ? apiKey : null;
2425
}
2526

2627
@Override
@@ -30,9 +31,14 @@ public NetworkFilterFilterService(@NotNull @NotBlank String apiKey) {
3031

3132
@Override
3233
public @NotNull FilterResult check(@NotNull String ip) {
33-
HttpResponse<JsonNode> response = Unirest.post("https://nf.ni.ls/api/check")
34-
.header("X-API-KEY", this.apiKey)
35-
.header("Content-Type", "application/x-www-form-urlencoded")
34+
HttpRequestWithBody request = Unirest.post("https://nf.ni.ls/api/check")
35+
.header("Content-Type", "application/x-www-form-urlencoded");
36+
37+
if (this.apiKey != null) {
38+
request.header("X-API-KEY", this.apiKey);
39+
}
40+
41+
HttpResponse<JsonNode> response = request
3642
.field("ip", ip)
3743
.asJson();
3844

common/src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ caches:
2020
services:
2121
# https://nf.ni.ls
2222
networkfilter:
23-
# Required
23+
# Optional, needed if rate-limited
2424
key: ""
2525

2626
# https://ipapi.is

0 commit comments

Comments
 (0)