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

20404: Edit packages feature #21812

Merged
merged 58 commits into from
Sep 17, 2024
Merged

20404: Edit packages feature #21812

merged 58 commits into from
Sep 17, 2024

Conversation

RachelElysia
Copy link
Member

@RachelElysia RachelElysia commented Sep 4, 2024

Issue

Cerra #20404

Description

  • Add frontend/API backend for editing software packages. GitOps will be a separate PR.

More

Checklist for submitter

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

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • Manual QA for all new/changed functionality

Automated tests will follow in another PR.

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 3.57143% with 324 lines in your changes missing coverage. Please review.

Project coverage is 65.18%. Comparing base (78ad174) to head (f4d36cc).
Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
ee/server/service/software_installers.go 0.00% 131 Missing ⚠️
server/service/software_installers.go 0.00% 77 Missing ⚠️
server/datastore/mysql/software_installers.go 2.66% 73 Missing ⚠️
frontend/components/FileUploader/FileUploader.tsx 0.00% 11 Missing ⚠️
frontend/services/entities/software.ts 0.00% 11 Missing ⚠️
server/service/transport.go 0.00% 9 Missing ⚠️
frontend/components/FileDetails/FileDetails.tsx 22.22% 7 Missing ⚠️
server/fleet/software_installer.go 0.00% 4 Missing ⚠️
frontend/utilities/endpoints.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21812      +/-   ##
==========================================
- Coverage   65.34%   65.18%   -0.17%     
==========================================
  Files        1493     1494       +1     
  Lines      116651   117013     +362     
  Branches     3452     3458       +6     
==========================================
+ Hits        76229    76277      +48     
- Misses      33316    33622     +306     
- Partials     7106     7114       +8     
Flag Coverage Δ
backend 66.48% <1.01%> (-0.19%) ⬇️
frontend 52.09% <23.07%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@iansltx iansltx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a few things as I was checking through to wrap my head around this.

frontend/services/entities/software.ts Outdated Show resolved Hide resolved
frontend/services/entities/software.ts Outdated Show resolved Hide resolved
frontend/services/entities/software.ts Show resolved Hide resolved
@iansltx
Copy link
Member

iansltx commented Sep 6, 2024

@RachelElysia Other note here is I'm assuming that you won't pass the software file at all if that doesn't need to be changed, at which point all I'll do is update metdata (and cancel installs if needed).

@RachelElysia
Copy link
Member Author

RachelElysia commented Sep 9, 2024

@lukeheath / @iansltx thanks for finishing up this feature! I'm unavailable to work on this any more but these are the TODOs I left. Hopefully it's not too much, and hopefully Jacob's work being merged in already will make addressing all this much quicker

Frontend TODOs left (address and remove TODO from code):

  • // TODO: Rename AddPackageForm.tsx to PackageForm.tsx after blocker PRs merge to avoid merge conflicts
  • // TODO: Rename this to PackageFormData after blocker PRs merge to avoid merge conflicts
  • // TODO: Rease onto 20320 Jacob's work that includes all correct fields, help text, default scripts, etc
  • // TODO: Rename to PackageFormData since its used in both add/edit software packages
  • // TODO: Rename to PackageForm everywhere (after Jacob's work is merged to avoid conflicts)
  • // TODO: figure this out is related to the comment above it // Only populate default install/uninstall scripts when adding (but not editing) software
  • // TODO: Only send data that is changing and test E2E
  • // TODO: Add uninstall script once Jacob's 20320 uninstall work is merged

Other TODOs:

  • Ensure team_id = 0 is being passed for editing software for no team

Thank you both so much and hope this all goes relatively smoothly.

@@ -237,7 +237,7 @@ func (ds *Datastore) SaveInstallerUpdates(ctx context.Context, payload *fleet.Up
}

var postInstallScriptID *uint
if payload.PostInstallScript != nil && *payload.PostInstallScript != "" { // pointer because optional
if payload.PostInstallScript != nil { // pointer because optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the script is empty, we should set its ID to NULL in software_installers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just realized that that was the previous behavior (postInstallScriptID *uint zero value being nil in L239). I've reverted the commit made based on your previous feedback. I had actually tested bouncing this back and forth and thought I had missed something when you brought the feedback up initially.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just verified this manually, going from blank post-install to populated, populated to different populated, and populated to blank. Values changed in the DB, including to/from NULL on post-install script contents ID.

This reverts commit fdd6f2d.

Post install script ID is by default nil, which is what we want for a blank
script, so the post-install script check was correct.
gillespi314
gillespi314 previously approved these changes Sep 16, 2024
Copy link
Contributor

@gillespi314 gillespi314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frontend looks good to merge. I included some comments regarding graphics names that I think may be missing. In the interest of time, I think can confirm those are working as expected in a follow up ticket.

/>
)
}
fileDetails={tokenFile ? { name: tokenFile.name } : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the graphic name may have been accidentally removed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's passed in from line 134

/>
)
}
fileDetails={tokenFile ? { name: tokenFile.name } : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the graphic name may have been accidentally removed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed in from line 102

/>
)
}
fileDetails={certFile ? { name: certFile.name } : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the graphic name may have been accidentally removed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the code passes line 115 graphicName in <FileDetails/>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the UI Screenshot 2024-09-16 at 8 00 29 AM

/>
)
}
fileDetails={tokenFile ? { name: tokenFile.name } : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the graphic name may have been accidentally removed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's passed in from line 69
Screenshot 2024-09-16 at 8 01 43 AM

/>
)
}
fileDetails={tokenFile ? { name: tokenFile.name } : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the graphic name may have been accidentally removed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed in from line 79


val, ok = r.MultipartForm.Value["uninstall_script"]
if ok && len(val) > 0 {
decoded.UninstallScript = &val[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the same val variable being reused multiple times in this function? I think the pointer is going to get overwritten (e.g., the install script and post-install script in the decoded map would become the same as the uninstall script)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, thanks for bringing this up (and for the playground link you DM'd me). What's weird is this actually seems to work when multiple scripts are changed, so I need to figure out what's going on. I think it works because the pointers are to the index in the multipart array, rather than to the val itself, so it's brittle but functional. Going to hack on the playground example to see if I can repro.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this works because the pointer is to the 0th array element rather than val itself, so reassigning val doesn't overwrite the pointer. See this playground.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went ahead and renamed values that involve pointers so this is a bit less brittle.

rachaelshaw
rachaelshaw previously approved these changes Sep 16, 2024
@iansltx
Copy link
Member

iansltx commented Sep 16, 2024

@rachaelshaw @gillespi314 I messed up here. Hit "update from main" post-cut and just backed that out because that would include items from post-cut in the cherry pick, which we don't want. Will need an approval on this again due to that dismissal. Sorry for the inconvenience.

Because of how pointers work, the previous implementation wasn't shadowing values, but this is clearer/safer
@iansltx iansltx removed the request for review from mostlikelee September 16, 2024 21:47
Copy link
Member

@iansltx iansltx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if this works...

@iansltx
Copy link
Member

iansltx commented Sep 17, 2024

Okay, that worked. Self-approval standing in for @gillespi314 because she already approved the same code, and it was my mistake that cleared the approval (this is not me approving me own code :) ).

@iansltx iansltx merged commit 1c1ebef into main Sep 17, 2024
29 of 30 checks passed
@iansltx iansltx deleted the 20404-edit-software-fe branch September 17, 2024 13:40
RachelElysia added a commit that referenced this pull request Sep 17, 2024
## Issue
Cerra #20404

## Description
- Add frontend/API backend for editing software packages. GitOps will be
a separate PR.

## More
- Please see subtasks for change lists
  - #21611 
  - #21613

# 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] Manual QA for all new/changed functionality

Automated tests will follow in another PR.

---------

Co-authored-by: Ian Littman <[email protected]>
Co-authored-by: Luke Heath <[email protected]>
Co-authored-by: Jacob Shandling <[email protected]>
Co-authored-by: Victor Lyuboslavsky <[email protected]>
iansltx added a commit that referenced this pull request Sep 17, 2024
(This cherry-pick is only of 21812, unreleased bugs found in QA process
will be cherry picked separately for trackability on zenhub)

> [!NOTE]
> This PR is already merged in `main`, see
#21812 This is against the release
branch so it can be included in 4.57.0

```
 1106  git fetch fleetdm
 1107  git checkout fleetdm/minor-fleet-v4.57.0
 1108  git log main
 1109  git cherry-pick 1c1ebef
 1110  git status
 1111  git checkout -b 20404-edit-software-rc
 1112  git push -u fleetdm 20404-edit-software-rc
```

---------

Co-authored-by: Ian Littman <[email protected]>
Co-authored-by: Luke Heath <[email protected]>
Co-authored-by: Jacob Shandling <[email protected]>
Co-authored-by: Victor Lyuboslavsky <[email protected]>
Co-authored-by: Rachael Shaw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

9 participants