Skip to content

Commit

Permalink
Fix mongodb database write prohibition plugin bug
Browse files Browse the repository at this point in the history
Signed-off-by: daizhenyu <[email protected]>
  • Loading branch information
daizhenyu committed Mar 6, 2024
1 parent 340cb3b commit 5d26305
Show file tree
Hide file tree
Showing 32 changed files with 1,229 additions and 443 deletions.
17 changes: 16 additions & 1 deletion report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,22 @@
</dependency>
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>mongodb-3.x-4.x-plugin</artifactId>
<artifactId>mongodb-3.x-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>mongodb-4.x-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>mysql-mariadb-2.x-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>mysql-mariadb-3.x-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,19 @@ protected void handleWriteOperationIfWriteDisabled(String sql, String databaseNa
DatabaseController.disableDatabaseWriteOperation(databaseName, context);
}
}

/**
* If the mongodb database has write prohibition enabled and it is a write operation, the write prohibition logic
* will be executed
*
* @param databaseName databaseName
* @param prohibitionDatabases prohibition write database collection
* @param context contextual information
*/
protected void handleWriteOperationIfWriteDisabled(String databaseName,
Set<String> prohibitionDatabases, ExecuteContext context) {
if (prohibitionDatabases.contains(databaseName)) {
DatabaseController.disableDatabaseWriteOperation(databaseName, context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
* limitations under the License.
*/

package com.huaweicloud.sermant.mongodb.interceptors;
package com.huaweicloud.sermant.database.interceptor;

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.database.config.DatabaseWriteProhibitionManager;
import com.huaweicloud.sermant.database.controller.DatabaseController;
import com.huaweicloud.sermant.database.interceptor.AbstractDatabaseInterceptor;

/**
* mongodb抽象interceptor
* MongoDB Abstract Interceptor
*
* @author daizhenyu
* @since 2024-02-02
Expand All @@ -31,9 +29,8 @@ public abstract class AbstractMongoDbInterceptor extends AbstractDatabaseInterce
@Override
public ExecuteContext doBefore(ExecuteContext context) {
String database = getDataBaseInfo(context).getDatabaseName();
if (DatabaseWriteProhibitionManager.getMongoDbProhibitionDatabases().contains(database)) {
DatabaseController.disableDatabaseWriteOperation(database, context);
}
handleWriteOperationIfWriteDisabled(database,
DatabaseWriteProhibitionManager.getMongoDbProhibitionDatabases(), context);
return context;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>sermant-database-write-prohibition</artifactId>
<groupId>com.huaweicloud.sermant</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>mongodb-3.x-plugin</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<config.skip.flag>false</config.skip.flag>
<package.plugin.type>plugin</package.plugin.type>
<mongodb.version>3.7.0</mongodb.version>
</properties>

<dependencies>
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>sermant-agentcore-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>${mongodb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>database-controller</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit 5d26305

Please sign in to comment.