fleet/ee/maintained-apps/maintained_apps.go
jacobshandling 3ca1ff4754
Detect UpgradeCodes when adding Windows FMA software, and persist them when the user adds that software; Fix recently introduced issue with list host software (#35876)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #35724 

- Fixes issues 1 and 2 of the referenced bug ticket
- Also fixes [this
issue](https://github.com/fleetdm/fleet/pull/35739/files#r2548349172)

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:
- [x] Alerted the release DRI if additional load testing is needed

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added upgrade code support to Windows maintained applications for
improved MSI installer tracking and management.

* **Documentation**
* Updated Windows onboarding instructions with more precise manifest
path guidance and concrete command examples for the maintained-apps
generator.

* **Tests**
* Added comprehensive test coverage for upgrade code association with
maintained applications.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-26 17:00:03 -08:00

91 lines
2.5 KiB
Go

package maintained_apps
import (
"context"
"crypto/sha256"
"encoding/hex"
"io"
"strings"
kitlog "github.com/go-kit/log"
)
// Ingester is responsible for ingesting the metadata for maintained apps for a given platform.
// Each platform may have multiple sources for metadata (e.g. homebrew and autopkg for macOS). Each
// source must have its own Ingester implementation.
type Ingester func(ctx context.Context, logger kitlog.Logger, inputsPath string, slugFilter string) ([]*FMAManifestApp, error)
const OutputPath = "ee/maintained-apps/outputs"
type FMAQueries struct {
Exists string `json:"exists"`
}
type FMAManifestApp struct {
Version string `json:"version"`
Queries FMAQueries `json:"queries"`
InstallerURL string `json:"installer_url"`
UniqueIdentifier string `json:"unique_identifier,omitempty"`
InstallScriptRef string `json:"install_script_ref"`
UninstallScriptRef string `json:"uninstall_script_ref"`
InstallScript string `json:"-"`
UninstallScript string `json:"-"`
SHA256 string `json:"sha256"`
Slug string `json:"-"`
Name string `json:"-"`
DefaultCategories []string `json:"default_categories"`
Frozen bool `json:"-"`
UpgradeCode string `json:"upgrade_code,omitempty"`
}
func (a *FMAManifestApp) Platform() string {
parts := strings.Split(a.Slug, "/")
if len(parts) != 2 {
return ""
}
return parts[1]
}
func (a *FMAManifestApp) SlugAppName() string {
parts := strings.Split(a.Slug, "/")
if len(parts) != 2 {
return ""
}
return parts[0]
}
func (a *FMAManifestApp) IsEmpty() bool {
return a.Version == "" &&
a.InstallerURL == "" &&
a.UniqueIdentifier == "" &&
a.InstallScriptRef == "" &&
a.UninstallScriptRef == "" &&
a.SHA256 == "" &&
a.Queries == (FMAQueries{})
}
type FMAManifestFile struct {
Versions []*FMAManifestApp `json:"versions"`
Refs map[string]string `json:"refs"`
}
type FMAListFileApp struct {
Name string `json:"name"`
Slug string `json:"slug"`
Platform string `json:"platform"`
UniqueIdentifier string `json:"unique_identifier"`
Description string `json:"description"`
}
type FMAListFile struct {
Version int `json:"version"`
Apps []FMAListFileApp `json:"apps"`
}
func GetScriptRef(script string) string {
h := sha256.New()
_, _ = io.Copy(h, strings.NewReader(script)) // writes to a Hash can never fail
return hex.EncodeToString(h.Sum(nil))[:8]
}