-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-9671][Manager] Adding JDBC URL checks to the updateAuditSourc…
…e method (#9673) * [INLONG-9671][Manager] Adding JDBC URL checks to the updateAuditSource method * foramt code * Implementing AuditSourceOperator functionality * add AuditSourceType class * add comment * Optimizing Elasticsearch Operator
- Loading branch information
1 parent
ec30ca2
commit 8b72deb
Showing
9 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...manager-common/src/main/java/org/apache/inlong/manager/common/consts/AuditSourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.manager.common.consts; | ||
|
||
/** | ||
* Audit Source Type | ||
*/ | ||
public enum AuditSourceType { | ||
MYSQL, CLICKHOUSE, ELASTICSEARCH | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ce/src/main/java/org/apache/inlong/manager/service/audit/AbstractAuditSourceOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.manager.service.audit; | ||
|
||
/** | ||
* Default of Audit Source Operator. | ||
*/ | ||
public abstract class AbstractAuditSourceOperator implements InlongAuditSourceOperator { | ||
|
||
@Override | ||
public Boolean accept(String type) { | ||
return getType().equals(type.toUpperCase()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../src/main/java/org/apache/inlong/manager/service/audit/AuditSourceClickhouseOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.manager.service.audit; | ||
|
||
import org.apache.inlong.manager.common.consts.AuditSourceType; | ||
import org.apache.inlong.manager.common.enums.ErrorCodeEnum; | ||
import org.apache.inlong.manager.common.exceptions.BusinessException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Audit source clickhouse operator. | ||
*/ | ||
@Service | ||
public class AuditSourceClickhouseOperator extends AbstractAuditSourceOperator { | ||
|
||
private static final String CLICKHOUSE_URL_PREFIX = "jdbc:clickhouse://"; | ||
|
||
@Override | ||
public String getType() { | ||
return AuditSourceType.CLICKHOUSE.name(); | ||
} | ||
|
||
@Override | ||
public String convertTo(String url) { | ||
if (StringUtils.isNotBlank(url) && url.startsWith(CLICKHOUSE_URL_PREFIX)) { | ||
return url; | ||
} | ||
|
||
throw new BusinessException(String.format(ErrorCodeEnum.AUDIT_SOURCE_URL_NOT_SUPPORTED.getMessage(), url)); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...c/main/java/org/apache/inlong/manager/service/audit/AuditSourceElasticsearchOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.manager.service.audit; | ||
|
||
import org.apache.inlong.manager.common.consts.AuditSourceType; | ||
import org.apache.inlong.manager.common.enums.ErrorCodeEnum; | ||
import org.apache.inlong.manager.common.exceptions.BusinessException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Audit source elasticsearch operator. | ||
*/ | ||
@Service | ||
public class AuditSourceElasticsearchOperator extends AbstractAuditSourceOperator { | ||
|
||
private static final String ES_HTTP_HOST_PREFIX = "http://"; | ||
private static final String ES_HTTPS_HOST_PREFIX = "https://"; | ||
|
||
@Override | ||
public String getType() { | ||
return AuditSourceType.ELASTICSEARCH.name(); | ||
} | ||
|
||
@Override | ||
public String convertTo(String url) { | ||
if (StringUtils.isNotBlank(url) | ||
&& (url.startsWith(ES_HTTP_HOST_PREFIX) || url.startsWith(ES_HTTPS_HOST_PREFIX))) { | ||
return url; | ||
} | ||
|
||
throw new BusinessException(String.format(ErrorCodeEnum.AUDIT_SOURCE_URL_NOT_SUPPORTED.getMessage(), url)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...rvice/src/main/java/org/apache/inlong/manager/service/audit/AuditSourceMysqlOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.manager.service.audit; | ||
|
||
import org.apache.inlong.manager.common.consts.AuditSourceType; | ||
import org.apache.inlong.manager.common.enums.ErrorCodeEnum; | ||
import org.apache.inlong.manager.common.exceptions.BusinessException; | ||
import org.apache.inlong.manager.pojo.util.MySQLSensitiveUrlUtils; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Audit source mysql operator. | ||
*/ | ||
@Service | ||
public class AuditSourceMysqlOperator extends AbstractAuditSourceOperator { | ||
|
||
private static final String MYSQL_JDBC_PREFIX = "jdbc:mysql://"; | ||
|
||
@Override | ||
public String getType() { | ||
return AuditSourceType.MYSQL.name(); | ||
} | ||
|
||
@Override | ||
public String convertTo(String url) { | ||
if (StringUtils.isNotBlank(url) && url.startsWith(MYSQL_JDBC_PREFIX)) { | ||
return MySQLSensitiveUrlUtils.filterSensitive(url); | ||
} | ||
|
||
throw new BusinessException(String.format(ErrorCodeEnum.AUDIT_SOURCE_URL_NOT_SUPPORTED.getMessage(), url)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...vice/src/main/java/org/apache/inlong/manager/service/audit/InlongAuditSourceOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.manager.service.audit; | ||
|
||
/** | ||
* Interface of the inlong audit source operator. | ||
*/ | ||
public interface InlongAuditSourceOperator { | ||
|
||
/** | ||
* Determines whether the current instance matches the specified type. | ||
*/ | ||
Boolean accept(String type); | ||
|
||
/** | ||
* Get the Audit Source type. | ||
* | ||
* @return audit source type string | ||
*/ | ||
String getType(); | ||
|
||
/** | ||
* Convert the URL. | ||
* | ||
* @param url audit source url | ||
* @return converted url string | ||
*/ | ||
String convertTo(String url); | ||
} |
47 changes: 47 additions & 0 deletions
47
...c/main/java/org/apache/inlong/manager/service/audit/InlongAuditSourceOperatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.manager.service.audit; | ||
|
||
import org.apache.inlong.manager.common.enums.ErrorCodeEnum; | ||
import org.apache.inlong.manager.common.exceptions.BusinessException; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Factory for {@link InlongAuditSourceOperator}. | ||
*/ | ||
@Service | ||
public class InlongAuditSourceOperatorFactory { | ||
|
||
@Autowired | ||
private List<InlongAuditSourceOperator> auditSourceOperatorList; | ||
|
||
/** | ||
* Get an inlong Audit Source operator instance via the given type | ||
*/ | ||
public InlongAuditSourceOperator getInstance(String type) { | ||
return auditSourceOperatorList.stream() | ||
.filter(inst -> inst.accept(type)) | ||
.findFirst() | ||
.orElseThrow(() -> new BusinessException( | ||
String.format(ErrorCodeEnum.AUDIT_SOURCE_TYPE_NOT_SUPPORTED.getMessage(), type))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters