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

addes non prod icon and debug menu #884

Merged
merged 5 commits into from
Sep 13, 2022
Merged
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
24 changes: 24 additions & 0 deletions cmd/launcher/desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package desktop

import (
"context"
"flag"
"fmt"
"os"
"os/signal"
Expand All @@ -18,12 +19,35 @@ func RunDesktop(args []string) error {
go exitWhenParentGone()
go handleSignals()

flagset := flag.NewFlagSet("launcher desktop", flag.ExitOnError)
var (
flhostname = flagset.String(
"hostname",
"",
"hostname launcher is connected to",
)
)
if err := flagset.Parse(args); err != nil {
return err
}

onReady := func() {
systray.SetTemplateIcon(kolideDesktopIcon, kolideDesktopIcon)
systray.SetTooltip("Kolide")

versionItem := systray.AddMenuItem(fmt.Sprintf("Version %s", version.Version().Version), "")
versionItem.Disable()

// if prod environment, return
if *flhostname == "k2device-preprod.kolide.com" || *flhostname == "k2device.kolide.com" {
return
}

// in non prod environment
systray.SetTemplateIcon(kolideDesktopIconNonProd, kolideDesktopIconNonProd)
systray.AddSeparator()
systray.AddMenuItem("--- DEBUG ---", "").Disable()
systray.AddMenuItem(fmt.Sprintf("Hostname: %s", *flhostname), "").Disable()
}

systray.Run(onReady, func() {})
Expand Down
9 changes: 7 additions & 2 deletions cmd/launcher/desktop/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ import (
_ "embed"
)

//go:embed kolide-mark-only-white.png
var kolideDesktopIcon []byte
var (
//go:embed kolide-prod-icon.png
kolideDesktopIcon []byte

//go:embed kolide-non-prod-icon.png
kolideDesktopIconNonProd []byte
)
9 changes: 7 additions & 2 deletions cmd/launcher/desktop/icon_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ import (
_ "embed"
)

//go:embed kolide-mark-only-purple-16x-32x.ico
var kolideDesktopIcon []byte
var (
//go:embed kolide-windows-prod-icon.ico
kolideDesktopIcon []byte

//go:embed kolide-windows-non-prod-icon.ico
kolideDesktopIconNonProd []byte
)
Binary file added cmd/launcher/desktop/kolide-non-prod-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 2 additions & 2 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
}

var desktopRunner *desktopRuntime.DesktopUsersProcessesRunner
if (opts.KolideServerURL == "k2device-preprod.kolide.com" || opts.KolideServerURL == "localhost:3443") && runtime.GOOS == "darwin" {
desktopRunner = desktopRuntime.New(logger, time.Second*5)
if (opts.KolideServerURL == "k2device-preprod.kolide.com" || opts.KolideServerURL == "localhost:3443") && runtime.GOOS != "linux" {
desktopRunner = desktopRuntime.New(logger, time.Second*5, opts.KolideServerURL)
runGroup.Add(desktopRunner.Execute, desktopRunner.Interrupt)
}

Expand Down
6 changes: 5 additions & 1 deletion ee/desktop/runtime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type DesktopUsersProcessesRunner struct {
// due to needing to build the binary to test as a result of some test harness weirdness.
// See runner_test.go for more details.
executablePath string
// hostname is the host that launcher is connecting to. It gets passed to the desktop process
// and is used to determine which icon to display
hostname string
}

// addProcessForUser adds process information to the internal tracking state
Expand Down Expand Up @@ -64,14 +67,15 @@ type processRecord struct {
}

// New creates and returns a new DesktopUsersProcessesRunner runner and initializes all required fields
func New(logger log.Logger, executionInterval time.Duration) *DesktopUsersProcessesRunner {
func New(logger log.Logger, executionInterval time.Duration, hostname string) *DesktopUsersProcessesRunner {
return &DesktopUsersProcessesRunner{
logger: logger,
interrupt: make(chan struct{}),
uidProcs: make(map[string]processRecord),
executionInterval: executionInterval,
procsWg: &sync.WaitGroup{},
procsWgTimeout: time.Second * 5,
hostname: hostname,
}
}

Expand Down
2 changes: 1 addition & 1 deletion ee/desktop/runtime/runner_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *DesktopUsersProcessesRunner) runConsoleUserDesktop() error {
return fmt.Errorf("determining executable path: %w", err)
}

proc, err := runAsUser(uid, executablePath, "desktop")
proc, err := runAsUser(uid, executablePath, "desktop", "--hostname", r.hostname)
if err != nil {
return fmt.Errorf("running desktop: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion ee/desktop/runtime/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestDesktopUserProcessRunner_Execute(t *testing.T) {

var logBytes threadSafeBuffer

r := New(log.NewLogfmtLogger(&logBytes), time.Second*1)
r := New(log.NewLogfmtLogger(&logBytes), time.Second*1, "some-where-over-the-rainbow.example.com")
r.executablePath = executablePath

if tt.setup != nil {
Expand Down
2 changes: 1 addition & 1 deletion ee/desktop/runtime/runner_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *DesktopUsersProcessesRunner) runConsoleUserDesktop() error {
}
defer accessToken.Close()

proc, err := runWithAccessToken(accessToken, executablePath, "desktop")
proc, err := runWithAccessToken(accessToken, executablePath, "desktop", "--hostname", r.hostname)
if err != nil {
return fmt.Errorf("running desktop: %w", err)
}
Expand Down