Skip to content

Commit

Permalink
Merge pull request #187 from almenscorner/refactor-classes
Browse files Browse the repository at this point in the history
Refactor classes
  • Loading branch information
almenscorner authored Mar 22, 2024
2 parents fce0209 + f28a181 commit 9072dfd
Show file tree
Hide file tree
Showing 348 changed files with 14,728 additions and 32,512 deletions.
6 changes: 6 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ disable=
too-many-nested-blocks,
unnecessary-lambda-assignment,
wrong-import-position,
broad-exception-caught,
no-member,
fixme,
ignore=
backup_intune.py,
backup_entra.py,
Expand All @@ -33,3 +36,6 @@ ignore=
document_intune.py,
document_entra.py,
run_documentation.py,
_test_backup_template.py,
backup_template.py,
update_template.py,
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ ignore:
- "src/IntuneCD/intunecdlib/logger.py"
- "src/IntuneCD/backup/Intune/backup_autopilotDevices.py"
- "src/IntuneCD/backup/Intune/backup_activationLock.py"
coverage:
range: 50..75
round: up
precision: 2
status:
patch: off
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.2.0
version = 2.3.0.rc1
author = Tobias Almén
author_email = [email protected]
description = Tool to backup and update configurations in Intune
Expand Down
57 changes: 57 additions & 0 deletions src/IntuneCD/backup/Entra/Applications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
from ...intunecdlib.BaseBackupModule import BaseBackupModule


class ApplicationsBackupModule(BaseBackupModule):
"""A class used to backup Entra Applications
Attributes:
CONFIG_ENDPOINT (str): The endpoint to get the data from
LOG_MESSAGE (str): The message to log when backing up the data
"""

CONFIG_ENDPOINT = "/v1.0/myorganization/applications"
LOG_MESSAGE = "Backing up Entra Application: "

def __init__(self, *args, **kwargs):
"""Initializes the ApplicationsBackupModule class
Args:
*args: The positional arguments to pass to the base class's __init__ method.
**kwargs: The keyword arguments to pass to the base class's __init__ method.
"""
super().__init__(*args, **kwargs)
self.path = f"{self.path}/Entra/Applications/"
self.handle_assignment = False

def main(self) -> dict[str, any]:
"""The main method to backup the Entra data
Returns:
dict[str, any]: The results of the backup
"""

try:
self.entra_data = self.make_graph_request(
endpoint=self.endpoint + self.CONFIG_ENDPOINT
)
except Exception as e:
self.log(
tag="error",
msg=f"Error getting Application data from {self.endpoint + self.CONFIG_ENDPOINT}: {e}",
)
return None

try:
self.results = self.process_data(
data=self.entra_data["value"],
filetype=self.filetype,
path=self.path,
name_key="displayName",
log_message=self.LOG_MESSAGE,
)
except Exception as e:
self.log(tag="error", msg=f"Error processing Application data: {e}")
return None

return self.results
59 changes: 59 additions & 0 deletions src/IntuneCD/backup/Entra/AuthenticationFlows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
from ...intunecdlib.BaseBackupModule import BaseBackupModule


class AuthenticationFlowsBackupModule(BaseBackupModule):
"""A class used to backup Entra Authentication Flows
Attributes:
CONFIG_ENDPOINT (str): The endpoint to get the data from
LOG_MESSAGE (str): The message to log when backing up the data
"""

CONFIG_ENDPOINT = "/beta/policies/authenticationFlowsPolicy"

def __init__(self, *args, **kwargs):
"""Initializes the AuthenticationFlowsBackupModule class
Args:
*args: The positional arguments to pass to the base class's __init__ method.
**kwargs: The keyword arguments to pass to the base class's __init__ method.
"""
super().__init__(*args, **kwargs)
self.path = f"{self.path}/Entra/Authentication Flows Policy/"
self.preset_filename = "authentication_flows_policy"

def main(self) -> dict[str, any]:
"""The main method to backup the Entra data
Returns:
dict[str, any]: The results of the backup
"""

try:
self.entra_data = self.make_graph_request(
endpoint=self.endpoint + self.CONFIG_ENDPOINT
)
except Exception as e:
self.log(
tag="error",
msg=f"Error getting Authentication Flows data from {self.endpoint + self.CONFIG_ENDPOINT}: {e}",
)
return None

self.log(msg="Backing up Entra Authentication Flows")

try:
self.results = self.process_data(
data=self.entra_data,
filetype=self.filetype,
path=self.path,
name_key="",
)
except Exception as e:
self.log(
tag="error", msg=f"Error processing Authentication Flows data: {e}"
)
return None

return self.results
59 changes: 59 additions & 0 deletions src/IntuneCD/backup/Entra/AuthenticationMethods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
from ...intunecdlib.BaseBackupModule import BaseBackupModule


class AuthenticationMethodsBackupModule(BaseBackupModule):
"""A class used to backup Entra Authentication Methods
Attributes:
CONFIG_ENDPOINT (str): The endpoint to get the data from
LOG_MESSAGE (str): The message to log when backing up the data
"""

CONFIG_ENDPOINT = "/beta/policies/authenticationmethodspolicy"

def __init__(self, *args, **kwargs):
"""Initializes the AuthenticationMethodsBackupModule class
Args:
*args: The positional arguments to pass to the base class's __init__ method.
**kwargs: The keyword arguments to pass to the base class's __init__ method.
"""
super().__init__(*args, **kwargs)
self.path = f"{self.path}/Entra/Authentication Methods/"
self.preset_filename = "authentication_methods"

def main(self) -> dict[str, any]:
"""The main method to backup the Entra data
Returns:
dict[str, any]: The results of the backup
"""

try:
self.entra_data = self.make_graph_request(
endpoint=self.endpoint + self.CONFIG_ENDPOINT
)
except Exception as e:
self.log(
tag="error",
msg=f"Error getting Authentication Methods data from {self.endpoint + self.CONFIG_ENDPOINT}: {e}",
)
return None

self.log(msg="Backing up Entra Authentication Methods")

try:
self.results = self.process_data(
data=self.entra_data,
filetype=self.filetype,
path=self.path,
name_key="",
)
except Exception as e:
self.log(
tag="error", msg=f"Error processing Authentication Methods data: {e}"
)
return None

return self.results
59 changes: 59 additions & 0 deletions src/IntuneCD/backup/Entra/AuthorizationPolicy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
from ...intunecdlib.BaseBackupModule import BaseBackupModule


class AuthorizationPolicyBackupModule(BaseBackupModule):
"""A class used to backup Entra Authorization Policy
Attributes:
CONFIG_ENDPOINT (str): The endpoint to get the data from
LOG_MESSAGE (str): The message to log when backing up the data
"""

CONFIG_ENDPOINT = "/beta/policies/authorizationPolicy"

def __init__(self, *args, **kwargs):
"""Initializes the AuthorizationPolicyBackupModule class
Args:
*args: The positional arguments to pass to the base class's __init__ method.
**kwargs: The keyword arguments to pass to the base class's __init__ method.
"""
super().__init__(*args, **kwargs)
self.path = f"{self.path}/Entra/Authorization Policy/"
self.preset_filename = "authorization_policy"

def main(self) -> dict[str, any]:
"""The main method to backup the Entra data
Returns:
dict[str, any]: The results of the backup
"""

try:
self.entra_data = self.make_graph_request(
endpoint=self.endpoint + self.CONFIG_ENDPOINT
)
except Exception as e:
self.log(
tag="error",
msg=f"Error getting Authorization Policy data from {self.endpoint + self.CONFIG_ENDPOINT}: {e}",
)
return None

self.log(msg="Backing up Entra Authorization Policy")

try:
self.results = self.process_data(
data=self.entra_data["value"],
filetype=self.filetype,
path=self.path,
name_key="",
)
except Exception as e:
self.log(
tag="error", msg=f"Error processing Authorization Policy data: {e}"
)
return None

return self.results
58 changes: 58 additions & 0 deletions src/IntuneCD/backup/Entra/B2B.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
from ...intunecdlib.BaseBackupModule import BaseBackupModule


class B2BPolicyBackupModule(BaseBackupModule):
"""A class used to backup Entra B2B Policy
Attributes:
CONFIG_ENDPOINT (str): The endpoint to get the data from
LOG_MESSAGE (str): The message to log when backing up the data
"""

CONFIG_ENDPOINT = "B2B/b2bPolicy"

def __init__(self, *args, **kwargs):
"""Initializes the B2BPolicyBackupModule class
Args:
*args: The positional arguments to pass to the base class's __init__ method.
**kwargs: The keyword arguments to pass to the base class's __init__ method.
"""
super().__init__(*args, **kwargs)
self.path = f"{self.path}/Entra/External Collaboration Settings/"
self.preset_filename = "b2b_policy"

def main(self) -> dict[str, any]:
"""The main method to backup the Entra data
Returns:
dict[str, any]: The results of the backup
"""

try:
self.entra_data = self.make_azure_request(self.CONFIG_ENDPOINT)
except Exception as e:
self.log(
tag="error",
msg=f"Error getting External Collaboration Settings data from {self.CONFIG_ENDPOINT}: {e}",
)
return None

self.log(msg="Backing up Entra External Collaboration Settings B2B Policy")

try:
self.results = self.process_data(
data=self.entra_data,
filetype=self.filetype,
path=self.path,
name_key="",
)
except Exception as e:
self.log(
tag="error",
msg=f"Error processing External Collaboration Settings data: {e}",
)
return None

return self.results
60 changes: 60 additions & 0 deletions src/IntuneCD/backup/Entra/DeviceRegistration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
from ...intunecdlib.BaseBackupModule import BaseBackupModule


class DeviceRegistrationPolicyBackupModule(BaseBackupModule):
"""A class used to backup Entra Device Registration Policy
Attributes:
CONFIG_ENDPOINT (str): The endpoint to get the data from
LOG_MESSAGE (str): The message to log when backing up the data
"""

CONFIG_ENDPOINT = "/beta/policies/deviceRegistrationPolicy"

def __init__(self, *args, **kwargs):
"""Initializes the DeviceRegistrationPolicyBackupModule class
Args:
*args: The positional arguments to pass to the base class's __init__ method.
**kwargs: The keyword arguments to pass to the base class's __init__ method.
"""
super().__init__(*args, **kwargs)
self.path = f"{self.path}/Entra/Device Registration Policy/"
self.preset_filename = "device_registration_policy"

def main(self) -> dict[str, any]:
"""The main method to backup the Entra data
Returns:
dict[str, any]: The results of the backup
"""

try:
self.entra_data = self.make_graph_request(
endpoint=self.endpoint + self.CONFIG_ENDPOINT
)
except Exception as e:
self.log(
tag="error",
msg=f"Error getting Device Registration Policy data from {self.endpoint + self.CONFIG_ENDPOINT}: {e}",
)
return None

self.log(msg="Backing up Entra Device Registration Policy")

try:
self.results = self.process_data(
data=self.entra_data,
filetype=self.filetype,
path=self.path,
name_key="",
)
except Exception as e:
self.log(
tag="error",
msg=f"Error processing Device Registration Policy data: {e}",
)
return None

return self.results
Loading

0 comments on commit 9072dfd

Please sign in to comment.