Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions src/IntuneCD/backup_intune.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def backup_intune(
args,
max_workers,
platforms,
enrich_documentation=False,
):
"""
Imports all the backup functions dynamically and runs them in parallel.
Expand Down Expand Up @@ -66,6 +67,21 @@ def backup_intune(
"platforms": platforms,
}

# Enrich data if the --enrich-documentation flag is set
if enrich_documentation:
from .intunecdlib.BaseGraphModule import BaseGraphModule
import os
import json

graph = BaseGraphModule()
graph.token = token
settings = graph.make_graph_request("https://graph.microsoft.com/beta/deviceManagement/configurationSettings")
with open(os.path.join(path, "configurationSettings.json"), "w", encoding="utf-8") as f:
json.dump(settings, f, indent=2)
categories = graph.make_graph_request("https://graph.microsoft.com/beta/deviceManagement/configurationCategories")
with open(os.path.join(path, "configurationCategories.json"), "w", encoding="utf-8") as f:
json.dump(categories, f, indent=2)

# List of backup modules to dynamically import and execute
backup_modules = [
(
Expand Down
103 changes: 79 additions & 24 deletions src/IntuneCD/document_intune.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-
from concurrent.futures import ThreadPoolExecutor, as_completed
import os
import json

from .intunecdlib.documentation_functions import (
document_configs,
document_management_intents,
document_settings_catalog,
)
from .decorators import time_command

Expand All @@ -18,6 +21,7 @@ def document_intune(
decode,
split_per_config,
max_workers,
enrich_documentation=False,
):
"""
This function is used to document Intune configuration using threading.
Expand All @@ -30,6 +34,7 @@ def document_intune(
:param decode: Decode base64 values
:param split_per_config: Whether to split each config into its own Markdown file
:param max_workers: Maximum number of concurrent threads
:param enrich_documentation: Whether to enrich Settings Catalog documentation with additional details
"""

# Ensure the output directory exists
Expand Down Expand Up @@ -77,22 +82,59 @@ def document_intune(
# sort doc_tasks alphabetically
doc_tasks = sorted(doc_tasks, key=lambda x: x[1])

settings_lookup = None
categories_lookup = None

if enrich_documentation:
settings_lookup = {}
categories_lookup = {}

settings_path = os.path.join(configpath, "configurationSettings.json")
categories_path = os.path.join(configpath, "configurationCategories.json")
if os.path.exists(settings_path):
with open(settings_path, "r", encoding="utf-8") as f:
settings_json = json.load(f)
if os.path.exists(categories_path):
with open(categories_path, "r", encoding="utf-8") as f:
categories_json = json.load(f)

# Build lookup dictionaries for enrichment
if settings_json:
for s in settings_json.get("value", []):
settings_lookup[s.get("id")] = s
if categories_json:
for c in categories_json.get("value", []):
categories_lookup[c.get("id")] = c

if split or split_per_config:
with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = {
executor.submit(
document_configs,
f"{configpath}/{task[0]}",
outpath,
task[1],
maxlength,
split,
cleanup,
decode,
split_per_config,
): task[1]
for task in doc_tasks
}
futures = {}
for task in doc_tasks:
# Submit Settings Catalog with enrichment if enabled
if task[1] == "Settings Catalog" and enrich_documentation:
futures[executor.submit(
document_settings_catalog,
f"{configpath}/{task[0]}",
outpath,
task[1],
maxlength,
split,
split_per_config,
settings_lookup,
categories_lookup,
)] = task[1]
else:
futures[executor.submit(
document_configs,
f"{configpath}/{task[0]}",
outpath,
task[1],
maxlength,
split,
cleanup,
decode,
split_per_config,
)] = task[1]

for future in as_completed(futures):
task_name = futures[future]
Expand All @@ -104,16 +146,29 @@ def document_intune(
else:
# Run sequentially if split options are disabled
for task in doc_tasks:
document_configs(
f"{configpath}/{task[0]}",
outpath,
task[1],
maxlength,
split,
cleanup,
decode,
split_per_config,
)
# Submit Settings Catalog with enrichment if enabled
if task[1] == "Settings Catalog" and enrich_documentation:
document_settings_catalog(
f"{configpath}/{task[0]}",
outpath,
task[1],
maxlength,
split,
split_per_config,
settings_lookup,
categories_lookup,
)
else:
document_configs(
f"{configpath}/{task[0]}",
outpath,
task[1],
maxlength,
split,
cleanup,
decode,
split_per_config,
)

# **Run Management Intents Sequentially**
document_management_intents(
Expand Down
Loading