mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #38536 This PR moves all logic to create new activities to activity bounded context. The old service and ActivityModule methods are not facades that route to the new activity bounded context. The facades will be removed in a subsequent PR. # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added webhook support for activity events with configurable endpoint and enable/disable settings. * Enhanced automation-initiated activity creation without requiring a user context. * Improved activity service architecture with centralized creation and management. * **Improvements** * Refactored activity creation to use a dedicated service layer for better separation of concerns. * Added support for host-specific and automation-originated activities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/activity"
|
|
"github.com/fleetdm/fleet/v4/server/activity/api"
|
|
"github.com/fleetdm/fleet/v4/server/activity/internal/service"
|
|
"github.com/fleetdm/fleet/v4/server/activity/internal/types"
|
|
platform_authz "github.com/fleetdm/fleet/v4/server/platform/authz"
|
|
)
|
|
|
|
// NewForUnitTests creates an activity NewActivityService backed by a noop store (no database required).
|
|
func NewForUnitTests(
|
|
providers activity.DataProviders,
|
|
webhookSendFn activity.WebhookSendFunc,
|
|
logger *slog.Logger,
|
|
) api.NewActivityService {
|
|
return service.NewService(&noopAuthorizer{}, &noopStore{}, providers, webhookSendFn, logger)
|
|
}
|
|
|
|
// noopAuthorizer allows all actions (appropriate for unit tests).
|
|
type noopAuthorizer struct{}
|
|
|
|
func (a *noopAuthorizer) Authorize(_ context.Context, _ platform_authz.AuthzTyper, _ platform_authz.Action) error {
|
|
return nil
|
|
}
|
|
|
|
// noopStore is a datastore that does nothing (appropriate for unit tests that only need webhook behavior).
|
|
type noopStore struct{}
|
|
|
|
func (s *noopStore) ListActivities(_ context.Context, _ types.ListOptions) ([]*api.Activity, *api.PaginationMetadata, error) {
|
|
return nil, nil, nil
|
|
}
|
|
|
|
func (s *noopStore) ListHostPastActivities(_ context.Context, _ uint, _ types.ListOptions) ([]*api.Activity, *api.PaginationMetadata, error) {
|
|
return nil, nil, nil
|
|
}
|
|
|
|
func (s *noopStore) MarkActivitiesAsStreamed(_ context.Context, _ []uint) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *noopStore) NewActivity(_ context.Context, _ *api.User, _ api.ActivityDetails, _ []byte, _ time.Time) error {
|
|
return nil
|
|
}
|