Пример #1
0
    def update(self, entry_id, body):
        """Does a PUT request to /v1.1/whitelists/geolocations/{entry_id}/update.

        Update a Geo Location in the Whitelist

        Args:
            entry_id (string): a unique identifier for the Geo Location;
                opaque but likely a GUID
            body (GeoLocation): TODO: type description here. Example: 

        Returns:
            UpdateResponse1: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/v1.1/whitelists/geolocations/{entry_id}/update'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {'entry_id': entry_id})
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.put(
            _query_url,
            headers=_headers,
            parameters=APIHelper.json_serialize(body))
        CustomAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise ReturnException(
                'Unexpected error in API call. See HTTP response body for details.',
                _context)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body,
                                          UpdateResponse1.from_dictionary)
Пример #2
0
    def register_new_user(self, body):
        """Does a POST request to /v1.1/register.

        ONLY AVAILABLE when Bouncer is started with the `--testing`
        parameter.
        Register a new user with this instance of Bouncer.

        Args:
            body (RegisterNewUserRequest): TODO: type description here.
                Example: 

        Returns:
            RegisterNewUserResponse: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/v1.1/register'
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.post(
            _query_url,
            headers=_headers,
            parameters=APIHelper.json_serialize(body))
        CustomAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise ReturnException(
                'Unexpected error in API call. See HTTP response body for details.',
                _context)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(
            _context.response.raw_body,
            RegisterNewUserResponse.from_dictionary)
Пример #3
0
    def create(self, body):
        """Does a POST request to /v1.1/whitelists/geolocations/create.

        Create a Geo Location in the Whitelist. When POSTed-to this endpoint,
        Bouncer scans `geolist.txt` for any IPs matching the Country Code (CC)
        in the POSTed object and, for each: Bouncer will create a new
        ipaddress in this list (black- or white-list).

        Args:
            body (GeoLocation): TODO: type description here. Example: 

        Returns:
            CreateResponse1: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/v1.1/whitelists/geolocations/create'
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'content-type': 'application/json; charset=utf-8'
        }

        # Prepare and execute request
        _request = self.http_client.post(
            _query_url,
            headers=_headers,
            parameters=APIHelper.json_serialize(body))
        CustomAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise ReturnException(
                'Unexpected error in API call. See HTTP response body for details.',
                _context)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body,
                                          CreateResponse1.from_dictionary)
Пример #4
0
    def search(self,
                search_filter):
        """Does a GET request to /v1.1/blacklists/ipaddresses/filter/{search_filter}.

        Search for IP Addresses in the Blacklist

        Args:
            search_filter (string): an comma-separated lsit of IP addresses in
                CIDR format (`192.168.100.14/24`) except with `/` replaced by
                `+`

        Returns:
            SearchResponse: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/v1.1/blacklists/ipaddresses/filter/{search_filter}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'search_filter': search_filter
        })
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json'
        }

        # Prepare and execute request
        _request = self.http_client.get(_query_url, headers=_headers)
        CustomAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise ReturnException('Unexpected error in API call. See HTTP response body for details.', _context)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body, SearchResponse.from_dictionary)
Пример #5
0
    def get_details(self,
                    entry_id):
        """Does a GET request to /v1.1/blacklists/ipaddresses/{entry_id}.

        Get Details of an IP Address Entry in the Blacklist

        Args:
            entry_id (string): a unique identifier for the IP Address; opaque
                but likely a GUID

        Returns:
            GetDetailsResponse: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/v1.1/blacklists/ipaddresses/{entry_id}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'entry_id': entry_id
        })
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json'
        }

        # Prepare and execute request
        _request = self.http_client.get(_query_url, headers=_headers)
        CustomAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise ReturnException('Unexpected error in API call. See HTTP response body for details.', _context)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body, GetDetailsResponse.from_dictionary)
Пример #6
0
    def test_for_list_membership(self, ip_address):
        """Does a GET request to /v1.1/check/{ip_address}.

        Check if an IP Address is Already White- or Black-Listed

        Args:
            ip_address (string): the IP address to check

        Returns:
            TestForListMembershipResponse: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/v1.1/check/{ip_address}'
        _url_path = APIHelper.append_url_with_template_parameters(
            _url_path, {'ip_address': ip_address})
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {'accept': 'application/json'}

        # Prepare and execute request
        _request = self.http_client.get(_query_url, headers=_headers)
        CustomAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise ReturnException(
                'Unexpected error in API call. See HTTP response body for details.',
                _context)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(
            _context.response.raw_body,
            TestForListMembershipResponse.from_dictionary)
Пример #7
0
    def all_contents(self):
        """Does a GET request to /v1.1/whitelists.

        This will list the entire contents of the Whitelist including both IP
        Addresses and Geo Locations.

        Returns:
            AllContentsResponse: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/v1.1/whitelists'
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {'accept': 'application/json'}

        # Prepare and execute request
        _request = self.http_client.get(_query_url, headers=_headers)
        CustomAuth.apply(_request)
        _context = self.execute_request(_request)

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise ReturnException(
                'Unexpected error in API call. See HTTP response body for details.',
                _context)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body,
                                          AllContentsResponse.from_dictionary)