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

added download info to flare #1878

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions ee/debug/checkups/checkups.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func checkupsFor(k types.Knapsack, target targetBits) []checkupInt {
{&uninstallHistoryCheckup{k: k}, flareSupported},
{&desktopMenu{k: k}, flareSupported},
{&coredumpCheckup{}, doctorSupported | flareSupported},
{&DownloadDirectory{}, flareSupported},
}

checkupsToRun := make([]checkupInt, 0)
Expand Down
117 changes: 117 additions & 0 deletions ee/debug/checkups/download_directory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package checkups

import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"strings"
)

type DownloadDirectory struct {
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
status Status
summary string
files []string
}

func (c *DownloadDirectory) Name() string {
return "Download directory contents"
}

func (c *DownloadDirectory) Run(_ context.Context, extraFH io.Writer) error {
downloadDir := getDownloadDir()
if downloadDir == "" {
return fmt.Errorf("no default download directory")
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
}

err := filepath.Walk(downloadDir, func(path string, info os.FileInfo, err error) error {
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
return err
}
if !info.IsDir() && isKolideInstaller(info.Name()) {
c.files = append(c.files, path)
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
})

switch {
case os.IsNotExist(err):
c.status = Warning
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
c.summary = fmt.Sprintf("download directory (%s) not present", downloadDir)
case err != nil:
c.status = Erroring
c.summary = fmt.Sprintf("error listing files in directory (%s): %s", downloadDir, err)
case len(c.files) == 0:
c.status = Warning
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
c.summary = fmt.Sprintf("no Kolide installers found in directory (%s)", downloadDir)
default:
c.status = Passing
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
fileNames := make([]string, len(c.files))
for i, file := range c.files {
fileNames[i] = filepath.Base(file)
}
installerList := strings.Join(fileNames, ", ")
c.summary = fmt.Sprintf("Found Kolide installer(s) in directory (%s): %s", downloadDir, installerList)

}

if len(c.files) > 0 {
fmt.Fprintln(extraFH, "Kolide installers found:")
for _, file := range c.files {
fmt.Fprintln(extraFH, file)
}
}

return nil
}

func (c *DownloadDirectory) ExtraFileName() string {
return "kolide-installers"
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *DownloadDirectory) Status() Status {
return c.status
}

func (c *DownloadDirectory) Summary() string {
return c.summary
}

func (c *DownloadDirectory) Data() any {
return c.files
}

func getDownloadDir() string {
homeDir, err := os.UserHomeDir()
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return ""
}

switch runtime.GOOS {
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
case "darwin":
return filepath.Join(homeDir, "Downloads")
case "linux":
return filepath.Join(homeDir, "Downloads")
case "windows":
return filepath.Join(homeDir, "Downloads")
}

return ""
}

func isKolideInstaller(filename string) bool {
lowerFilename := strings.ToLower(filename)
switch runtime.GOOS {
case "darwin":
return strings.HasSuffix(lowerFilename, "kolide-launcher.pkg")
cesarfda marked this conversation as resolved.
Show resolved Hide resolved
case "linux":
return strings.HasSuffix(lowerFilename, "kolide-launcher.rpm") ||
strings.HasSuffix(lowerFilename, "kolide-launcher.deb") ||
strings.HasSuffix(lowerFilename, "kolide-launcher.pacman")
case "windows":
return strings.HasSuffix(lowerFilename, "kolide-launcher.msi")
}
return false
}
Loading