Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: code clean up #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ setup: true
orbs:
gravitee: gravitee-io/[email protected]


# our single workflow, that triggers the setup job defined above, filters on tag and branches are needed otherwise
# some workflow and job will not be triggered for tags (default CircleCI behavior)
workflows:
Expand All @@ -33,4 +32,4 @@ workflows:
- /.*/
tags:
only:
- /^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.[0-9]+)?$/
- /^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.[0-9]+)?$/
40 changes: 19 additions & 21 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{
"extends": [
"config:base"
],
"rebaseWhen": "conflicted",
"packageRules": [
{
"matchDatasources": ["orb"],
"matchUpdateTypes": ["patch", "minor"],
"automerge": true,
"automergeType": "branch",
"semanticCommitType": "ci"
},
{
"matchDepTypes": ["provided", "test", "build", "import", "parent"],
"matchUpdateTypes": ["patch", "minor"],
"automerge": true,
"automergeType": "branch",
"semanticCommitType": "chore"
}
]
}
"extends": ["config:base"],
"rebaseWhen": "conflicted",
"packageRules": [
{
"matchDatasources": ["orb"],
"matchUpdateTypes": ["patch", "minor"],
"automerge": true,
"automergeType": "branch",
"semanticCommitType": "ci"
},
{
"matchDepTypes": ["provided", "test", "build", "import", "parent"],
"matchUpdateTypes": ["patch", "minor"],
"automerge": true,
"automergeType": "branch",
"semanticCommitType": "chore"
}
]
}
55 changes: 38 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) 2015 The Gravitee team (http://gravitee.io)
Copyright © 2015 The Gravitee team (http://gravitee.io)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -19,6 +19,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.gravitee</groupId>
<artifactId>gravitee-parent</artifactId>
<version>22.1.13</version>
</parent>

<groupId>io.gravitee.policy</groupId>
<artifactId>gravitee-policy-ipfiltering</artifactId>
Expand All @@ -30,26 +35,27 @@
You can use IPv4 and CIDR notation.
</description>

<parent>
<groupId>io.gravitee</groupId>
<artifactId>gravitee-parent</artifactId>
<version>21.0.1</version>
</parent>

<properties>
<gravitee-bom.version>5.0.0</gravitee-bom.version>
<gravitee-gateway-api.version>1.47.1</gravitee-gateway-api.version>
<gravitee-node-api.version>1.27.9</gravitee-node-api.version>
<gravitee-bom.version>6.0.60</gravitee-bom.version>
<gravitee-gateway-api.version>3.0.0</gravitee-gateway-api.version>
<gravitee-node-api.version>4.8.7</gravitee-node-api.version>

<gravitee-policy-api.version>1.4.0</gravitee-policy-api.version>
<gravitee-common.version>1.28.0</gravitee-common.version>
<gravitee-policy-api.version>1.11.0</gravitee-policy-api.version>
<gravitee-common.version>2.1.1</gravitee-common.version>

<json-schema-generator-maven-plugin.version>1.3.0</json-schema-generator-maven-plugin.version>
<json-schema-generator-maven-plugin.outputDirectory>${project.build.directory}/schemas</json-schema-generator-maven-plugin.outputDirectory>
<json-schema-generator-maven-plugin.outputDirectory>${project.build.directory}/schemas
</json-schema-generator-maven-plugin.outputDirectory>

<commons-net.version>3.11.1</commons-net.version>
<commons-validator.version>1.9.0</commons-validator.version>

<!-- Maven plugins -->
<maven-plugin-assembly.version>3.7.1</maven-plugin-assembly.version>
<maven-plugin-properties.version>1.2.1</maven-plugin-properties.version>

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

Expand Down Expand Up @@ -119,11 +125,26 @@
<artifactId>commons-net</artifactId>
<version>${commons-net.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -175,7 +196,7 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<version>${maven-plugin-assembly.version}</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
Expand Down
4 changes: 2 additions & 2 deletions src/assembly/policy-assembly.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!--

Copyright (C) 2015 The Gravitee team (http://gravitee.io)
Copyright © 2015 The Gravitee team (http://gravitee.io)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -32,6 +32,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.net.util.SubnetUtils;
import org.apache.commons.validator.routines.InetAddressValidator;
import org.slf4j.Logger;
Expand All @@ -42,10 +43,9 @@
* @author Azize ELAMRANI (azize.elamrani at graviteesource.com)
* @author GraviteeSource Team
*/
@Slf4j
public class IPFilteringPolicy {

private static final Logger LOGGER = LoggerFactory.getLogger(IPFilteringPolicy.class);

private final IPFilteringPolicyConfiguration configuration;

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ public void onRequest(ExecutionContext executionContext, PolicyChain policyChain
promise.complete();
}
} else {
LOGGER.error("Cannot resolve host: '" + host + "'", event.cause());
log.error("Cannot resolve host: '" + host + "'", event.cause());
promise.complete();
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public void onRequest(ExecutionContext executionContext, PolicyChain policyChain
promise.complete();
}
} else {
LOGGER.error("Cannot resolve host: '" + host + "'", event.cause());
log.error("Cannot resolve host: '" + host + "'", event.cause());
promise.complete();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -18,8 +18,11 @@
import io.gravitee.policy.api.PolicyConfiguration;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;

@SuppressWarnings("unused")
@Getter
@Setter
public class IPFilteringPolicyConfiguration implements PolicyConfiguration {

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

private boolean isInclusiveHostCount = false;

public boolean isMatchAllFromXForwardedFor() {
return matchAllFromXForwardedFor;
}

public void setMatchAllFromXForwardedFor(boolean matchAllFromXForwardedFor) {
this.matchAllFromXForwardedFor = matchAllFromXForwardedFor;
}

public List<String> getWhitelistIps() {
return whitelistIps;
}

public void setWhitelistIps(List<String> whitelistIps) {
this.whitelistIps = whitelistIps == null ? List.of() : whitelistIps.stream().map(String::trim).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use this implementation instead of the Lombok generated one?

}

public List<String> getBlacklistIps() {
return blacklistIps;
}

public void setBlacklistIps(List<String> blacklistIps) {
this.blacklistIps = blacklistIps == null ? List.of() : blacklistIps.stream().map(String::trim).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use this implementation instead of the Lombok generated one?

}

public LookupIpVersion getLookupIpVersion() {
return lookupIpVersion == null ? LookupIpVersion.ALL : lookupIpVersion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use this implementation instead of the Lombok generated one?

}

public void setLookupIpVersion(LookupIpVersion lookupIpVersion) {
this.lookupIpVersion = lookupIpVersion;
}

public void setInclusiveHostCount(boolean inclusiveHostCount) {
isInclusiveHostCount = inclusiveHostCount;
}

public boolean isInclusiveHostCount() {
return isInclusiveHostCount;
}
}
26 changes: 10 additions & 16 deletions src/main/java/io/gravitee/policy/ipfiltering/LazyDnsClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -22,6 +22,8 @@
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.dns.DnsClient;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

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

private LazyDnsClient() {}

private static DnsClient dnsClient;

public static DnsClient get(ExecutionContext context) {
public static DnsClient get(final ExecutionContext context) {
if (dnsClient == null) {
DnsConfiguration dnsConfiguration = new DnsConfiguration(context.getComponent(Configuration.class));
dnsConfiguration.getDnsClientOptions().setRecursionDesired(true);
Expand All @@ -55,16 +56,9 @@ public static void lookup(
) {
DnsClient client = get(executionContext);
switch (lookupIpVersion) {
case IPV6:
client.lookup6(host, handler);
break;
case IPV4:
client.lookup4(host, handler);
break;
case ALL:
default:
client.lookup(host, handler);
break;
case IPV6 -> client.lookup6(host, handler);
case IPV4 -> client.lookup4(host, handler);
default -> client.lookup(host, handler);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Loading