Skip to content
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

v2.3.4 #207

Merged
merged 6 commits into from
Jun 28, 2024
Merged
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
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.3.3
version = 2.3.4
author = Tobias Almén
author_email = [email protected]
description = Tool to backup and update configurations in Intune
Expand Down
48 changes: 25 additions & 23 deletions src/IntuneCD/intunecdlib/BaseUpdateModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,17 @@ def create_downstream_data(
self.log(msg=f"Created with id: {self.create_request['id']}")

if self.handle_assignment:
self.handle_assignments(
repo_assignments, [], self.assignment_key, self.create_request["id"]
)
if self.handle_iterable_assignment:
self.handle_iterable_assignments(
repo_assignments,
[],
self.assignment_key,
self.create_request["id"],
)
if self.config_type == "Windows Enrollment Profile":
self.handle_iterable_assignments(
repo_assignments,
[],
self.assignment_key,
self.create_request["id"],
)
else:
self.handle_assignments(
repo_assignments, [], self.assignment_key, self.create_request["id"]
)

def get_match_data(self, intune_data: dict, match_info: dict) -> tuple:
"""Gets the matching data
Expand Down Expand Up @@ -664,19 +665,20 @@ def process_update(
)

if self.handle_assignment:
self.handle_assignments(
repo_assignments,
self.downstream_assignments,
self.assignment_key,
self.downstream_id,
)
if self.handle_iterable_assignment:
self.handle_iterable_assignments(
repo_assignments,
self.downstream_assignments,
self.assignment_key,
self.downstream_id,
)
if self.config_type == "Windows Enrollment Profile":
self.handle_iterable_assignments(
repo_assignments,
self.downstream_assignments,
self.assignment_key,
self.downstream_id,
)
else:
self.handle_assignments(
repo_assignments,
self.downstream_assignments,
self.assignment_key,
self.downstream_id,
)

# Add scheduledActionsForRule back to the data if it was removed
if repo_scheduled_actions:
Expand Down
5 changes: 5 additions & 0 deletions src/IntuneCD/intunecdlib/IntuneCDBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import base64
import json
import os
import sys
import time

import yaml
Expand Down Expand Up @@ -168,6 +169,7 @@ def log(self, function: str = None, msg: str = None, tag: str = "info"):
msg (str): The message to print to the console.
tag (str): The tag to use for the log message. Defaults to "info".
"""
exit_on_error = os.getenv("EXIT_ON_ERROR")
verbose = os.getenv("VERBOSE")
if verbose:
msg = (
Expand All @@ -181,6 +183,9 @@ def log(self, function: str = None, msg: str = None, tag: str = "info"):
msg = f"{time.asctime()} [{tag.upper()}] {msg}"
print(msg)

if tag == "error" and exit_on_error:
sys.exit(1)

def get_pop_keys(self, data: dict, keys: list[str], method: str = "get") -> None:
"""A method to get or pop keys from a dictionary

Expand Down
11 changes: 11 additions & 0 deletions src/IntuneCD/run_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,20 @@ def start():
help="The authentication token to use for the update if not using an app registration",
type=str,
)
parser.add_argument(
"--exit-on-error",
help="When set, the script will exit on the first error",
action="store_true",
)

args = parser.parse_args()

if args.verbose:
os.environ["VERBOSE"] = "True"

if args.exit_on_error:
os.environ["EXIT_ON_ERROR"] = "True"

def devtoprod():
return "devtoprod"

Expand Down Expand Up @@ -318,6 +326,9 @@ def run_backup(path, output, exclude, token, prefix, append_id):
if "VERBOSE" in os.environ:
del os.environ["VERBOSE"]

if "EXIT_ON_ERROR" in os.environ:
del os.environ["EXIT_ON_ERROR"]


if __name__ == "__main__":
start()
10 changes: 10 additions & 0 deletions src/IntuneCD/run_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,20 @@ def start():
help="The authentication token to use for the update if not using an app registration",
type=str,
)
parser.add_argument(
"--exit-on-error",
help="When this parameter is set, IntuneCD will exit on error",
action="store_true",
)

args = parser.parse_args()

if args.verbose:
os.environ["VERBOSE"] = "True"

if args.exit_on_error:
os.environ["EXIT_ON_ERROR"] = "True"

def devtoprod():
return "devtoprod"

Expand Down Expand Up @@ -315,6 +323,8 @@ def run_update(path, token, assignment, exclude, report, create_groups, remove):

if "VERBOSE" in os.environ:
del os.environ["VERBOSE"]
if "EXIT_ON_ERROR" in os.environ:
del os.environ["EXIT_ON_ERROR"]


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/IntuneCD/update/Intune/EnrollmentStatusPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_app_ids(self, repo_data: dict) -> dict[str, any]:

for app in repo_data["selectedMobileAppNames"]:
param = {
"$filter": f"(isof('{str(app['type']).replace('#','')}'))",
"$filter": f"(isof('{str(app['type']).replace('#', '')}'))",
"$search": '"' + app["name"] + '"',
}

Expand Down
8 changes: 4 additions & 4 deletions src/IntuneCD/update/Intune/WindowsEnrollmentProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(self, *args, **kwargs):
"root['assignments']",
]
# Windows enrollment profile assginment is handled differently, so we need to set the following attributes
self.handle_assignment = False
self.handle_iterable_assignment = True
self.assignment_key = "target"
self.assignment_status_code = 201
Expand Down Expand Up @@ -82,9 +81,10 @@ def main(self) -> dict[str, any]:
self.reset_diffs_and_count()

for item in intune_data["value"]:
# Remvoe any assignments before removing the profile
endpoint = f"{self.endpoint}{self.CONFIG_ENDPOINT}{item['id']}{self.assignment_extra_url}"
self.make_graph_request(endpoint, method="delete", status_code=200)
if self.remove:
# Remvoe any assignments before removing the profile
endpoint = f"{self.endpoint}{self.CONFIG_ENDPOINT}{item['id']}{self.assignment_extra_url}"
self.make_graph_request(endpoint, method="delete", status_code=200)
self.remove_downstream_data(self.CONFIG_ENDPOINT, intune_data["value"])

return self.diff_summary
Loading