primalcurve / git2jss

Easily sync your scripts and EA's from a git repo with the JSS
MIT License
3 stars 3 forks source link

Feature request: Allow deletion of scripts & EAs #3

Open mikedowler opened 4 years ago

mikedowler commented 4 years ago

At present, sync.py will perform GETs, PUTs, and POSTs - allowing script and EA objects to be read, updated, and created.

We have a bunch of older scripts in our repo that we no longer need, and that we want to delete (taking advantage of the fact that git keeps a record of the deletion and would allow them to be reinstated if necessary). In order to sync those changes across to Jamf Pro, I think we need a method that will implement a DELETE.

I'm not entirely sure how we would implement this - I guess it would need a second list of deleted files to go alongside all_items (which lists changes), and a delete_resource method. I'm willing to give it a try, if you can provide a couple of pointers.

primalcurve commented 4 years ago

Probably the best way to do this is to compare what's live in the JPS against what is in the repo as a whole, rather than relying on merely what's been deleted from one moment to the next. Naturally for CI/CD using the git repository works from moment to moment, but I'm thinking of running it from the command line irregularly, as some people do.

mikedowler commented 4 years ago

~Not sure I really understand why that's different for deletions than changes. If someone makes a whole bunch of commits (without using CI/CD to sync), and then runs the tool at the end, it's only going to pick up the changes between the penultimate and last commits, right? Anything from the earlier commits won't be synced (until that file gets changed again). So the same with deletions - if you choose not to run sync.py after every commit (or using CI/CD, after every build), then you are going miss changes.~ (Sorry - re-read the code, and understand what you mean now. If ARGS.update_all is set, then the code isn't looking at a list of changes - it's just iterating through the list of objects and uploading each of them)

I think the other challenge is going to be working out when an item counts as 'deleted'. If the directory is deleted, or if the directory is left in place but is empty, then that's a clear deletion. Deletion of a script.* file (for a script) should also count as deletion, even if the xml were left in place. For an EA, it might be fine to delete the script and leave the xml (but maybe we need to validate that the xml is no longer referencing it - see my other FR?). Deletion of the xml, but leaving a script.* or ea.* in place is probably not deletion, and we just need to regenerate the xml from a template. Thoughts?