2024-09-18 16:21:53 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-09-19 19:42:17 +00:00
|
|
|
"errors"
|
2024-09-18 16:21:53 +00:00
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2024-09-19 19:42:17 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/mdm/maintainedapps"
|
2024-09-18 16:21:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type addFleetMaintainedAppRequest struct {
|
2024-12-17 00:17:13 +00:00
|
|
|
TeamID *uint `json:"team_id"`
|
|
|
|
|
AppID uint `json:"fleet_maintained_app_id"`
|
|
|
|
|
InstallScript string `json:"install_script"`
|
|
|
|
|
PreInstallQuery string `json:"pre_install_query"`
|
|
|
|
|
PostInstallScript string `json:"post_install_script"`
|
|
|
|
|
SelfService bool `json:"self_service"`
|
|
|
|
|
UninstallScript string `json:"uninstall_script"`
|
|
|
|
|
LabelsIncludeAny []string `json:"labels_include_any"`
|
|
|
|
|
LabelsExcludeAny []string `json:"labels_exclude_any"`
|
2025-02-22 00:08:48 +00:00
|
|
|
AutomaticInstall bool `json:"automatic_install"`
|
2024-09-18 16:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type addFleetMaintainedAppResponse struct {
|
2024-11-26 22:21:00 +00:00
|
|
|
SoftwareTitleID uint `json:"software_title_id,omitempty"`
|
|
|
|
|
Err error `json:"error,omitempty"`
|
2024-09-18 16:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:23:26 +00:00
|
|
|
func (r addFleetMaintainedAppResponse) Error() error { return r.Err }
|
2024-09-18 16:21:53 +00:00
|
|
|
|
2025-02-14 22:19:34 +00:00
|
|
|
func addFleetMaintainedAppEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (fleet.Errorer, error) {
|
2024-09-18 16:21:53 +00:00
|
|
|
req := request.(*addFleetMaintainedAppRequest)
|
2025-03-21 02:21:56 +00:00
|
|
|
ctx, cancel := context.WithTimeout(ctx, maintained_apps.InstallerTimeout)
|
2024-09-19 19:42:17 +00:00
|
|
|
defer cancel()
|
2024-11-26 22:21:00 +00:00
|
|
|
titleId, err := svc.AddFleetMaintainedApp(
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
ctx,
|
|
|
|
|
req.TeamID,
|
|
|
|
|
req.AppID,
|
|
|
|
|
req.InstallScript,
|
|
|
|
|
req.PreInstallQuery,
|
|
|
|
|
req.PostInstallScript,
|
|
|
|
|
req.UninstallScript,
|
|
|
|
|
req.SelfService,
|
2025-02-22 00:08:48 +00:00
|
|
|
req.AutomaticInstall,
|
2024-12-17 00:17:13 +00:00
|
|
|
req.LabelsIncludeAny,
|
|
|
|
|
req.LabelsExcludeAny,
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
)
|
2024-09-18 16:21:53 +00:00
|
|
|
if err != nil {
|
2024-09-19 19:42:17 +00:00
|
|
|
if errors.Is(err, context.DeadlineExceeded) {
|
2025-03-20 20:44:09 +00:00
|
|
|
err = fleet.NewGatewayTimeoutError("Couldn't add. Request timeout. Please make sure your server and load balancer timeout is long enough.", err)
|
2024-09-19 19:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-18 16:21:53 +00:00
|
|
|
return &addFleetMaintainedAppResponse{Err: err}, nil
|
|
|
|
|
}
|
2024-11-26 22:21:00 +00:00
|
|
|
return &addFleetMaintainedAppResponse{SoftwareTitleID: titleId}, nil
|
2024-09-18 16:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-22 00:08:48 +00:00
|
|
|
func (svc *Service) AddFleetMaintainedApp(ctx context.Context, _ *uint, _ uint, _, _, _, _ string, _ bool, _ bool, _, _ []string) (uint, error) {
|
2024-09-18 16:21:53 +00:00
|
|
|
// skipauth: No authorization check needed due to implementation returning
|
|
|
|
|
// only license error.
|
|
|
|
|
svc.authz.SkipAuthorization(ctx)
|
|
|
|
|
|
2024-11-26 22:21:00 +00:00
|
|
|
return 0, fleet.ErrMissingLicense
|
2024-09-18 16:21:53 +00:00
|
|
|
}
|
2024-09-20 14:42:43 +00:00
|
|
|
|
|
|
|
|
type listFleetMaintainedAppsRequest struct {
|
|
|
|
|
fleet.ListOptions
|
2024-12-12 03:12:38 +00:00
|
|
|
TeamID *uint `query:"team_id,optional"`
|
2024-09-20 14:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type listFleetMaintainedAppsResponse struct {
|
|
|
|
|
FleetMaintainedApps []fleet.MaintainedApp `json:"fleet_maintained_apps"`
|
|
|
|
|
Meta *fleet.PaginationMetadata `json:"meta"`
|
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:23:26 +00:00
|
|
|
func (r listFleetMaintainedAppsResponse) Error() error { return r.Err }
|
2024-09-20 14:42:43 +00:00
|
|
|
|
2025-02-14 22:19:34 +00:00
|
|
|
func listFleetMaintainedAppsEndpoint(ctx context.Context, request any, svc fleet.Service) (fleet.Errorer, error) {
|
2024-09-20 14:42:43 +00:00
|
|
|
req := request.(*listFleetMaintainedAppsRequest)
|
|
|
|
|
|
|
|
|
|
apps, meta, err := svc.ListFleetMaintainedApps(ctx, req.TeamID, req.ListOptions)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return listFleetMaintainedAppsResponse{Err: err}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 14:49:06 +00:00
|
|
|
listResp := listFleetMaintainedAppsResponse{
|
|
|
|
|
FleetMaintainedApps: apps,
|
|
|
|
|
Meta: meta,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return listResp, nil
|
2024-09-20 14:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-12 03:12:38 +00:00
|
|
|
func (svc *Service) ListFleetMaintainedApps(ctx context.Context, teamID *uint, opts fleet.ListOptions) ([]fleet.MaintainedApp, *fleet.PaginationMetadata, error) {
|
2024-09-20 14:42:43 +00:00
|
|
|
// skipauth: No authorization check needed due to implementation returning
|
|
|
|
|
// only license error.
|
|
|
|
|
svc.authz.SkipAuthorization(ctx)
|
|
|
|
|
|
|
|
|
|
return nil, nil, fleet.ErrMissingLicense
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type getFleetMaintainedAppRequest struct {
|
2025-03-17 15:09:39 +00:00
|
|
|
AppID uint `url:"app_id"`
|
|
|
|
|
TeamID *uint `query:"team_id,optional"`
|
2024-09-20 14:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type getFleetMaintainedAppResponse struct {
|
|
|
|
|
FleetMaintainedApp *fleet.MaintainedApp `json:"fleet_maintained_app"`
|
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:23:26 +00:00
|
|
|
func (r getFleetMaintainedAppResponse) Error() error { return r.Err }
|
2024-09-20 14:42:43 +00:00
|
|
|
|
2025-02-14 22:19:34 +00:00
|
|
|
func getFleetMaintainedApp(ctx context.Context, request any, svc fleet.Service) (fleet.Errorer, error) {
|
2024-09-20 14:42:43 +00:00
|
|
|
req := request.(*getFleetMaintainedAppRequest)
|
|
|
|
|
|
2025-03-17 15:09:39 +00:00
|
|
|
app, err := svc.GetFleetMaintainedApp(ctx, req.AppID, req.TeamID)
|
2024-09-20 14:42:43 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return getFleetMaintainedAppResponse{Err: err}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getFleetMaintainedAppResponse{FleetMaintainedApp: app}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-17 15:09:39 +00:00
|
|
|
func (svc *Service) GetFleetMaintainedApp(ctx context.Context, appID uint, teamID *uint) (*fleet.MaintainedApp, error) {
|
2024-09-20 14:42:43 +00:00
|
|
|
// skipauth: No authorization check needed due to implementation returning
|
|
|
|
|
// only license error.
|
|
|
|
|
svc.authz.SkipAuthorization(ctx)
|
|
|
|
|
|
|
|
|
|
return nil, fleet.ErrMissingLicense
|
|
|
|
|
}
|