Refactor Nomad Command Generation.
- Abstracting from the exec form while generating. - Removal of single quotes (usage of only double-quotes). - Bash-nesting using escaping of special characters.
This commit is contained in:

committed by
Sebastian Serth

parent
f309d0f70e
commit
7dadc5dfe9
@@ -4,23 +4,23 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
"io"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// timeDebugMessageFormat is the format of messages that will be converted to debug messages.
|
||||
// Format Parameters: 1. Debug Comment, 2. command.
|
||||
timeDebugMessageFormatStart = `echo -ne "\x1EPoseidon %s $(date +%%s%%3N)\x1E"; %s`
|
||||
// Format Parameters: 1. command, 2. Debug Comment.
|
||||
timeDebugMessageFormatEnd = `%s; bash -c "ec=$?; echo -ne \"\\x1EPoseidon %s \$(date +%%s%%3N)\\x1E\" && exit \$ec"`
|
||||
)
|
||||
|
||||
var (
|
||||
timeDebugMessagePattern = regexp.
|
||||
MustCompile(`(?P<before>.*)\x1EPoseidon (?P<text>.+) (?P<time>\d{13})\x1E(?P<after>.*)`)
|
||||
// timeDebugMessageFormat is the format of messages that will be converted to debug messages.
|
||||
timeDebugMessageFormat = `echo -ne "\x1EPoseidon %s $(date +%%s%%3N)\x1E"`
|
||||
// Format Parameters: 1. Debug Comment, 2. command.
|
||||
timeDebugMessageFormatStart = timeDebugMessageFormat + `; %s`
|
||||
// Format Parameters: 1. command, 2. Debug Comment.
|
||||
timeDebugMessageFormatEnd = `%s; ` + dto.WrapBashCommand(`ec=$?; `+timeDebugMessageFormat+` && exit $ec`)
|
||||
|
||||
timeDebugMessagePattern = regexp.MustCompile(
|
||||
`(?P<before>.*)\x1EPoseidon (?P<text>.+) (?P<time>\d{13})\x1E(?P<after>.*)`)
|
||||
timeDebugMessagePatternStart = regexp.MustCompile(`\x1EPoseidon`)
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user