fleet/ee/maintained-apps/maintained_apps.go
Jahziel Villasana-Espinoza db5444d6cd
software categories: backend (#28479)
> For #28138 

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [x] Added/updated automated tests
- [x] A detailed QA plan exists on the associated ticket (if it isn't
there, work with the product group's QA engineer to add it)
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Ian Littman <iansltx@gmail.com>
2025-05-02 11:41:26 -04:00

89 lines
2.4 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"`
}
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]
}