Skip to content

Commit

Permalink
261 add extra parameters in the query api calls (#264)
Browse files Browse the repository at this point in the history
* chore: Format correctly several files

* feat: Add ip_as_string feature

* doc: Update docs

* fix: Fix tests
  • Loading branch information
angel-devo committed Apr 11, 2024
1 parent 1d47ee8 commit fe900ae
Show file tree
Hide file tree
Showing 28 changed files with 605 additions and 223 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ jobs:
version: ["3.8", "3.9"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install -e .
- name: Install certificates
run: |
mkdir -p certs/us
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.2.0] - 2024-04-10

### Added

- Add ip-as-string flag to the API client to return the IP address as a string instead of an integer.

### Changed

- `cryptography` dependency upgraded from `cryptography~=42.0.2` to `cryptography~=42.0.5`
- `msgpack` dependency upgraded from `msgpack~=1.0.7` to `msgpack~=1.0.8`
- `pipdeptree` dependency upgraded from `pipdeptree~=2.14.0` to `pipdeptree~=2.17.0`
- `pyopenssl` dependency upgraded from `pyopenssl~=24.0` to `pyopenssl~=24.1.0`
- `pytest-cov` dependency upgraded from `pytest-cov~=4.1.0` to `pytest-cov~=5.0.0`
- `pytest` dependency upgraded from `pytest~=7.4.4` to `pytest~=8.1.1`
- `responses` dependency upgraded from `responses~=0.24` to `responses~=0.25.0`

## [5.1.10] - 2024-02-16

### Changed
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ The Devo SDK for Python requires Python 3.8+
You can install the Devo SDK by using `easy_install` or `pip`:

```console
#option 1
# option 1
easy_install devo-sdk

#option 2
# option 2
pip install devo-sdk
```

You can use sources files, cloning the project too:

```console
#option 3
# option 3
python setup.py install

#option 4
# option 4
pip install .

#option 5 - dev option
# option 5 - dev option
pip install -e .
```

Expand Down Expand Up @@ -120,21 +120,21 @@ The SDK uses Pytest for testing. This is a powerful tool for testing Python code
Install the testing requirements:

```console
~/projects/devo-python-sdk > pip install -r requirements-test.txt
pip install -r requirements-test.txt
```

You can run tests from the `tests` folder of SDK

```console
~/projects/devo-python-sdk/tests > pytest
pytest
```

Its normal that TCP tests fails in clients or not Devo developers systems.

You can add the option `--cov` to create a coverage report.

```console
~/projects/devo-python-sdk/tests > pytest --cov
pytest --cov
```

Check the [pytest-cov documentation](https://pytest-cov.readthedocs.io/) for more details.
Expand All @@ -144,19 +144,19 @@ The tests are divided into unit and integration tests. The integration tests req
To run the unit tests only, you can use the `unit` folder:

```console
~/projects/devo-python-sdk/tests > pytest unit
pytest unit
```

To run the integration tests only, you can use the `integration` folder:

```console
~/projects/devo-python-sdk/tests > pytest integration
pytest integration
```

You can also run the test for just one module. This is a useful feature if you are developing functionality in just one module.

```console
~/projects/devo-python-sdk/tests > pytest unit/test_sender_encoding.py
pytest unit/test_sender_encoding.py
```

### Contact Us
Expand Down
2 changes: 1 addition & 1 deletion devo/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__description__ = "Devo Python Library."
__url__ = "http://www.devo.com"
__version__ = "5.1.10"
__version__ = "5.2.0"
__author__ = "Devo"
__author_email__ = "support@devo.com"
__license__ = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions devo/api/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""Main class for pull data from Devo API (Client)."""

import calendar
import hashlib
import hmac
Expand Down Expand Up @@ -430,6 +431,7 @@ def query(
limit=None,
offset=None,
comment=None,
ip_as_string=False,
):
"""
Query API by a custom query
Expand All @@ -452,6 +454,7 @@ def query(
"offset": offset,
"destination": self.config.destination,
"keepAliveToken": self.config.keepAliveToken,
"ip_as_string": ip_as_string,
}

if not self.stream_available(self.config.response) or not self.config.stream:
Expand Down Expand Up @@ -682,6 +685,9 @@ def _get_payload(query, query_id, dates, opts):
"token": opts["keepAliveToken"],
}

if opts["ip_as_string"]:
payload["ipAsString"] = opts["ip_as_string"]

return json.dumps(payload)

def _get_headers(self, data):
Expand Down
1 change: 1 addition & 0 deletions devo/api/processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""Defaults proccessors of API data."""

import json


Expand Down
6 changes: 4 additions & 2 deletions devo/api/scripts/client_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""CLI for use Devo API from shell command line."""

import os
import sys

Expand Down Expand Up @@ -84,6 +85,7 @@ def cli(version):
@click.option("--timeZone", help="Timezone info. For valid formats see API README")
@click.option("--verify", type=bool, help="Verify certificates")
@click.option("--debug/--no-debug", help="For testing purposes", default=False)
@click.option("--ip-as-string", is_flag=True, help="Return IPs as strings", default=False)
def query(**kwargs):
"""Perform query by query string"""
api, config = configure(kwargs)
Expand Down Expand Up @@ -121,9 +123,9 @@ def query(**kwargs):
print_error(ERROR_MSGS["binary_format_requires_output"], show_help=True)
exit()

reponse = api.query(query=config["query"], dates=dates)
response = api.query(query=config["query"], dates=dates, ip_as_string=config["ip_as_string"])

process_response(reponse, config)
process_response(response, config)


def process_response(response, config):
Expand Down
1 change: 1 addition & 0 deletions devo/common/dates/dateoperations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
"""A collection of allowed operations on date parsing"""

from datetime import datetime as dt
from datetime import timedelta

Expand Down
3 changes: 2 additions & 1 deletion devo/common/generic/configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
""" Util for load generic config file in devo standars"""
"""Util for load generic config file in devo standars"""

import json
import os
import sys
Expand Down
3 changes: 2 additions & 1 deletion devo/common/logging/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
""" Generic function to logging events in Devo SDK """
"""Generic function to logging events in Devo SDK"""

import logging
import os
import sys
Expand Down
5 changes: 3 additions & 2 deletions devo/sender/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
""" File to group all the classes and functions related to the connection
and sending of data to Devo """
"""File to group all the classes and functions related to the connection
and sending of data to Devo"""

import errno
import logging
import select
Expand Down
3 changes: 2 additions & 1 deletion devo/sender/lookup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
""" File with utils for send Lookups to Devo """
"""File with utils for send Lookups to Devo"""

import csv
import re
import sys
Expand Down
3 changes: 2 additions & 1 deletion devo/sender/pfx_to_pem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
""" Util function to convert .pfx and .pkcs12 certs to key+cert+chain for
"""Util function to convert .pfx and .pkcs12 certs to key+cert+chain for
use in Python sockets"""

import tempfile

import OpenSSL.crypto
Expand Down

0 comments on commit fe900ae

Please sign in to comment.