Skip to content

Commit

Permalink
Merge pull request #261 from TheHive-Project/feature/add-basic-github…
Browse files Browse the repository at this point in the history
…-actions

Add basic ci workflow
  • Loading branch information
Kamforka authored Nov 18, 2022
2 parents d2665a2 + c98c2d7 commit 1ef491d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --no-cache-dir -U pip .['dev']
- name: Lint check with flake8
run: |
flake8 setup.py thehive4py/ tests/
- name: Format check with black
run: |
black --diff setup.py thehive4py/ tests/
- name: Type check with mypy
run: |
mypy --install-types --non-interactive thehive4py/ tests/ &> /dev/null
mypy setup.py thehive4py/ tests/
# the pip-audit step will become much cleaner after migrating to pyproject.toml
- name: CVE check with pip-audit
run: |
python -m venv auditvenv/ && auditvenv/bin/pip install --no-cache-dir -U pip . &> /dev/null
auditvenv/bin/pip freeze > audit-requirements
pip-audit -r audit-requirements
- name: Security check with bandit
run: |
bandit -r setup.py thehive4py/
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ def parse_version():
REQUIREMENTS = ["requests>=2.27"]


EXTRAS_REQUIRE = {"lint": ["flake8", "black", "mypy"], "test": ["pytest"]}
EXTRAS_REQUIRE["dev"] = EXTRAS_REQUIRE["lint"] + EXTRAS_REQUIRE["test"]
EXTRAS_REQUIRE = {
"audit": ["pip-audit", "bandit"],
"lint": ["flake8", "black", "mypy", "pip-audit"],
"test": ["pytest"],
}
EXTRAS_REQUIRE["dev"] = (
EXTRAS_REQUIRE["lint"] + EXTRAS_REQUIRE["test"] + EXTRAS_REQUIRE["audit"]
)


def read(fname):
Expand Down
2 changes: 1 addition & 1 deletion thehive4py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(

@property
def session_organisation(self) -> Optional[str]:
return self.session.headers.get("X-Organisation")
return self.session.headers.get("X-Organisation") # type:ignore

@session_organisation.setter
def session_organisation(self, organisation: Optional[str] = None):
Expand Down
3 changes: 2 additions & 1 deletion thehive4py/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime as dt
import time
from typing import Optional


def now_to_ts() -> int:
Expand All @@ -12,6 +13,6 @@ def dt_to_ts(datetime: dt.datetime) -> int:
return int(datetime.timestamp() * 1000)


def ts_to_dt(timestamp: int, tz: dt.timezone = None) -> dt.datetime:
def ts_to_dt(timestamp: int, tz: Optional[dt.timezone] = None) -> dt.datetime:
"""Convert TheHive timestamp to datetime object."""
return dt.datetime.fromtimestamp(timestamp / 1000.0, tz=tz)
5 changes: 2 additions & 3 deletions thehive4py/query/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections import UserDict
from logging import Filter


class FilterExpr(UserDict):
Expand All @@ -11,7 +10,7 @@ def __and__(self, other: "FilterExpr") -> "FilterExpr":
args = self.get("_and", [self]) + other.get("_and", [other])
return FilterExpr(_and=args)

def __or__(self, other: "FilterExpr") -> "FilterExpr":
def __or__(self, other: "FilterExpr") -> "FilterExpr": # type:ignore
if not isinstance(other, FilterExpr):
self._raise_type_error("|", self, other)
args = self.get("_or", [self]) + other.get("_or", [other])
Expand Down Expand Up @@ -89,4 +88,4 @@ def __init__(self, field: str, end: int):

class After(FilterExpr):
def __init__(self, field: str, start: int):
super().__init__(_between={"_field": field, "_from": start})
super().__init__(_between={"_field": field, "_from": start})
2 changes: 1 addition & 1 deletion thehive4py/query/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SortExpr(UserDict):
def __and__(self, other: "SortExpr") -> "SortExpr":
return self._concat_expressions("&", self, other)

def __or__(self, other: "SortExpr") -> "SortExpr":
def __or__(self, other: "SortExpr") -> "SortExpr": # type:ignore
return self._concat_expressions("|", self, other)

def _concat_expressions(
Expand Down

0 comments on commit 1ef491d

Please sign in to comment.