How to use the fmcapi.api_objects.policy_services.accesspolicies.AccessPolicies function in fmcapi

To help you get started, we’ve selected a few fmcapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github daxm / fmcapi / fmcapi / api_objects / policy_services / hitcounts.py View on Github external
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}'
github daxm / fmcapi / fmcapi / api_objects / policy_services / accessrules.py View on Github external
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.")
github daxm / fmcapi / fmcapi / api_objects / device_services / devicerecords.py View on Github external
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.')
github daxm / fmcapi / fmcapi / api_objects / policy_services / accesspolicies.py View on Github external
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)
github daxm / fmcapi / fmcapi / api_objects / policy_services / defaultactions.py View on Github external
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.")
github daxm / fmcapi / fmcapi / api_objects / policy_services / inheritancesettings.py View on Github external
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.")
github daxm / fmcapi / fmcapi / api_objects / policy_assignment_services / policyassignments.py View on Github external
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(