ShouldReexecWithSudo checks if keploy should re-execute itself with sudo. Returns true if: 1. A Docker/Docker Compose command is detected in the -c/--command flag, OR 2. The "cloud replay" subcommand is being used (it generates a docker-compose internally) AND Keploy is NOT currently running as root
()
| 68 | // 2. The "cloud replay" subcommand is being used (it generates a docker-compose internally) |
| 69 | // AND Keploy is NOT currently running as root. |
| 70 | func ShouldReexecWithSudo() bool { |
| 71 | // Already running as root - no need to re-exec |
| 72 | if os.Geteuid() == 0 { |
| 73 | return false |
| 74 | } |
| 75 | |
| 76 | // Check if this is a "cloud replay" command, which always needs root |
| 77 | // because it generates and runs a docker-compose file internally. |
| 78 | if isCloudReplayCmd(os.Args) { |
| 79 | return true |
| 80 | } |
| 81 | |
| 82 | // Extract the command from arguments |
| 83 | cmd := ExtractCommandFromArgs(os.Args) |
| 84 | if cmd == "" { |
| 85 | return false |
| 86 | } |
| 87 | |
| 88 | // Check if it's a Docker command |
| 89 | cmdType := FindDockerCmd(cmd) |
| 90 | return IsDockerCmd(cmdType) |
| 91 | } |
| 92 | |
| 93 | // isCloudReplayCmd checks if the args represent the "keploy cloud replay" subcommand. |
| 94 | func isCloudReplayCmd(args []string) bool { |
nothing calls this directly
no test coverage detected