Skip to content

Commit

Permalink
Cleanup on activities, software installer handling
Browse files Browse the repository at this point in the history
  • Loading branch information
iansltx committed Sep 8, 2024
1 parent 1d8cb51 commit 3346907
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/Contributing/Audit-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ Generated when a software installer is updated in Fleet.

This activity contains the following fields:
- "software_title": Name of the software.
- "software_package": Filename of the installer.
- "software_package": Filename of the installer. `null` if the installer package was not modified.
- "team_name": Name of the team on which this software was edited. `null` if it was edited on no team.
- "team_id": The ID of the team on which this software was edited. `null` if it was edited on no team.
- "self_service": Whether the software is available for installation by the end user.
Expand Down
27 changes: 17 additions & 10 deletions ee/server/service/software_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ func (svc *Service) UpdateSoftwareInstaller(ctx context.Context, titleID uint, p
installer.SelfService = *payload.SelfService
}

activity := fleet.ActivityTypeEditedSoftware{
SoftwareTitle: installer.SoftwareTitle,
TeamName: teamName,
TeamID: payload.TeamID,
SelfService: installer.SelfService,
}

if payload.InstallerFile != nil || payload.PreInstallQuery != nil ||
payload.InstallScript != nil || payload.PostInstallScript != nil || payload.UninstallScript != nil {

Expand Down Expand Up @@ -196,12 +203,17 @@ func (svc *Service) UpdateSoftwareInstaller(ctx context.Context, titleID uint, p

var newInstallerFileMeta *file.InstallerMetadata = nil

Check failure on line 204 in ee/server/service/software_installers.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

var-declaration: should drop = nil from declaration of var newInstallerFileMeta; it is the zero value (revive)

Check failure on line 204 in ee/server/service/software_installers.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

var-declaration: should drop = nil from declaration of var newInstallerFileMeta; it is the zero value (revive)
if payload.InstallerFile != nil {
newInstallerFileMeta, err = file.ExtractInstallerMetadata(payload.InstallerFile)
payloadForInstallerFile := &fleet.UploadSoftwareInstallerPayload{
InstallerFile: payload.InstallerFile,
Filename: payload.Filename,
}

newInstallerExtension, err := svc.addMetadataToSoftwarePayload(ctx, payloadForInstallerFile)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "extracting updated installer metadata")
}

if newInstallerFileMeta.Extension != existingInstallerFileMeta.Extension {
if newInstallerExtension != existingInstallerFileMeta.Extension {
return nil, &fleet.BadRequestError{
Message: "You must upload an installer of the same type as the currently uploaded installer. To switch installer types, delete and re-add.",
InternalErr: ctxerr.Wrap(ctx, err, "installer extension mismatch"),
Expand All @@ -211,7 +223,8 @@ func (svc *Service) UpdateSoftwareInstaller(ctx context.Context, titleID uint, p
// TODO check if installer file is for a different software title (if so, fail; this will implicitly fail on source mismatch)

// noop if uploaded installer is identical to previous installer
if bytes.Compare(newInstallerFileMeta.SHASum, existingInstallerFileMeta.SHASum) != 0 {
if payloadForInstallerFile.StorageID != hex.EncodeToString(existingInstallerFileMeta.SHASum) {
activity.SoftwarePackage = &payload.Filename
dirty = true
cancelPendingInstalls = true
resetInstallCounts = true
Expand Down Expand Up @@ -286,13 +299,7 @@ func (svc *Service) UpdateSoftwareInstaller(ctx context.Context, titleID uint, p
}

// Create activity
if err := svc.NewActivity(ctx, vc.User, fleet.ActivityTypeEditedSoftware{
SoftwareTitle: payload.Title,
SoftwarePackage: payload.Filename,
TeamName: teamName,
TeamID: payload.TeamID,
SelfService: installer.SelfService,
}); err != nil {
if err := svc.NewActivity(ctx, vc.User, activity); err != nil {
return nil, ctxerr.Wrap(ctx, err, "creating activity for edited software")
}

Expand Down
4 changes: 2 additions & 2 deletions server/fleet/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ func (a ActivityTypeAddedSoftware) Documentation() (string, string, string) {

type ActivityTypeEditedSoftware struct {
SoftwareTitle string `json:"software_title"`
SoftwarePackage string `json:"software_package"`
SoftwarePackage *string `json:"software_package"`
TeamName *string `json:"team_name"`
TeamID *uint `json:"team_id"`
SelfService bool `json:"self_service"`
Expand All @@ -1596,7 +1596,7 @@ func (a ActivityTypeEditedSoftware) ActivityName() string {
func (a ActivityTypeEditedSoftware) Documentation() (string, string, string) {
return `Generated when a software installer is updated in Fleet.`, `This activity contains the following fields:
- "software_title": Name of the software.
- "software_package": Filename of the installer.
- "software_package": Filename of the installer.` + " `null` " + `if the installer package was not modified."
- "team_name": Name of the team on which this software was updated.` + " `null` " + `if it was updated on no team." +
- "team_id": The ID of the team on which this software was updated.` + " `null` " + `if it was updated on no team.
- "self_service": Whether the software is available for installation by the end user.`, `{
Expand Down

0 comments on commit 3346907

Please sign in to comment.