Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def acp(self, name='', acp_id=''):
# either name or id of the ACP should be given
logging.debug("In acp() for HitCounts class.")
if acp_id != '':
self.acp_id = acp_id
self.URL = f'{self.fmc.configuration_url}{self.PREFIX_URL}/{self.acp_id}/operational/hitcounts'
self.acp_added_to_url = True
elif name != '':
acp1 = AccessPolicies(fmc=self.fmc)
acp1.get(name=name)
if 'id' in acp1.__dict__:
self.acp_id = acp1.id
self.URL = f'{self.fmc.configuration_url}{self.PREFIX_URL}/{self.acp_id}/operational/hitcounts'
self.acp_added_to_url = True
else:
logging.warning(f'Access Control Policy "{name}" not found. Cannot configure acp for HitCounts.')
else:
logging.error('No accessPolicy name or id was provided.')
# Rebuild the URL with possible new information
self.URL = self.URL.split('?')[0]
self.URL = f'{self.URL}{self.URL_SUFFIX}'
def acp(self, name="", id=""):
"""
Associate an AccessPolicies object with this AccessRule object.
:param name: (str) Name of ACP.
:param id: (str) ID of ACP.
:return: None
"""
# either name or id of the ACP should be given
logging.debug("In acp() for AccessRules class.")
if id != "":
self.acp_id = id
self.URL = f"{self.fmc.configuration_url}{self.PREFIX_URL}/{id}/accessrules"
elif name != "":
acp1 = AccessPolicies(fmc=self.fmc)
acp1.get(name=name)
if "id" in acp1.__dict__:
self.acp_id = acp1.id
self.URL = f"{self.fmc.configuration_url}{self.PREFIX_URL}/{acp1.id}/accessrules"
else:
logging.warning(
f"Access Control Policy {name} not found. Cannot set up accessPolicy for AccessRules."
)
else:
logging.error("No accessPolicy name or ID was provided.")
def acp(self, name=''):
logging.debug("In acp() for Device class.")
acp = AccessPolicies(fmc=self.fmc)
acp.get(name=name)
if 'id' in acp.__dict__:
self.accessPolicy = {'id': acp.id, 'type': acp.type}
else:
logging.warning(f'Access Control Policy {name} not found. Cannot set up accessPolicy for DeviceRecords.')
def parse_kwargs(self, **kwargs):
super().parse_kwargs(**kwargs)
logging.debug("In parse_kwargs() for AccessPolicies class.")
if 'defaultAction' in kwargs:
self.defaultAction = kwargs['defaultAction']
else:
self.defaultAction = {'action': 'BLOCK'}
def put(self, **kwargs):
logging.info('The put() method for the AccessPolicies() class can work but I need to write a '
'DefaultAction() class and accommodate for such before "putting".')
pass
class AccessControlPolicy(AccessPolicies):
"""Dispose of this Class after 20210101."""
def __init__(self, fmc, **kwargs):
warnings.resetwarnings()
warnings.warn("Deprecated: AccessControlPolicy() should be called via AccessPolicies().")
super().__init__(fmc, **kwargs)
def acp(self, name="", acp_id=""):
"""
Associate an AccessPolicies object with this DefaultAction object.
:param name: (str) Name of ACP.
:param id: (str) ID of ACP.
:return: None
"""
# either name or id of the ACP should be given
logging.debug("In acp() for DefaultActions class.")
if acp_id != "":
self.acp_id = acp_id
self.URL = f"{self.fmc.configuration_url}{self.PREFIX_URL}/{self.acp_id}"
self.acp_added_to_url = True
elif name != "":
acp1 = AccessPolicies(fmc=self.fmc)
acp1.get(name=name)
if "id" in acp1.__dict__:
self.acp_id = acp1.id
self.URL = f"{self.fmc.configuration_url}{self.PREFIX_URL}/{self.acp_id}/defaultactions"
self.acp_added_to_url = True
else:
logging.warning(
f'Access Control Policy "{name}" not found. Cannot configure acp for DefaultActions.'
)
else:
logging.error("No accessPolicy name or id was provided.")
def acp(self, name="", acp_id=""):
"""
Associate an AccessPolicies object with this InheritanceSettings object.
:param name: (str) Name of ACP.
:param id: (str) ID of ACP.
:return: None
"""
# either name or id of the ACP should be given
logging.debug("In acp() for InheritanceSettings class.")
if acp_id != "":
self.acp_id = acp_id
self.URL = f"{self.fmc.configuration_url}{self.PREFIX_URL}/{self.acp_id}/inheritancesettings"
self.acp_added_to_url = True
elif name != "":
acp1 = AccessPolicies(fmc=self.fmc)
acp1.get(name=name)
if "id" in acp1.__dict__:
self.acp_id = acp1.id
self.URL = f"{self.fmc.configuration_url}{self.PREFIX_URL}/{self.acp_id}/inheritancesettings"
self.acp_added_to_url = True
else:
logging.warning(
f'Access Control Policy "{name}" not found. Cannot configure acp for InheritanceSettings.'
)
else:
logging.error("No accessPolicy name or id was provided.")
def accesspolicy(self, name, devices):
"""
Assign Access Control Policy to the list of devices.
:param name: (str) Name of ACP.
:param devices: (list) List of device names.
"""
logging.debug("In accesspolicy() for PolicyAssignments class.")
targets = []
pol1 = AccessPolicies(fmc=self.fmc)
pol1.get(name=name)
if "id" in pol1.__dict__:
self.policy = {"type": pol1.type, "name": pol1.name, "id": pol1.id}
else:
logging.warning(
f"Access Control Policy {name} not found. Cannot set up PolicyAssignment."
)
for device in devices:
if device["type"] == "device":
dev1 = DeviceRecords(fmc=self.fmc)
dev1.get(name=device["name"])
elif device["type"] == "deviceHAPair":
dev1 = FTDDeviceHAPairs(fmc=self.fmc)
dev1.get(name=device["name"])
if "id" in dev1.__dict__:
logging.info(