Skip to content

Commit

Permalink
Merge pull request #534 from Security-Onion-Solutions/2.4/addflag
Browse files Browse the repository at this point in the history
Add flags: timeout and delay-enrollment
  • Loading branch information
defensivedepth authored May 15, 2024
2 parents 1576356 + 337b112 commit f268c5a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions so-elastic-agent-builder/source/so-elastic-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var fleetHostURLsList = ""
var fleetHostFlag string

var enrollmentToken, enrollmentTokenFlag string
var delayEnrollFlag bool
var timeoutFlag time.Duration

func check(err error, context string) {
if err != nil {
Expand Down Expand Up @@ -93,6 +95,8 @@ func main() {
// Allow runtime configuration
flag.StringVar(&enrollmentTokenFlag, "token", "", "Override default Enrollment Token")
flag.StringVar(&fleetHostFlag, "fleet", "", "Override default Fleet Host")
flag.BoolVar(&delayEnrollFlag, "delay-enroll", false, "Add delay enroll flag")
flag.DurationVar(&timeoutFlag, "timeout", 5*time.Minute, "Set the timeout duration (default: 5 minutes)")
flag.Parse()

if enrollmentTokenFlag != "" {
Expand Down Expand Up @@ -184,13 +188,17 @@ func main() {
arg4 := "--certificate-authorities=" + installPath + "soca.crt"
arg5 := "-n"

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*3)
args := []string{arg1, arg2, arg3, arg4, arg5}
if delayEnrollFlag {
args = append(args, "--delay-enroll")
}

ctx, cancel := context.WithTimeout(context.Background(), timeoutFlag)
defer cancel()

cmd := exec.CommandContext(ctx, prg, arg1, arg2, arg3, arg4, arg5)
cmd := exec.CommandContext(ctx, prg, args...)

//strings.join the following
statusLogs("Executing the following: " + prg + " " + arg1 + " " + arg2 + " " + arg3 + " " + arg4 + " " + arg5)
statusLogs("Executing the following: " + prg + " " + strings.Join(args, " "))

output, err := cmd.CombinedOutput()
check(err, string(output))
Expand All @@ -199,5 +207,4 @@ func main() {

statusLogs("Elastic Agent installation completed")
fmt.Println("\n\nInstallation completed successfully.")

}

0 comments on commit f268c5a

Please sign in to comment.