Exemple #1
0
// fileContains checks whether a file matches a given regex
func fileContains(parameters []string) (exitCode int, exitMessage string) {
	path := parameters[0]
	regex := wrkutils.ParseUserRegex(parameters[1])
	if regex.Match(wrkutils.FileToBytes(path)) {
		return 0, ""
	}
	msg := "File does not match regexp:\n\tFile: "
	return 1, msg + path + "\n\tRegexp" + regex.String()
}
Exemple #2
0
// responseMatchesGeneral is an abstraction of responseMatches and
// responseMatchesInsecure that simply varies in the security of the connection
func responseMatchesGeneral(parameters []string, secure bool) (exitCode int, exitMessage string) {
	urlstr := parameters[0]
	re := wrkutils.ParseUserRegex(parameters[1])
	body := wrkutils.URLToBytes(urlstr, secure)
	if re.Match(body) {
		return 0, ""
	}
	msg := "Response didn't match regexp"
	return wrkutils.GenericError(msg, re.String(), []string{string(body)})
}
Exemple #3
0
// commandOutputMatches checks to see if a command's combined output matches a
// given regexp
func commandOutputMatches(parameters []string) (exitCode int, exitMessage string) {
	toExec := parameters[0]
	re := wrkutils.ParseUserRegex(parameters[1])
	cmd := exec.Command("bash", "-c", toExec)
	out, err := cmd.CombinedOutput()
	if err != nil {
		wrkutils.ExecError(cmd, string(out), err)
	}
	if re.Match(out) {
		return 0, ""
	}
	msg := "Command output did not match regexp"
	return wrkutils.GenericError(msg, re.String(), []string{string(out)})
}
Exemple #4
0
// repoExistsURI checks to see if the repo with the given URI is listed in the
// appropriate configuration file
func repoExistsURI(parameters []string) (exitCode int, exitMessage string) {
	re := wrkutils.ParseUserRegex(parameters[1])
	return existsRepoWithProperty("URL", re, parameters[0])
}