Skip to content

Commit

Permalink
Merge pull request #96 from almenscorner/dev
Browse files Browse the repository at this point in the history
v1.3.5
  • Loading branch information
almenscorner authored Mar 3, 2023
2 parents f0a431b + 3bf6d01 commit d4a3429
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 18 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = IntuneCD
version = 1.3.4
version = 1.3.5
author = Tobias Almén
author_email = [email protected]
description = Tool to backup and update configurations in Intune
Expand Down
78 changes: 63 additions & 15 deletions src/IntuneCD/update_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,43 @@ def get_added_removed(diff_object) -> list:
intent = diff_object[root]["intent"]

if "target" in diff_object[root]:
if "deviceAndAppManagementAssignmentFilterId" in diff_object[root]["target"]:
filterID = diff_object[root]["target"]["deviceAndAppManagementAssignmentFilterId"]
if "deviceAndAppManagementAssignmentFilterType" in diff_object[root]["target"]:
filterType = diff_object[root]["target"]["deviceAndAppManagementAssignmentFilterType"]
if (
"deviceAndAppManagementAssignmentFilterId"
in diff_object[root]["target"]
):
filterID = diff_object[root]["target"][
"deviceAndAppManagementAssignmentFilterId"
]

if diff_object[root]["target"]["@odata.type"] == "#microsoft.graph.groupAssignmentTarget":
if (
"deviceAndAppManagementAssignmentFilterType"
in diff_object[root]["target"]
):
filterType = diff_object[root]["target"][
"deviceAndAppManagementAssignmentFilterType"
]

if (
diff_object[root]["target"]["@odata.type"]
== "#microsoft.graph.groupAssignmentTarget"
):
target = diff_object[root]["target"]["groupId"]

if diff_object[root]["target"]["@odata.type"] == "#microsoft.graph.allDevicesAssignmentTarget":
if (
diff_object[root]["target"]["@odata.type"]
== "#microsoft.graph.allDevicesAssignmentTarget"
):
target = "All Devices"

if diff_object[root]["target"]["@odata.type"] == "#microsoft.graph.allLicensedUsersAssignmentTarget":
if (
diff_object[root]["target"]["@odata.type"]
== "#microsoft.graph.allLicensedUsersAssignmentTarget"
):
target = "All Users"

update.append(f"intent: {intent}, Filter ID: {filterID}, Filter Type: {filterType}, target: {target}")
update.append(
f"intent: {intent}, Filter ID: {filterID}, Filter Type: {filterType}, target: {target}"
)

return update

Expand All @@ -67,34 +89,58 @@ def update_assignment(repo, mem, token) -> list:
request = makeapirequest(
"https://graph.microsoft.com/beta/groups",
token,
{"$filter": "displayName eq " + "'" + val["target"]["groupName"] + "'"},
{
"$filter": "displayName eq "
+ "'"
+ val["target"]["groupName"]
+ "'"
},
)
if request["value"]:
val["target"].pop("groupName")
val["target"]["groupId"] = request["value"][0]["id"]

# Request filter id based on filter name
if val["target"]["deviceAndAppManagementAssignmentFilterId"]:
filters = makeapirequest("https://graph.microsoft.com/beta/deviceManagement/assignmentFilters", token)
filters = makeapirequest(
"https://graph.microsoft.com/beta/deviceManagement/assignmentFilters",
token,
)
for filter in filters["value"]:
if val["target"]["deviceAndAppManagementAssignmentFilterId"] == filter["displayName"]:
val["target"]["deviceAndAppManagementAssignmentFilterId"] = filter["id"]
if (
val["target"]["deviceAndAppManagementAssignmentFilterId"]
== filter["displayName"]
):
val["target"][
"deviceAndAppManagementAssignmentFilterId"
] = filter["id"]

# If filter is None, remove keys
if val["target"]["deviceAndAppManagementAssignmentFilterId"] is None:
val["target"].pop("deviceAndAppManagementAssignmentFilterId")
val["target"].pop("deviceAndAppManagementAssignmentFilterType")

repo = [
val for val in repo if "target" in val and "groupName" not in val["target"]
]

for val in repo:
if (
"groupId" in val["target"]
or "#microsoft.graph.allDevicesAssignmentTarget" in val["target"]["@odata.type"]
or "#microsoft.graph.allLicensedUsersAssignmentTarget" in val["target"]["@odata.type"]
or "#microsoft.graph.allDevicesAssignmentTarget"
in val["target"]["@odata.type"]
or "#microsoft.graph.allLicensedUsersAssignmentTarget"
in val["target"]["@odata.type"]
):
update = True

if update is True:
# Print added assignments
added = {
key: value
for key, value in added.items()
if "target" in value and "groupName" not in value["target"]
}
if added:
print("Updating assignments, added assignments:")
updates = get_added_removed(added)
Expand All @@ -120,4 +166,6 @@ def post_assignment_update(object, id, url, extra_url, token, status_code=200):

request_json = json.dumps(object)
url = f"https://graph.microsoft.com/beta/{url}/{id}/{extra_url}"
makeapirequestPost(url, token, q_param=None, jdata=request_json, status_code=status_code)
makeapirequestPost(
url, token, q_param=None, jdata=request_json, status_code=status_code
)
7 changes: 5 additions & 2 deletions src/IntuneCD/update_enrollmentStatusPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,17 @@ def update(path, token, assignment=False, report=False):
mem_assign_obj = get_object_assignment(mem_id, mem_assignments)
update = update_assignment(assign_obj, mem_assign_obj, token)
if update is not None:
request_data = {"target": update}
target = [{"target": t["target"]} for t in update]
request_data = {
"enrollmentConfigurationAssignments": target
}
post_assignment_update(
request_data,
mem_id,
"deviceManagement/deviceEnrollmentConfigurations",
"assign",
token,
status_code=201,
status_code=200,
)

# If Enrollmen Status Page profile does not exist, create it and assign
Expand Down

0 comments on commit d4a3429

Please sign in to comment.