kaisero / fireREST

Python library for interacting with Cisco Firepower Management Center REST API
GNU General Public License v3.0
70 stars 49 forks source link

Reset Params Option on every request #8

Closed jbronikowski closed 4 years ago

jbronikowski commented 5 years ago

Within the code, you never reset the params field which can cause fields to not render properly if you have more than one ACP policy. It will set the offset value to 25 and will return invalid values.

add to _get function

    if 'offset' in params:
        del params['offset']

    def _get(self, request, params=dict(), limit=None):
        """
        GET Operation that supports paging for FMC REST API. In case of authentication issues session will be refreshed
        :param request: URL of request that should be performed
        :param params: dict of parameters for http request
        :param limit: set custom limit for paging. If not set, api will default to 25
        :return: list of requests.Response objects
        """
        if 'offset' in params:
            del params['offset']
        responses = list()
        response = self._get_request(request, params, limit)
        responses.append(response)
        payload = response.json()
        if 'paging' in payload.keys():
            pages = int(payload['paging']['pages'])
            limit = int(payload['paging']['limit'])
            for i in range(1, pages, 1):
                params['offset'] = str(int(i) * limit)
                response_page = self._get_request(request, params, limit)
                responses.append(response_page)
        return responses
kaisero commented 4 years ago

The issue you are mentioning was caused by initializing the dict incorrectly, this has been fixed in my repo, therefore I will not merge the changes into FireREST.