Skip to content

Commit

Permalink
fix: fix no output returns + functionality to strip content
Browse files Browse the repository at this point in the history
  • Loading branch information
furan917 committed Oct 9, 2023
1 parent f8e3454 commit 869942f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config_manager/magerun_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func IsMageRunCommandAllowed(command string) bool {
}
}
// print allowed commands
logger.Fatalf("`%s` Command not allowed, allowed commands are:\n%s \n", command, strings.Join(allowedCommands, ",\n"))
logger.Errorf("`%s` Command not allowed, allowed commands are:\n%s \n", command, strings.Join(allowedCommands, ",\n"))
return false
}

Expand Down
18 changes: 17 additions & 1 deletion magerun/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"magecomm/logger"
"magecomm/notifictions"
"os/exec"
"regexp"
"strings"
)

Expand Down Expand Up @@ -63,11 +64,26 @@ func executeMagerunCommand(args []string) (string, error) {
stdoutStr := stdoutBuffer.String()
stderrStr := stderrBuffer.String()

output := stdoutStr + "\n" + stderrStr
output := stripMagerunOutput(stdoutStr + "\n" + stderrStr)

return output, nil
}

func stripMagerunOutput(output string) string {
patterns := map[string]string{
`(?i)(?:it's|it is) not recommended to run .*? as root user`: "",
//Add more regex patterns here with their corresponding replacement
}

strippedOutput := output
for pattern, replacement := range patterns {
re := regexp.MustCompile(pattern)
strippedOutput = re.ReplaceAllString(strippedOutput, replacement)
}

return strippedOutput
}

func getMageRunCommand() string {
configuredMageRunCmd := config_manager.GetValue(config_manager.CommandConfigMageRunCommandPath)
if configuredMageRunCmd == "" {
Expand Down
6 changes: 6 additions & 0 deletions messages/handler/magerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func (handler *MagerunHandler) ProcessMessage(messageBody string, correlationID
if err != nil {
output = output + err.Error()
}
output = strings.TrimSpace(output)

//if output is empty return "command finished with no out
if output == "" {
output = "Command finished with no output"
}

if config_manager.GetBoolValue(config_manager.ConfigSlackEnabled) && !config_manager.GetBoolValue(config_manager.ConfigSlackDisableOutputNotifications) {
logger.Infof("Slack notification is enabled, sending output notification")
Expand Down

0 comments on commit 869942f

Please sign in to comment.