-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support local desensitization (#277)
- Loading branch information
Showing
8 changed files
with
124 additions
and
115 deletions.
There are no files selected for viewing
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
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
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
65 changes: 0 additions & 65 deletions
65
...b-api/src/main/java/com/arextest/storage/repository/impl/mongo/DesensitizationLoader.java
This file was deleted.
Oops, something went wrong.
53 changes: 32 additions & 21 deletions
53
...com/arextest/storage/repository/impl/mongo/converters/ArexMockerCompressionConverter.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 |
---|---|---|
@@ -1,51 +1,62 @@ | ||
package com.arextest.storage.repository.impl.mongo.converters; | ||
|
||
import com.arextest.common.utils.SerializationUtils; | ||
import com.arextest.extension.desensitization.DataDesensitization; | ||
import com.arextest.model.mock.Mocker.Target; | ||
import com.arextest.storage.repository.impl.mongo.DesensitizationLoader; | ||
import com.mongodb.lang.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.data.convert.ReadingConverter; | ||
import org.springframework.data.convert.WritingConverter; | ||
|
||
@Slf4j | ||
public class ArexMockerCompressionConverter { | ||
private static Target read(String source) { | ||
String encodeWithDecryptString = null; | ||
try { | ||
encodeWithDecryptString = DesensitizationLoader.DESENSITIZATION_SERVICE.decrypt(source); | ||
} catch (Exception e) { | ||
LOGGER.error("Data decrypt failed", e); | ||
} | ||
return SerializationUtils.useZstdDeserialize(encodeWithDecryptString, Target.class); | ||
} | ||
|
||
private static String write(Target source) { | ||
String base64Result = SerializationUtils.useZstdSerializeToBase64(source); | ||
try { | ||
base64Result = DesensitizationLoader.DESENSITIZATION_SERVICE.encrypt(base64Result); | ||
return base64Result; | ||
} catch (Exception e) { | ||
LOGGER.error("Data encrypt failed", e); | ||
} | ||
return base64Result; | ||
} | ||
|
||
@ReadingConverter | ||
@RequiredArgsConstructor | ||
public static class Read implements Converter<String, Target> { | ||
|
||
private final DataDesensitization dataDesensitization; | ||
|
||
@Override | ||
public Target convert(@NonNull String source) { | ||
return read(source); | ||
} | ||
|
||
private Target read(String source) { | ||
String encodeWithDecryptString = null; | ||
try { | ||
encodeWithDecryptString = dataDesensitization.decrypt(source); | ||
} catch (Exception e) { | ||
LOGGER.error("Data decrypt failed", e); | ||
} | ||
return SerializationUtils.useZstdDeserialize(encodeWithDecryptString, Target.class); | ||
} | ||
} | ||
|
||
@WritingConverter | ||
@RequiredArgsConstructor | ||
public static class Write implements Converter<Target, String> { | ||
|
||
private final DataDesensitization dataDesensitization; | ||
|
||
@Override | ||
public String convert(@NonNull Target source) { | ||
return write(source); | ||
} | ||
|
||
private String write(Target source) { | ||
String base64Result = SerializationUtils.useZstdSerializeToBase64(source); | ||
try { | ||
base64Result = dataDesensitization.encrypt(base64Result); | ||
return base64Result; | ||
} catch (Exception e) { | ||
LOGGER.error("Data encrypt failed", e); | ||
} | ||
return base64Result; | ||
} | ||
|
||
} | ||
|
||
} |
28 changes: 12 additions & 16 deletions
28
...va/com/arextest/storage/service/handler/mocker/coverage/DefaultCoverageEventListener.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 |
---|---|---|
@@ -1,30 +1,26 @@ | ||
package com.arextest.storage.service.handler.mocker.coverage; | ||
|
||
import com.arextest.model.mock.Mocker; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author: QizhengMo | ||
* @date: 2024/9/18 19:00 | ||
*/ | ||
@Service | ||
@ConditionalOnMissingBean(CoverageEventListener.class) | ||
public class DefaultCoverageEventListener implements CoverageEventListener { | ||
|
||
@Override | ||
public void onBeforeNewCaseRecord(Mocker coverageMocker) { | ||
} | ||
@Override | ||
public void onBeforeNewCaseRecord(Mocker coverageMocker) { | ||
} | ||
|
||
@Override | ||
public void onNewCaseRecorded(Mocker coverageMocker) { | ||
} | ||
@Override | ||
public void onNewCaseRecorded(Mocker coverageMocker) { | ||
} | ||
|
||
@Override | ||
public void onBeforeExistingCaseRecord(Mocker coverageMocker) { | ||
} | ||
@Override | ||
public void onBeforeExistingCaseRecord(Mocker coverageMocker) { | ||
} | ||
|
||
@Override | ||
public void onExistingCaseRecorded(Mocker coverageMocker) { | ||
} | ||
@Override | ||
public void onExistingCaseRecorded(Mocker coverageMocker) { | ||
} | ||
} |
Binary file added
BIN
+49.3 KB
arex-storage-web-api/src/main/resources/lib/arex-extension-desensitization.jar
Binary file not shown.
Oops, something went wrong.