Skip to content

Commit cd8a3f3

Browse files
author
Guillaume Lamirand
committed
refactor: code clean up
1 parent ddf742f commit cd8a3f3

File tree

12 files changed

+277
-288
lines changed

12 files changed

+277
-288
lines changed

.github/renovate.json

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
{
2-
"extends": [
3-
"config:base"
4-
],
5-
"rebaseWhen": "conflicted",
6-
"packageRules": [
7-
{
8-
"matchDatasources": ["orb"],
9-
"matchUpdateTypes": ["patch", "minor"],
10-
"automerge": true,
11-
"automergeType": "branch",
12-
"semanticCommitType": "ci"
13-
},
14-
{
15-
"matchDepTypes": ["provided", "test", "build", "import", "parent"],
16-
"matchUpdateTypes": ["patch", "minor"],
17-
"automerge": true,
18-
"automergeType": "branch",
19-
"semanticCommitType": "chore"
20-
}
21-
]
22-
}
2+
"extends": ["config:base"],
3+
"rebaseWhen": "conflicted",
4+
"packageRules": [
5+
{
6+
"matchDatasources": ["orb"],
7+
"matchUpdateTypes": ["patch", "minor"],
8+
"automerge": true,
9+
"automergeType": "branch",
10+
"semanticCommitType": "ci"
11+
},
12+
{
13+
"matchDepTypes": ["provided", "test", "build", "import", "parent"],
14+
"matchUpdateTypes": ["patch", "minor"],
15+
"automerge": true,
16+
"automergeType": "branch",
17+
"semanticCommitType": "chore"
18+
}
19+
]
20+
}

pom.xml

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (C) 2015 The Gravitee team (http://gravitee.io)
4+
Copyright © 2015 The Gravitee team (http://gravitee.io)
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
88
You may obtain a copy of the License at
99
10-
http://www.apache.org/licenses/LICENSE-2.0
10+
http://www.apache.org/licenses/LICENSE-2.0
1111
1212
Unless required by applicable law or agreed to in writing, software
1313
distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,6 +19,11 @@
1919
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2020
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2121
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>io.gravitee</groupId>
24+
<artifactId>gravitee-parent</artifactId>
25+
<version>22.1.13</version>
26+
</parent>
2227

2328
<groupId>io.gravitee.policy</groupId>
2429
<artifactId>gravitee-policy-ipfiltering</artifactId>
@@ -30,26 +35,27 @@
3035
You can use IPv4 and CIDR notation.
3136
</description>
3237

33-
<parent>
34-
<groupId>io.gravitee</groupId>
35-
<artifactId>gravitee-parent</artifactId>
36-
<version>21.0.1</version>
37-
</parent>
3838

3939
<properties>
40-
<gravitee-bom.version>5.0.0</gravitee-bom.version>
41-
<gravitee-gateway-api.version>1.47.1</gravitee-gateway-api.version>
42-
<gravitee-node-api.version>1.27.9</gravitee-node-api.version>
40+
<gravitee-bom.version>6.0.60</gravitee-bom.version>
41+
<gravitee-gateway-api.version>3.0.0</gravitee-gateway-api.version>
42+
<gravitee-node-api.version>4.8.7</gravitee-node-api.version>
4343

44-
<gravitee-policy-api.version>1.4.0</gravitee-policy-api.version>
45-
<gravitee-common.version>1.28.0</gravitee-common.version>
44+
<gravitee-policy-api.version>1.11.0</gravitee-policy-api.version>
45+
<gravitee-common.version>2.1.1</gravitee-common.version>
4646

4747
<json-schema-generator-maven-plugin.version>1.3.0</json-schema-generator-maven-plugin.version>
48-
<json-schema-generator-maven-plugin.outputDirectory>${project.build.directory}/schemas</json-schema-generator-maven-plugin.outputDirectory>
48+
<json-schema-generator-maven-plugin.outputDirectory>${project.build.directory}/schemas
49+
</json-schema-generator-maven-plugin.outputDirectory>
50+
51+
<commons-net.version>3.11.1</commons-net.version>
52+
<commons-validator.version>1.9.0</commons-validator.version>
53+
54+
<!-- Maven plugins -->
55+
<maven-plugin-assembly.version>3.7.1</maven-plugin-assembly.version>
56+
<maven-plugin-properties.version>1.2.1</maven-plugin-properties.version>
4957

50-
<maven-assembly-plugin.version>2.5.5</maven-assembly-plugin.version>
51-
<commons-net.version>3.6</commons-net.version>
52-
<commons-validator.version>1.7</commons-validator.version>
58+
<!-- Property used by the publication job in CI-->
5359
<publish-folder-path>graviteeio-apim/plugins/policies</publish-folder-path>
5460
</properties>
5561

@@ -119,11 +125,26 @@
119125
<artifactId>commons-net</artifactId>
120126
<version>${commons-net.version}</version>
121127
</dependency>
128+
<dependency>
129+
<groupId>org.junit.jupiter</groupId>
130+
<artifactId>junit-jupiter</artifactId>
131+
<scope>test</scope>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.assertj</groupId>
135+
<artifactId>assertj-core</artifactId>
136+
<scope>test</scope>
137+
</dependency>
122138
<dependency>
123139
<groupId>org.mockito</groupId>
124140
<artifactId>mockito-core</artifactId>
125141
<scope>test</scope>
126142
</dependency>
143+
<dependency>
144+
<groupId>org.mockito</groupId>
145+
<artifactId>mockito-junit-jupiter</artifactId>
146+
<scope>test</scope>
147+
</dependency>
127148
</dependencies>
128149

129150
<build>
@@ -175,7 +196,7 @@
175196
</plugin>
176197
<plugin>
177198
<artifactId>maven-assembly-plugin</artifactId>
178-
<version>${maven-assembly-plugin.version}</version>
199+
<version>${maven-plugin-assembly.version}</version>
179200
<configuration>
180201
<appendAssemblyId>false</appendAssemblyId>
181202
<descriptors>

src/assembly/policy-assembly.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<!--
22
3-
Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3+
Copyright © 2015 The Gravitee team (http://gravitee.io)
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
77
You may obtain a copy of the License at
88
9-
http://www.apache.org/licenses/LICENSE-2.0
9+
http://www.apache.org/licenses/LICENSE-2.0
1010
1111
Unless required by applicable law or agreed to in writing, software
1212
distributed under the License is distributed on an "AS IS" BASIS,

src/main/java/io/gravitee/policy/ipfiltering/DnsConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/**
2-
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
1+
/*
2+
* Copyright © 2015 The Gravitee team (http://gravitee.io)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,

src/main/java/io/gravitee/policy/ipfiltering/IPFilteringPolicy.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/**
2-
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
1+
/*
2+
* Copyright © 2015 The Gravitee team (http://gravitee.io)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -32,6 +32,7 @@
3232
import java.util.Arrays;
3333
import java.util.List;
3434
import java.util.Objects;
35+
import lombok.extern.slf4j.Slf4j;
3536
import org.apache.commons.net.util.SubnetUtils;
3637
import org.apache.commons.validator.routines.InetAddressValidator;
3738
import org.slf4j.Logger;
@@ -42,10 +43,9 @@
4243
* @author Azize ELAMRANI (azize.elamrani at graviteesource.com)
4344
* @author GraviteeSource Team
4445
*/
46+
@Slf4j
4547
public class IPFilteringPolicy {
4648

47-
private static final Logger LOGGER = LoggerFactory.getLogger(IPFilteringPolicy.class);
48-
4949
private final IPFilteringPolicyConfiguration configuration;
5050

5151
/**
@@ -87,7 +87,7 @@ public void onRequest(ExecutionContext executionContext, PolicyChain policyChain
8787
promise.complete();
8888
}
8989
} else {
90-
LOGGER.error("Cannot resolve host: '" + host + "'", event.cause());
90+
log.error("Cannot resolve host: '" + host + "'", event.cause());
9191
promise.complete();
9292
}
9393
}
@@ -121,7 +121,7 @@ public void onRequest(ExecutionContext executionContext, PolicyChain policyChain
121121
promise.complete();
122122
}
123123
} else {
124-
LOGGER.error("Cannot resolve host: '" + host + "'", event.cause());
124+
log.error("Cannot resolve host: '" + host + "'", event.cause());
125125
promise.complete();
126126
}
127127
}
Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/**
2-
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
1+
/*
2+
* Copyright © 2015 The Gravitee team (http://gravitee.io)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,8 +18,11 @@
1818
import io.gravitee.policy.api.PolicyConfiguration;
1919
import java.util.List;
2020
import java.util.stream.Collectors;
21+
import lombok.Getter;
22+
import lombok.Setter;
2123

22-
@SuppressWarnings("unused")
24+
@Getter
25+
@Setter
2326
public class IPFilteringPolicyConfiguration implements PolicyConfiguration {
2427

2528
/**
@@ -43,44 +46,4 @@ public class IPFilteringPolicyConfiguration implements PolicyConfiguration {
4346
private LookupIpVersion lookupIpVersion;
4447

4548
private boolean isInclusiveHostCount = false;
46-
47-
public boolean isMatchAllFromXForwardedFor() {
48-
return matchAllFromXForwardedFor;
49-
}
50-
51-
public void setMatchAllFromXForwardedFor(boolean matchAllFromXForwardedFor) {
52-
this.matchAllFromXForwardedFor = matchAllFromXForwardedFor;
53-
}
54-
55-
public List<String> getWhitelistIps() {
56-
return whitelistIps;
57-
}
58-
59-
public void setWhitelistIps(List<String> whitelistIps) {
60-
this.whitelistIps = whitelistIps == null ? List.of() : whitelistIps.stream().map(String::trim).collect(Collectors.toList());
61-
}
62-
63-
public List<String> getBlacklistIps() {
64-
return blacklistIps;
65-
}
66-
67-
public void setBlacklistIps(List<String> blacklistIps) {
68-
this.blacklistIps = blacklistIps == null ? List.of() : blacklistIps.stream().map(String::trim).collect(Collectors.toList());
69-
}
70-
71-
public LookupIpVersion getLookupIpVersion() {
72-
return lookupIpVersion == null ? LookupIpVersion.ALL : lookupIpVersion;
73-
}
74-
75-
public void setLookupIpVersion(LookupIpVersion lookupIpVersion) {
76-
this.lookupIpVersion = lookupIpVersion;
77-
}
78-
79-
public void setInclusiveHostCount(boolean inclusiveHostCount) {
80-
isInclusiveHostCount = inclusiveHostCount;
81-
}
82-
83-
public boolean isInclusiveHostCount() {
84-
return isInclusiveHostCount;
85-
}
8649
}

src/main/java/io/gravitee/policy/ipfiltering/LazyDnsClient.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/**
2-
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
1+
/*
2+
* Copyright © 2015 The Gravitee team (http://gravitee.io)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,6 +22,8 @@
2222
import io.vertx.core.Handler;
2323
import io.vertx.core.Vertx;
2424
import io.vertx.core.dns.DnsClient;
25+
import lombok.AccessLevel;
26+
import lombok.NoArgsConstructor;
2527

2628
/**
2729
* LazyDnsClient is an abstract class that provides a lazy initialization of a DNS client. The DNS client is only created when required.
@@ -31,13 +33,12 @@
3133
* @see DnsClient
3234
* @see ExecutionContext
3335
*/
36+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3437
public class LazyDnsClient {
3538

36-
private LazyDnsClient() {}
37-
3839
private static DnsClient dnsClient;
3940

40-
public static DnsClient get(ExecutionContext context) {
41+
public static DnsClient get(final ExecutionContext context) {
4142
if (dnsClient == null) {
4243
DnsConfiguration dnsConfiguration = new DnsConfiguration(context.getComponent(Configuration.class));
4344
dnsConfiguration.getDnsClientOptions().setRecursionDesired(true);
@@ -55,16 +56,9 @@ public static void lookup(
5556
) {
5657
DnsClient client = get(executionContext);
5758
switch (lookupIpVersion) {
58-
case IPV6:
59-
client.lookup6(host, handler);
60-
break;
61-
case IPV4:
62-
client.lookup4(host, handler);
63-
break;
64-
case ALL:
65-
default:
66-
client.lookup(host, handler);
67-
break;
59+
case IPV6 -> client.lookup6(host, handler);
60+
case IPV4 -> client.lookup4(host, handler);
61+
default -> client.lookup(host, handler);
6862
}
6963
}
7064
}

src/main/java/io/gravitee/policy/ipfiltering/LookupIpVersion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/**
2-
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
1+
/*
2+
* Copyright © 2015 The Gravitee team (http://gravitee.io)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,

0 commit comments

Comments
 (0)