Skip to content

Update JAMF extension attributes #3

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

Merged
merged 5 commits into from
Jun 2, 2025
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: 1 addition & 1 deletion docs/integrations.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lastUpdated": "2025-05-23T20:31:27.935744Z",
"lastUpdated": "2025-06-02T16:03:45.979932Z",
"totalIntegrations": 18,
"integrationDetails": [
{
Expand Down
36 changes: 26 additions & 10 deletions jamf/custom-integration-jamf.star
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ COMPUTER_ASSETS = True
MOBILE_ASSETS = True
DEV_MODE = False

def sanitize_string(s):
if s:
return s.replace(" ", "_").replace(".", "").replace("+", "").replace("(", "").replace(")", "").lower()
else:
return None

def get_bearer_token(client_id, client_secret):
headers = {'Content-Type': 'application/x-www-form-urlencoded', 'accept': 'application/json'}
params = {'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'client_credentials'}
Expand Down Expand Up @@ -278,24 +284,34 @@ def build_asset(item):

# add flattened version of certain attributes
custom_attributes = {}
# add extension attributes
main_ext_attrs = item.get("extensionAttributes", [])
if len(main_ext_attrs) > 0:
for ext in main_ext_attrs:
ext_name = sanitize_string(ext.get("name", None))
ext_values = ext.get("values", None) or ext.get("value", None)
if ext_name and ext_values:
key_name = "ext_attr_" + ext_name
custom_attributes[key_name] = ",".join(ext_values)
# add user extension attributes
user_ext_attrs = item.get("userAndLocation", {}).get("extensionAttributes", [])
if len(user_ext_attrs) > 0:
for ext in user_ext_attrs:
user_ext_name = sanitize_string(ext.get("name", None))
user_ext_values = ext.get("values", None) or ext.get("value", None)
if user_ext_name and user_ext_values:
key_name = "ext_attr_" + user_ext_name
custom_attributes[key_name] = ",".join(user_ext_values)

for key in item.keys():
if key == "extensionAttributes":
for ext in item["extensionAttributes"]:
ext_name = ext.get("name", None).replace(" ", "_").lower()
ext_values = ext.get("values", None) or ext.get("value", None)
if ext_name and ext_values:
key_name = "ext_attr_" + ext_name
custom_attributes[key_name] = ",".join(ext_values)
elif key not in ["purchasing", "storage", "packageReceipts", "contentCaching"]:
if key not in ["purchasing", "storage", "packageReceipts", "contentCaching", "extensionAttributes", "userAndLocation"]:
if type(item[key]) == "dict":
custom_attributes.update(flatten(item[key]))
elif type(item[key]) == "string":
custom_attributes[key] = item[key]
elif type(item[key]) == "list":
# skip lists unless we have more context on them like extensionAttributes
continue
else:
continue

return ImportAsset(
id=asset_id,
Expand Down