Skip to content

Commit

Permalink
Merge pull request #179 from almenscorner/dev
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
almenscorner committed Mar 4, 2024
2 parents 36d0ab8 + fce0209 commit 19a6954
Show file tree
Hide file tree
Showing 131 changed files with 7,062 additions and 342 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 = 2.1.2
version = 2.2.0
author = Tobias Almén
author_email = [email protected]
description = Tool to backup and update configurations in Intune
Expand Down
19 changes: 17 additions & 2 deletions src/IntuneCD/backup/Intune/backup_AppProtection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from ...intunecdlib.check_prefix import check_prefix_match
from ...intunecdlib.clean_filename import clean_filename
from ...intunecdlib.graph_batch import batch_assignment, get_object_assignment
from ...intunecdlib.graph_request import makeapirequest
from ...intunecdlib.graph_request import makeapirequest, makeAuditRequest
from ...intunecdlib.process_audit_data import process_audit_data
from ...intunecdlib.process_scope_tags import get_scope_tags_name
from ...intunecdlib.remove_keys import remove_keys
from ...intunecdlib.save_output import save_output

Expand All @@ -17,7 +19,7 @@


# Get all App Protection policies and save them in specified path
def savebackup(path, output, exclude, token, prefix, append_id):
def savebackup(path, output, exclude, token, prefix, append_id, audit, scope_tags):
"""
Saves all App Protection policies in Intune to a JSON or YAML file.
Expand All @@ -28,12 +30,16 @@ def savebackup(path, output, exclude, token, prefix, append_id):
"""

results = {"config_count": 0, "outputs": []}
audit_data = None
configpath = path + "/" + "App Protection/"
data = makeapirequest(ENDPOINT, token)

assignment_responses = batch_assignment(
data, "deviceAppManagement/", "/assignments", token, app_protection=True
)
if audit:
graph_filter = "componentName eq 'ManagedAppProtection'"
audit_data = makeAuditRequest(graph_filter, token)

# If profile is ManagedAppConfiguration, skip to next
for profile in data["value"]:
Expand All @@ -45,6 +51,9 @@ def savebackup(path, output, exclude, token, prefix, append_id):

results["config_count"] += 1

if scope_tags:
profile = get_scope_tags_name(profile, scope_tags)

if (
"assignments" not in exclude
and profile["@odata.type"] != "#microsoft.graph.defaultManagedAppProtection"
Expand Down Expand Up @@ -76,4 +85,10 @@ def savebackup(path, output, exclude, token, prefix, append_id):

results["outputs"].append(fname)

if audit_data:
compare_data = {"type": "resourceId", "value": graph_id}
process_audit_data(
audit_data, compare_data, path, f"{configpath}{fname}.{output}"
)

return results
19 changes: 16 additions & 3 deletions src/IntuneCD/backup/Intune/backup_apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"""

from ...intunecdlib.clean_filename import clean_filename
from ...intunecdlib.graph_request import makeapirequest
from ...intunecdlib.graph_request import makeapirequest, makeAuditRequest
from ...intunecdlib.process_audit_data import process_audit_data
from ...intunecdlib.remove_keys import remove_keys
from ...intunecdlib.save_output import save_output

Expand All @@ -17,7 +18,7 @@


# Get APNs information and save in specified path
def savebackup(path, output, token):
def savebackup(path, output, audit, token):
"""
Save Apple Push Notification setting to a JSON or YAML file.
Expand All @@ -27,9 +28,12 @@ def savebackup(path, output, token):
"""

results = {"config_count": 0, "outputs": []}

audit_data = None
configpath = path + "/" + "Apple Push Notification/"
data = makeapirequest(ENDPOINT, token)
if audit:
graph_filter = "resources/any(s:s/auditResourceType eq 'Microsoft.Management.Services.Api.ApplePushNotificationCertificate')"
audit_data = makeAuditRequest(graph_filter, token)

if data:
results["config_count"] += 1
Expand All @@ -43,4 +47,13 @@ def savebackup(path, output, token):

results["outputs"].append(fname)

if audit_data:
compare_data = {
"type": "auditResourceType",
"value": "Microsoft.Management.Services.Api.ApplePushNotificationCertificate",
}
process_audit_data(
audit_data, path, compare_data, f"{configpath}{fname}.{output}"
)

return results
19 changes: 17 additions & 2 deletions src/IntuneCD/backup/Intune/backup_appConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from ...intunecdlib.check_prefix import check_prefix_match
from ...intunecdlib.clean_filename import clean_filename
from ...intunecdlib.graph_batch import batch_assignment, get_object_assignment
from ...intunecdlib.graph_request import makeapirequest
from ...intunecdlib.graph_request import makeapirequest, makeAuditRequest
from ...intunecdlib.process_audit_data import process_audit_data
from ...intunecdlib.process_scope_tags import get_scope_tags_name
from ...intunecdlib.remove_keys import remove_keys
from ...intunecdlib.save_output import save_output

Expand All @@ -23,7 +25,7 @@


# Get all App Configuration policies and save them in specified path
def savebackup(path, output, exclude, token, prefix, append_id):
def savebackup(path, output, exclude, token, prefix, append_id, audit, scope_tags):
"""
Saves all App Configuration policies in Intune to a JSON or YAML file.
Expand All @@ -34,8 +36,12 @@ def savebackup(path, output, exclude, token, prefix, append_id):
"""

results = {"config_count": 0, "outputs": []}
audit_data = None
configpath = path + "/" + "App Configuration/"
data = makeapirequest(ENDPOINT, token)
if audit:
graph_filter = "componentName eq 'MobileAppConfiguration'"
audit_data = makeAuditRequest(graph_filter, token)

if data["value"]:
assignment_responses = batch_assignment(
Expand All @@ -47,6 +53,9 @@ def savebackup(path, output, exclude, token, prefix, append_id):
continue

results["config_count"] += 1

if scope_tags:
profile = get_scope_tags_name(profile, scope_tags)
if "assignments" not in exclude:
assignments = get_object_assignment(profile["id"], assignment_responses)
if assignments:
Expand Down Expand Up @@ -90,4 +99,10 @@ def savebackup(path, output, exclude, token, prefix, append_id):

results["outputs"].append(fname)

if audit_data:
compare_data = {"type": "resourceId", "value": graph_id}
process_audit_data(
audit_data, compare_data, path, f"{configpath}{fname}.{output}"
)

return results
15 changes: 13 additions & 2 deletions src/IntuneCD/backup/Intune/backup_appleEnrollmentProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from ...intunecdlib.check_prefix import check_prefix_match
from ...intunecdlib.clean_filename import clean_filename
from ...intunecdlib.graph_batch import batch_request
from ...intunecdlib.graph_request import makeapirequest
from ...intunecdlib.graph_request import makeapirequest, makeAuditRequest
from ...intunecdlib.process_audit_data import process_audit_data
from ...intunecdlib.remove_keys import remove_keys
from ...intunecdlib.save_output import save_output

Expand All @@ -17,7 +18,7 @@


# Get all Apple Enrollment Profiles and save them in specified path
def savebackup(path, output, token, prefix, append_id):
def savebackup(path, output, token, prefix, append_id, audit):
"""
Saves all Apple Enrollment Profiles in Intune to a JSON or YAML file.
Expand All @@ -27,8 +28,12 @@ def savebackup(path, output, token, prefix, append_id):
"""

results = {"config_count": 0, "outputs": []}
audit_data = None
configpath = path + "/" + "Enrollment Profiles/Apple/"
data = makeapirequest(ENDPOINT, token)
if audit:
graph_filter = "componentName eq 'Enrollment'"
audit_data = makeAuditRequest(graph_filter, token)

if data["value"]:
profile_ids = []
Expand Down Expand Up @@ -63,4 +68,10 @@ def savebackup(path, output, token, prefix, append_id):

results["outputs"].append(fname)

if audit_data:
compare_data = {"type": "resourceId", "value": graph_id}
process_audit_data(
audit_data, compare_data, path, f"{configpath}{fname}.{output}"
)

return results
38 changes: 34 additions & 4 deletions src/IntuneCD/backup/Intune/backup_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
import re

from ...intunecdlib.clean_filename import clean_filename
from ...intunecdlib.graph_batch import batch_assignment, get_object_assignment
from ...intunecdlib.graph_request import makeapirequest
from ...intunecdlib.graph_batch import (
batch_assignment,
batch_request,
get_object_assignment,
)
from ...intunecdlib.graph_request import makeapirequest, makeAuditRequest
from ...intunecdlib.process_audit_data import process_audit_data
from ...intunecdlib.process_scope_tags import get_scope_tags_name
from ...intunecdlib.remove_keys import remove_keys
from ...intunecdlib.save_output import save_output

Expand Down Expand Up @@ -37,7 +43,7 @@ def match(platform, odata_input) -> bool:


# Get all applications and save them in specified path
def savebackup(path, output, exclude, token, append_id):
def savebackup(path, output, exclude, token, append_id, audit, scope_tags):
"""
Saves all applications in Intune to a JSON or YAML file.
Expand All @@ -48,22 +54,40 @@ def savebackup(path, output, exclude, token, append_id):
"""

results = {"config_count": 0, "outputs": []}

audit_data = None
data = makeapirequest(ENDPOINT, token, q_param)
assignment_responses = batch_assignment(
data, "deviceAppManagement/mobileApps/", "/assignments", token
)
app_ids = [app["id"] for app in data["value"]]
scope_tag_responses = batch_request(
app_ids, "deviceAppManagement/mobileApps/", "?$select=roleScopeTagIds,id", token
)

if audit:
graph_filter = "componentName eq 'MobileApp'"
audit_data = makeAuditRequest(graph_filter, token)

for app in data["value"]:
app_name = ""
platform = ""
results["config_count"] += 1

scope_tag_data = [v for v in scope_tag_responses if app["id"] == v["id"]]
if scope_tag_data:
app["roleScopeTagIds"] = scope_tag_data[0]["roleScopeTagIds"]

if scope_tags:
app = get_scope_tags_name(app, scope_tags)

if "assignments" not in exclude:
assignments = get_object_assignment(app["id"], assignment_responses)
if assignments:
app["assignments"] = assignments

# if audit:
# audit_data = get_audit_log(app["id"], audit_responses)

graph_id = app["id"]
app = remove_keys(app)
app.pop("description", None)
Expand Down Expand Up @@ -137,4 +161,10 @@ def savebackup(path, output, exclude, token, append_id):

results["outputs"].append(fname)

if audit_data:
compare_data = {"type": "resourceId", "value": graph_id}
process_audit_data(
audit_data, compare_data, path, f"{configpath}{fname}.{output}"
)

return results
19 changes: 17 additions & 2 deletions src/IntuneCD/backup/Intune/backup_assignmentFilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

from ...intunecdlib.check_prefix import check_prefix_match
from ...intunecdlib.clean_filename import clean_filename
from ...intunecdlib.graph_request import makeapirequest
from ...intunecdlib.graph_request import makeapirequest, makeAuditRequest
from ...intunecdlib.process_audit_data import process_audit_data
from ...intunecdlib.process_scope_tags import get_scope_tags_name
from ...intunecdlib.remove_keys import remove_keys
from ...intunecdlib.save_output import save_output

Expand All @@ -16,7 +18,7 @@


# Get all Filters and save them in specified path
def savebackup(path, output, token, prefix, append_id):
def savebackup(path, output, token, prefix, append_id, audit, scope_tags):
"""
Saves all Filter in Intune to a JSON or YAML file.
Expand All @@ -26,14 +28,21 @@ def savebackup(path, output, token, prefix, append_id):
"""

results = {"config_count": 0, "outputs": []}
audit_data = None
configpath = path + "/" + "Filters/"
data = makeapirequest(ENDPOINT, token)
if audit:
graph_filter = "componentName eq 'AssignmentFilter'"
audit_data = makeAuditRequest(graph_filter, token)

if data:
for assign_filter in data["value"]:
if prefix and not check_prefix_match(assign_filter["displayName"], prefix):
continue

if scope_tags:
assign_filter = get_scope_tags_name(assign_filter, scope_tags)

results["config_count"] += 1
graph_id = assign_filter["id"]
assign_filter = remove_keys(assign_filter)
Expand All @@ -49,4 +58,10 @@ def savebackup(path, output, token, prefix, append_id):

results["outputs"].append(fname)

if audit_data:
compare_data = {"type": "resourceId", "value": graph_id}
process_audit_data(
audit_data, compare_data, path, f"{configpath}{fname}.{output}"
)

return results
Loading

0 comments on commit 19a6954

Please sign in to comment.