Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing field #24977

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/Contributing/Audit-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ This activity contains the following fields:
- "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.
- "software_title_id": ID of the added software title.
- "labels_include_any": Target hosts that have any label in the array.
- "labels_exclude_any": Target hosts that don't have any label in the array.

Expand All @@ -1290,6 +1291,7 @@ This activity contains the following fields:
"team_name": "Workstations",
"team_id": 123,
"self_service": true,
"software_title_id": 2234,
"labels_include_any": [
{
"name": "Engineering",
Expand Down
6 changes: 6 additions & 0 deletions ee/server/service/software_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ func (svc *Service) UpdateSoftwareInstaller(ctx context.Context, payload *fleet.
TeamID: actTeamID,
SelfService: existingInstaller.SelfService,
SoftwarePackage: &existingInstaller.Name,
SoftwareTitleID: payload.TitleID,
}

if payload.SelfService != nil && *payload.SelfService != existingInstaller.SelfService {
dirty["SelfService"] = true
activity.SelfService = *payload.SelfService
}

var payloadForNewInstallerFile *fleet.UploadSoftwareInstallerPayload
Expand Down
3 changes: 3 additions & 0 deletions server/fleet/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ type ActivityTypeEditedSoftware struct {
SelfService bool `json:"self_service"`
LabelsIncludeAny []ActivitySoftwareLabel `json:"labels_include_any,omitempty"`
LabelsExcludeAny []ActivitySoftwareLabel `json:"labels_exclude_any,omitempty"`
SoftwareTitleID uint `json:"software_title_id"`
}

func (a ActivityTypeEditedSoftware) ActivityName() string {
Expand All @@ -1733,13 +1734,15 @@ func (a ActivityTypeEditedSoftware) Documentation() (string, string, string) {
- "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.
- "software_title_id": ID of the added software title.
- "labels_include_any": Target hosts that have any label in the array.
- "labels_exclude_any": Target hosts that don't have any label in the array.`, `{
"software_title": "Falcon.app",
"software_package": "FalconSensor-6.44.pkg",
"team_name": "Workstations",
"team_id": 123,
"self_service": true,
"software_title_id": 2234,
"labels_include_any": [
{
"name": "Engineering",
Expand Down
15 changes: 13 additions & 2 deletions server/service/integration_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10790,6 +10790,17 @@
// upload again fails
s.uploadSoftwareInstaller(t, payload, http.StatusConflict, "already exists")

// update should succeed
s.updateSoftwareInstaller(t, &fleet.UpdateSoftwareInstallerPayload{
SelfService: ptr.Bool(true),
InstallScript: ptr.String("some install script"),
PreInstallQuery: ptr.String("some pre install query"),
PostInstallScript: ptr.String("some post install script"),
Filename: "ruby.deb",
TitleID: titleID,
TeamID: nil,
}, http.StatusOK, "")
activityData = fmt.Sprintf(`{"software_title": "ruby", "software_package": "ruby.deb", "team_name": null, "team_id": 0, "self_service": true, "software_title_id": %d}`, titleID)

Check failure on line 10803 in server/service/integration_enterprise_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

ineffectual assignment to activityData (ineffassign)

Check failure on line 10803 in server/service/integration_enterprise_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

ineffectual assignment to activityData (ineffassign)
// patch the software installer to change the labels
body, headers := generateMultipartRequest(t, "", "", nil, s.token, map[string][]string{
"team_id": {"0"},
Expand Down Expand Up @@ -10847,8 +10858,8 @@
s.DoRawWithHeaders("PATCH", fmt.Sprintf("/api/latest/fleet/software/titles/%d/package", titleID), body.Bytes(), http.StatusOK, headers)

activityData = fmt.Sprintf(`{"software_title": "ruby", "software_package": "ruby.deb", "team_name": null,
"team_id": null, "self_service": true, "labels_include_any": [{"id": %d, "name": %q}]}`,
labelResp.Label.ID, labelResp.Label.Name)
"team_id": null, "self_service": true, "labels_include_any": [{"id": %d, "name": %q}], "software_title_id": %d}`,
labelResp.Label.ID, labelResp.Label.Name, titleID)
s.lastActivityMatches(fleet.ActivityTypeEditedSoftware{}.ActivityName(), activityData, 0)

// orbit-downloading fails with invalid orbit node key
Expand Down
68 changes: 68 additions & 0 deletions server/service/testing_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,71 @@ func (ts *withServer) uploadSoftwareInstaller(
require.Contains(t, errMsg, expectedError)
}
}

func (ts *withServer) updateSoftwareInstaller(
t *testing.T,
payload *fleet.UpdateSoftwareInstallerPayload,
expectedStatus int,
expectedError string,
) {
t.Helper()

tfr, err := fleet.NewKeepFileReader(filepath.Join("testdata", "software-installers", payload.Filename))
require.NoError(t, err)
defer tfr.Close()

payload.InstallerFile = tfr

var b bytes.Buffer
w := multipart.NewWriter(&b)

// add the software field
fw, err := w.CreateFormFile("software", payload.Filename)
require.NoError(t, err)
n, err := io.Copy(fw, payload.InstallerFile)
require.NoError(t, err)
require.NotZero(t, n)

// add the team_id field
var tmID uint
if payload.TeamID != nil {
tmID = *payload.TeamID
}
require.NoError(t, w.WriteField("team_id", fmt.Sprintf("%d", tmID)))
// add the remaining fields
if payload.InstallScript != nil {
require.NoError(t, w.WriteField("install_script", *payload.InstallScript))
}
if payload.PreInstallQuery != nil {
require.NoError(t, w.WriteField("pre_install_query", *payload.PreInstallQuery))
}
if payload.PostInstallScript != nil {
require.NoError(t, w.WriteField("post_install_script", *payload.PostInstallScript))
}
if payload.UninstallScript != nil {
require.NoError(t, w.WriteField("uninstall_script", *payload.UninstallScript))
}
if payload.SelfService != nil {
if *payload.SelfService {
require.NoError(t, w.WriteField("self_service", "true"))
} else {
require.NoError(t, w.WriteField("self_service", "false"))
}
}

w.Close()

headers := map[string]string{
"Content-Type": w.FormDataContentType(),
"Accept": "application/json",
"Authorization": fmt.Sprintf("Bearer %s", ts.token),
}

r := ts.DoRawWithHeaders("PATCH", fmt.Sprintf("/api/latest/fleet/software/titles/%d/package", payload.TitleID), b.Bytes(), expectedStatus, headers)
defer r.Body.Close()

if expectedError != "" {
errMsg := extractServerErrorText(r.Body)
require.Contains(t, errMsg, expectedError)
}
}
Loading