Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement recheck cmd #1837

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Comment on lines +15 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think this is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the attach/detach command whenever it's a command that a Windows user could be running from the command line, so I think we'd want it here?


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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing this through a flag feels a little weird to me. Might be right though... Why go this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does feel weird. I just followed the pattern used to store other data in the sqlite db via the start up settings writer. Perhaps we should create a new table / store in the sqlite db ... runtime_values or something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like runtime_values

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
7 changes: 4 additions & 3 deletions ee/agent/startupsettings/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ func OpenWriter(ctx context.Context, knapsack types.Knapsack) (*startupSettingsW
kvStore: store,
knapsack: knapsack,
storedFlags: map[keys.FlagKey]func() string{
keys.UpdateChannel: func() string { return knapsack.UpdateChannel() },
keys.PinnedLauncherVersion: func() string { return knapsack.PinnedLauncherVersion() },
keys.PinnedOsquerydVersion: func() string { return knapsack.PinnedOsquerydVersion() },
keys.UpdateChannel: func() string { return knapsack.UpdateChannel() },
keys.PinnedLauncherVersion: func() string { return knapsack.PinnedLauncherVersion() },
keys.PinnedOsquerydVersion: func() string { return knapsack.PinnedOsquerydVersion() },
keys.DesktopRunnerServerUrl: func() string { return knapsack.DesktopRunnerServerURL() },
},
}

Expand Down
9 changes: 9 additions & 0 deletions ee/agent/startupsettings/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestOpenWriter_NewDatabase(t *testing.T) {
k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel)
k.On("RegisterChangeObserver", mock.Anything, keys.PinnedLauncherVersion)
k.On("RegisterChangeObserver", mock.Anything, keys.PinnedOsquerydVersion)
k.On("RegisterChangeObserver", mock.Anything, keys.DesktopRunnerServerUrl)
updateChannelVal := "stable"
k.On("UpdateChannel").Return(updateChannelVal)
k.On("PinnedLauncherVersion").Return("")
Expand All @@ -36,6 +37,8 @@ func TestOpenWriter_NewDatabase(t *testing.T) {
k.On("Slogger").Return(multislogger.NewNopLogger())
k.On("KatcConfigStore").Return(inmemory.NewStore())

k.On("DesktopRunnerServerURL").Return(ulid.New())

// Set up storage db, which should create the database and set all flags
s, err := OpenWriter(context.TODO(), k)
require.NoError(t, err, "expected no error setting up storage db")
Expand Down Expand Up @@ -87,6 +90,7 @@ func TestOpenWriter_DatabaseAlreadyExists(t *testing.T) {
k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel)
k.On("RegisterChangeObserver", mock.Anything, keys.PinnedLauncherVersion)
k.On("RegisterChangeObserver", mock.Anything, keys.PinnedOsquerydVersion)
k.On("RegisterChangeObserver", mock.Anything, keys.DesktopRunnerServerUrl)

// Set up flag
updateChannelVal := "alpha"
Expand All @@ -99,6 +103,8 @@ func TestOpenWriter_DatabaseAlreadyExists(t *testing.T) {
k.On("ConfigStore").Return(inmemory.NewStore())
k.On("Slogger").Return(multislogger.NewNopLogger())

k.On("DesktopRunnerServerURL").Return(ulid.New())

// Set up storage db, which should create the database and set all flags
s, err := OpenWriter(context.TODO(), k)
require.NoError(t, err, "expected no error setting up storage db")
Expand Down Expand Up @@ -132,13 +138,16 @@ func TestFlagsChanged(t *testing.T) {
k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel)
k.On("RegisterChangeObserver", mock.Anything, keys.PinnedLauncherVersion)
k.On("RegisterChangeObserver", mock.Anything, keys.PinnedOsquerydVersion)
k.On("RegisterChangeObserver", mock.Anything, keys.DesktopRunnerServerUrl)
updateChannelVal := "beta"
k.On("UpdateChannel").Return(updateChannelVal).Once()
pinnedLauncherVersion := "1.2.3"
k.On("PinnedLauncherVersion").Return(pinnedLauncherVersion).Once()
pinnedOsquerydVersion := "5.3.2"
k.On("PinnedOsquerydVersion").Return(pinnedOsquerydVersion).Once()

k.On("DesktopRunnerServerURL").Return(ulid.New())

autoTableConstructionValue := ulid.New()

configStore := inmemory.NewStore()
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
Loading