mirror of
https://github.com/Infisical/infisical.git
synced 2025-03-25 14:05:03 +00:00
fix(cli): filter out dynamically generated request ID
This commit is contained in:
@ -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:]
|
||||
}
|
||||
|
Reference in New Issue
Block a user