Skip to content

Commit 24901c9

Browse files
author
gitlab
committed
Merge branch 'c-0' into 'feature-zsv-5.0.0-vm-support-vtpm-and-secuceboot'
<feature>[log]: add LongText type for logging long content safely See merge request zstackio/zstack!9528
2 parents 4db6aab + 2d3633c commit 24901c9

5 files changed

Lines changed: 17 additions & 2 deletions

File tree

core/src/main/java/org/zstack/core/log/LogSafeGson.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ String getMaskedValue(String raw) {
9999
return "*****";
100100
} else if (annotation.type().tag()) {
101101
return tagInfoHider.call(raw);
102+
} else if (annotation.type().longText()) {
103+
if (raw == null)
104+
return null;
105+
return (raw.length() < 20) ? raw : raw.substring(0, 10) + "..." + raw.substring(raw.length() - 10);
102106
} else {
103107
return Utils.getLogMaskWords().getOrDefault(raw, uriPattern.matcher(raw).replaceFirst(":*****@"));
104108
}

header/src/main/java/org/zstack/header/log/NoLogging.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public boolean mask() {
2626
enum Type {
2727
Simple,
2828
Tag,
29-
Uri;
29+
Uri,
30+
LongText,
31+
;
3032

3133
public boolean simple() {
3234
return this == Simple;
@@ -39,6 +41,10 @@ public boolean tag() {
3941
public boolean uri() {
4042
return this == Uri;
4143
}
44+
45+
public boolean longText() {
46+
return this == LongText;
47+
}
4248
}
4349

4450
Behavior behavior() default Behavior.Mask;

header/src/main/java/org/zstack/header/vm/APITakeVmConsoleScreenshotEvent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.zstack.header.vm;
22

3+
import org.zstack.header.log.NoLogging;
34
import org.zstack.header.message.APIEvent;
45
import org.zstack.header.rest.RestResponse;
56

@@ -9,6 +10,7 @@
910
*/
1011
@RestResponse(fieldsTo = {"imageData"})
1112
public class APITakeVmConsoleScreenshotEvent extends APIEvent {
13+
@NoLogging(type = NoLogging.Type.LongText)
1214
private String imageData;
1315

1416
public APITakeVmConsoleScreenshotEvent() {

header/src/main/java/org/zstack/header/vm/TakeVmConsoleScreenshotReply.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package org.zstack.header.vm;
22

3+
import org.zstack.header.log.NoLogging;
34
import org.zstack.header.message.MessageReply;
45

56
/**
67
* @author shanshan.ning
78
* @date 2023-09-11
89
*/
910
public class TakeVmConsoleScreenshotReply extends MessageReply {
11+
@NoLogging(type = NoLogging.Type.LongText)
1012
private String imageData;
1113

1214
public String getImageData() {

plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2844,7 +2844,7 @@ public static class VmHostFileTO {
28442844
/**
28452845
* null if operation is Prepare or Delete
28462846
*/
2847-
@NoLogging
2847+
@NoLogging(type = NoLogging.Type.LongText)
28482848
private String contentBase64;
28492849
private String error;
28502850

@@ -4760,6 +4760,7 @@ public void setVmUuid(String vmUuid) {
47604760
}
47614761

47624762
public static class TakeVmConsoleScreenshotRsp extends AgentResponse {
4763+
@NoLogging(type = NoLogging.Type.LongText)
47634764
private String imageData;
47644765

47654766
public String getImageData() {

0 commit comments

Comments
 (0)