Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(cli): filter out dynamically generated request ID

Daniel Hougaardcfc0ca1f0389
diff --git a/cli/test/helper.go b/cli/test/helper.go
index 819f4c4c9d..14e6f6b786 100644
--- a/cli/test/helper.go
+++ b/cli/test/helper.go
@@ -1,6 +1,7 @@
package tests
import (
+ "encoding/json"
"fmt"
"log"
"os"
@@ -43,9 +44,9 @@ func ExecuteCliCommand(command string, args ...string) (string, error) {
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + string(output))
- return strings.TrimSpace(string(output)), err
+ return FilterRequestID(strings.TrimSpace(string(output))), err
}
- return strings.TrimSpace(string(output)), nil
+ return FilterRequestID(strings.TrimSpace(string(output))), nil
}
func SetupCli() {
@@ -67,3 +68,39 @@ func SetupCli() {
}
}
+
+func FilterRequestID(input string) string {
+
+ if !strings.Contains(input, "requestId") && strings.Contains(input, "reqId") {
+ return input
+ }
+
+ // Find the JSON part of the error message
+ start := strings.Index(input, "{")
+ end := strings.LastIndex(input, "}") + 1
+
+ if start == -1 || end == -1 {
+ return input
+ }
+
+ jsonPart := input[:start] // Pre-JSON content
+
+ // Parse the JSON object
+ var errorObj map[string]interface{}
+ if err := json.Unmarshal([]byte(input[start:end]), &errorObj); err != nil {
+ return input
+ }
+
+ // Remove requestId field
+ delete(errorObj, "requestId")
+ delete(errorObj, "reqId")
+
+ // Convert back to JSON
+ filtered, err := json.Marshal(errorObj)
+ if err != nil {
+ return input
+ }
+
+ // Reconstruct the full string
+ return jsonPart + string(filtered) + input[end:]
+}