Skip to content

Commit

Permalink
[INLONG-7673][Manager] Remove whitespace when saving or updating URLs (
Browse files Browse the repository at this point in the history
  • Loading branch information
fuweng11 committed Mar 27, 2023
1 parent 9bedbac commit 963c193
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 6 deletions.
Expand Up @@ -35,6 +35,8 @@ public class InlongConstants {
*/
public static final String COMMA = ",";

public static final String BLANK = " ";

public static final String SLASH = "/";

public static final String COLON = ":";
Expand Down
Expand Up @@ -65,6 +65,7 @@ public abstract class ClusterRequest {

@ApiModelProperty(value = "Cluster url")
@Length(max = 512, message = "length must be less than or equal to 512")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String url;

@ApiModelProperty(value = "Extension tag")
Expand Down
Expand Up @@ -27,6 +27,8 @@
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.cluster.ClusterRequest;

import javax.validation.constraints.Pattern;

/**
* Inlong cluster request for Pulsar
*/
Expand All @@ -38,6 +40,7 @@
public class PulsarClusterRequest extends ClusterRequest {

@ApiModelProperty(value = "Pulsar admin URL, such as: http://127.0.0.1:8080", notes = "Pulsar service URL is the 'url' field of the cluster")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String adminUrl;

@ApiModelProperty(value = "Pulsar tenant, default is 'public'")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.cluster.ClusterRequest;

import javax.validation.constraints.Pattern;

/**
* Inlong cluster request for TubeMQ
*/
Expand All @@ -37,6 +39,7 @@
public class TubeClusterRequest extends ClusterRequest {

@ApiModelProperty(value = "Master Web URL http://120.0.0.1:8080", notes = "TubeMQ master RPC URL is the 'url' field of the cluster")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String masterWebUrl;

public TubeClusterRequest() {
Expand Down
Expand Up @@ -60,6 +60,7 @@ public abstract class DataNodeRequest {

@ApiModelProperty(value = "Data node URL")
@Length(max = 512, message = "length must be less than or equal to 512")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String url;

@ApiModelProperty(value = "Data node username")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.node.DataNodeRequest;

import javax.validation.constraints.Pattern;

/**
* MySQL data node request
*/
Expand All @@ -37,6 +39,7 @@
public class MySQLDataNodeRequest extends DataNodeRequest {

@ApiModelProperty("URL of backup DB server")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String backupUrl;

}
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.sink.SinkRequest;

import javax.validation.constraints.Pattern;

/**
* ClickHouse sink request.
*/
Expand All @@ -37,6 +39,7 @@
public class ClickHouseSinkRequest extends SinkRequest {

@ApiModelProperty("JDBC URL of the ClickHouse server")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Username of the ClickHouse server")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.pojo.sink.SinkRequest;
import org.apache.inlong.manager.common.util.JsonTypeDefine;

import javax.validation.constraints.Pattern;

/**
* Greenplum sink request.
*/
Expand All @@ -37,6 +39,7 @@
public class GreenplumSinkRequest extends SinkRequest {

@ApiModelProperty("Greenplum JDBC URL such as:jdbc:postgresql://host:port/database")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Username for JDBC URL")
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.apache.inlong.manager.pojo.sink.SinkRequest;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.nio.charset.StandardCharsets;
import java.util.List;

Expand All @@ -42,6 +43,7 @@
public class HiveSinkRequest extends SinkRequest {

@ApiModelProperty("Hive JDBC URL, such as jdbc:hive2://${ip}:${port}")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Username of the Hive server")
Expand Down
Expand Up @@ -28,6 +28,8 @@
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.sink.SinkRequest;

import javax.validation.constraints.Pattern;

/**
* Hudi sink request.
*/
Expand All @@ -42,6 +44,7 @@ public class HudiSinkRequest extends SinkRequest {
private String catalogType = "HIVE";

@ApiModelProperty("Catalog uri, such as hive metastore thrift://ip:port")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String catalogUri;

@ApiModelProperty("Hudi data warehouse dir")
Expand Down
Expand Up @@ -225,6 +225,7 @@ public static String filterSensitive(String url) {
while (resultUrl.contains(InlongConstants.PERCENT)) {
resultUrl = URLDecoder.decode(resultUrl, "UTF-8");
}
resultUrl = resultUrl.replaceAll(InlongConstants.BLANK, "");
for (String sensitiveParam : SENSITIVE_PARAM_MAP.keySet()) {
if (StringUtils.containsIgnoreCase(resultUrl, sensitiveParam)) {
resultUrl = StringUtils.replaceIgnoreCase(resultUrl, sensitiveParam,
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.pojo.sink.SinkRequest;
import org.apache.inlong.manager.common.util.JsonTypeDefine;

import javax.validation.constraints.Pattern;

/**
* MySQL sink request.
*/
Expand All @@ -37,6 +39,7 @@
public class MySQLSinkRequest extends SinkRequest {

@ApiModelProperty("MySQL JDBC URL, such as jdbc:mysql://host:port")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Username for JDBC URL")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.pojo.sink.SinkRequest;
import org.apache.inlong.manager.common.util.JsonTypeDefine;

import javax.validation.constraints.Pattern;

/**
* Oracle sink request.
*/
Expand All @@ -37,6 +39,7 @@
public class OracleSinkRequest extends SinkRequest {

@ApiModelProperty("Oracle JDBC URL, such as jdbc:oracle:thin://host:port/database")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Username for JDBC URL")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.pojo.sink.SinkRequest;
import org.apache.inlong.manager.common.util.JsonTypeDefine;

import javax.validation.constraints.Pattern;

/**
* PostgreSQL sink request.
*/
Expand All @@ -37,6 +39,7 @@
public class PostgreSQLSinkRequest extends SinkRequest {

@ApiModelProperty("JDBC URL of the PostgreSQL server")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Username for JDBC URL")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.pojo.sink.SinkRequest;
import org.apache.inlong.manager.common.util.JsonTypeDefine;

import javax.validation.constraints.Pattern;

/**
* SQLServer sink request.
*/
Expand All @@ -43,6 +45,7 @@ public class SQLServerSinkRequest extends SinkRequest {
private String password;

@ApiModelProperty("SQLServer meta db URL, etc jdbc:sqlserver://host:port;databaseName=database")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Schema name of the SQLServer")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.sink.SinkRequest;

import javax.validation.constraints.Pattern;

/**
* StarRocks sink request.
*/
Expand All @@ -37,6 +39,7 @@
public class StarRocksSinkRequest extends SinkRequest {

@ApiModelProperty("StarRocks jdbc url")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("StarRocks FE http address")
Expand Down
Expand Up @@ -26,6 +26,8 @@
import org.apache.inlong.manager.pojo.sink.SinkRequest;
import org.apache.inlong.manager.common.util.JsonTypeDefine;

import javax.validation.constraints.Pattern;

/**
* TDSQLPostgreSQL sink request.
*/
Expand All @@ -37,6 +39,7 @@
public class TDSQLPostgreSQLSinkRequest extends SinkRequest {

@ApiModelProperty("TDSQLPostgreSQL jdbc url, such as jdbc:postgresql://host:port/database")
@Pattern(regexp = "^((?!\\s).)*$", message = "not supports blank in url")
private String jdbcUrl;

@ApiModelProperty("Username for JDBC URL")
Expand Down
Expand Up @@ -31,43 +31,43 @@ public class MySQLSinkDTOTest {
public void testFilterSensitive() throws Exception {
// the sensitive params no use url code
String originUrl = MySQLSinkDTO.filterSensitive(
"autoDeserialize=TRue&allowLoadLocalInfile=TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/&autoReconnect=true");
"autoDeserialize=TRue&allowLoadLocalInfile = TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/&autoReconnect=true");
Assertions.assertEquals(
"autoDeserialize=false&allowLoadLocalInfile=false&allowUrlInLocalInfile=false&allowLoadLocalInfileInPath=&autoReconnect=true",
originUrl);

originUrl = MySQLSinkDTO.filterSensitive(
"autoReconnect=true&autoDeserialize=TRue&allowLoadLocalInfile=TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/");
"autoReconnect=true&autoDeserialize = TRue&allowLoadLocalInfile=TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/");
Assertions.assertEquals(
"autoReconnect=true&autoDeserialize=false&allowLoadLocalInfile=false&allowUrlInLocalInfile=false&allowLoadLocalInfileInPath=",
originUrl);

originUrl = MySQLSinkDTO.filterSensitive(
"autoDeserialize=TRue&allowLoadLocalInfile=TRue&autoReconnect=true&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/");
"autoDeserialize=TRue&allowLoadLocalInfile = TRue&autoReconnect=true&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/");
Assertions.assertEquals(
"autoDeserialize=false&allowLoadLocalInfile=false&autoReconnect=true&allowUrlInLocalInfile=false&allowLoadLocalInfileInPath=",
originUrl);

// the sensitive params use url code
originUrl = MySQLSinkDTO.filterSensitive(
URLEncoder.encode(
"autoDeserialize=TRue&allowLoadLocalInfile=TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/&autoReconnect=true",
"autoDeserialize=TRue&allowLoadLocalInfile = TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/&autoReconnect=true",
"UTF-8"));
Assertions.assertEquals(
"autoDeserialize=false&allowLoadLocalInfile=false&allowUrlInLocalInfile=false&allowLoadLocalInfileInPath=&autoReconnect=true",
originUrl);

originUrl = MySQLSinkDTO.filterSensitive(
URLEncoder.encode(
"autoReconnect=true&autoDeserialize=TRue&allowLoadLocalInfile=TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/",
"autoReconnect=true&autoDeserialize = TRue&allowLoadLocalInfile=TRue&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/",
"UTF-8"));
Assertions.assertEquals(
"autoReconnect=true&autoDeserialize=false&allowLoadLocalInfile=false&allowUrlInLocalInfile=false&allowLoadLocalInfileInPath=",
originUrl);

originUrl = MySQLSinkDTO.filterSensitive(
URLEncoder.encode(
"autoDeserialize=TRue&allowLoadLocalInfile=TRue&autoReconnect=true&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/",
"autoDeserialize=TRue&allowLoadLocalInfile = TRue&autoReconnect=true&allowUrlInLocalInfile=TRue&allowLoadLocalInfileInPath=/",
"UTF-8"));
Assertions.assertEquals(
"autoDeserialize=false&allowLoadLocalInfile=false&autoReconnect=true&allowUrlInLocalInfile=false&allowLoadLocalInfileInPath=",
Expand Down

0 comments on commit 963c193

Please sign in to comment.