Skip to content

Commit

Permalink
implement recheck cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Aug 15, 2024
1 parent 1b40334 commit 4034422
Show file tree
Hide file tree
Showing 11 changed files with 1,041 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cmd/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ func runSubcommands(systemMultiSlogger *multislogger.MultiSlogger) error {
run = runSecureEnclave
case "watchdog": // note: this is currently only implemented for windows
run = watchdog.RunWatchdogService
case "recheck":
run = runRecheck
default:
return fmt.Errorf("unknown subcommand %s", os.Args[1])
}
Expand Down
45 changes: 45 additions & 0 deletions cmd/launcher/recheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"context"
"fmt"
"net/http"

"github.com/kolide/launcher/ee/agent/flags/keys"
"github.com/kolide/launcher/ee/agent/startupsettings"
"github.com/kolide/launcher/pkg/launcher"
"github.com/kolide/launcher/pkg/log/multislogger"
)

func runRecheck(_ *multislogger.MultiSlogger, _ []string) error {
attachConsole()
defer detachConsole()

settingReader, err := startupsettings.OpenReader(context.TODO(), launcher.DefaultPath(launcher.RootDirectory))
if err != nil {
return fmt.Errorf("opening startup settings reader to fetch desktop runner server url, is launcher daemon running?: %w", err)
}
defer settingReader.Close()

desktopRunnerServerURL, err := settingReader.Get(keys.DesktopRunnerServerUrl.String())
if err != nil {
return fmt.Errorf("getting desktop runner server url, is launcher daemon running?: %w", err)
}

response, err := http.Get(fmt.Sprintf("%s/recheck", desktopRunnerServerURL))
if err != nil {
return fmt.Errorf("sending recheck request to desktop runner server, is launcher daemon running?: %w", err)
}

if response.Body != nil {
defer response.Body.Close()
}

if response.StatusCode != http.StatusOK {
return fmt.Errorf("recheck request failed with status code %d", response.StatusCode)
}

fmt.Print("recheck request sent successfully")

return nil
}
7 changes: 7 additions & 0 deletions ee/agent/flags/flag_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,10 @@ func (fc *FlagController) LocalDevelopmentPath() string {
WithDefaultString(fc.cmdLineOpts.LocalDevelopmentPath),
).get(nil)
}

func (fc *FlagController) SetDesktopRunnerServerURL(url string) error {
return fc.setControlServerValue(keys.DesktopRunnerServerUrl, []byte(url))
}
func (fc *FlagController) DesktopRunnerServerURL() string {
return NewStringFlagValue().get(fc.getControlServerValue(keys.DesktopRunnerServerUrl))
}
1 change: 1 addition & 0 deletions ee/agent/flags/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
InModernStandby FlagKey = "in_modern_standby"
LocalDevelopmentPath FlagKey = "localdev_path"
LauncherWatchdogEnabled FlagKey = "launcher_watchdog_enabled" // note that this will only impact windows deployments for now
DesktopRunnerServerUrl FlagKey = "desktop_runner_server_url"
)

func (key FlagKey) String() string {
Expand Down
2 changes: 2 additions & 0 deletions ee/agent/startupsettings/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func (s *startupSettingsWriter) WriteSettings() error {
}
updatedFlags["use_tuf_autoupdater"] = "enabled" // Hardcode for backwards compatibility circa v1.5.3

updatedFlags[keys.DesktopRunnerServerUrl.String()] = s.knapsack.DesktopRunnerServerURL()

atcConfig, err := s.extractAutoTableConstructionConfig()
if err != nil {
s.knapsack.Slogger().Log(context.TODO(), slog.LevelDebug,
Expand Down
4 changes: 4 additions & 0 deletions ee/agent/types/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,8 @@ type Flags interface {
// LauncherWatchdogEnabled controls whether launcher installs/runs, or stops/removes the launcher watchdog service
SetLauncherWatchdogEnabled(enabled bool) error
LauncherWatchdogEnabled() bool

// DesktopRunnerServerURL is the URL of the desktop runner server
SetDesktopRunnerServerURL(url string) error
DesktopRunnerServerURL() string
}
Loading

0 comments on commit 4034422

Please sign in to comment.