salopensource / sal-scripts

Apache License 2.0
23 stars 31 forks source link

Adding TTL for udid_cache #112

Closed agburch closed 11 months ago

agburch commented 1 year ago

The process of determining a "friendly" model name is truly anything but.

As it stands now, we first attempt to pull the product-name from the I/O Registry. If this fails (which it will on the dwindling intel mac population), we fall back on a UDID cache file. If this file is present then done! Otherwise, phone Apple and ask nicely.

But sadly, this has led to some inaccuracies in the field. Namely for macs that (for one strange reason or another) have a UDID_cache from a different device. Given that the cache file has no TTL, this means that a device restored from backup can happily report the wrong "friendly model" forever.

This PR attempts to address this issue by adding a 30 day TTL to the cache after which it is cleared and updated. This way, even if a device has an invalid (or alien) cache file, it will eventually correct itself. This makes everyone happy! Especially if you are relying on SAL to audit your inventory database 👀

grahamgilbert commented 1 year ago

Wow, thank you for that passive agressive comment.

If you are somehow copying over the device's UDID when you are restoring a backup, you likely have other problems. As it stands, the cache is only used if the devive's UDID matches the one of the cache filename, so I do not see how this would become an issue as this is tied to the physical hardware, not anything that would be copied during a backup restore.

agburch commented 1 year ago

I totally admit that I don't understand the root cause of the issue, e.g. why the cache file would have a wrong value, but I was attempting to describe what I was seeing and fix it in the most minimally invasive way.

Apologies if my first comment appeared to have any tone - that was not my intent. I just wanted to save any reviewer the potential "what is this??" line of questioning.

agburch commented 11 months ago

Looks like we only have a handful of devices reporting the wrong friendly name. So I don't think this is worth an upstream change. I'll close this now 👍🏼