Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

293-actualize-main-with-develop #297

Merged
merged 33 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ef1a961
Merge branch 'release/2.0.0b4' into develop
nadouani Jan 20, 2023
8f54d72
#273 - Add page manipulation methods to case endpoint
Kamforka Feb 11, 2023
7d08f4c
#273 - Add missing delete page test
Kamforka Feb 11, 2023
475a549
Add central test config and refactor test instance management
Kamforka Feb 11, 2023
964ff54
Integration test pipeline attempt #1
Kamforka Feb 11, 2023
8289c7c
remove unused logging
Kamforka Feb 11, 2023
a554b30
Add pytest run and hive service container
Kamforka Feb 12, 2023
d8b0f54
hive container check
Kamforka Feb 12, 2023
3fe5f4a
better specify test image name
Kamforka Feb 12, 2023
f2b17b7
integration test attemp #1
Kamforka Feb 12, 2023
8850672
integration test attemp #1
Kamforka Feb 12, 2023
7bddeb7
integration test attemp #2
Kamforka Feb 12, 2023
d4039a8
try to pull the image only
Kamforka Feb 12, 2023
fcca3a3
increase startup timeout and add second docker check
Kamforka Feb 12, 2023
05e6470
debug exiting container
Kamforka Feb 12, 2023
4943204
docker debug
Kamforka Feb 12, 2023
a151f56
try again with multi platform docker image
Kamforka Feb 12, 2023
fd1eeb5
get rid of debugging steps
Kamforka Feb 12, 2023
c665410
add coverage report
Kamforka Feb 14, 2023
6803b83
add missing pytest coverage dependency
Kamforka Feb 14, 2023
b8e7c36
Merge pull request #275 from TheHive-Project/273-support-cases-page
Kamforka Mar 1, 2023
ad37309
277 - Fix InputAlert and InputProcedure type defs
Kamforka Mar 21, 2023
1ab5092
Rename CI action to static-checks
Kamforka Mar 27, 2023
7ad3670
make integration tests action optional
Kamforka Mar 27, 2023
071dfc6
Merge pull request #280 from TheHive-Project/277-inaccurate-type-defi…
Kamforka Sep 18, 2023
09145f4
#276 - formatting changes
Kamforka Sep 25, 2023
2626e3d
#276 - update tests to support v5.2.x
Kamforka Sep 25, 2023
2e0fad5
#276 - Remove unnecessary service container and add explicit docker l…
Kamforka Sep 25, 2023
764a902
#276 - Refactor ci script
Kamforka Sep 25, 2023
b45a9e9
#276 - black format changes
Kamforka Sep 25, 2023
75123aa
#276 - refactor ci script
Kamforka Sep 26, 2023
af057bf
#276 - fix typing compatibility for py3.8
Kamforka Sep 26, 2023
9de3457
Merge pull request #276 from TheHive-Project/feature/automate-integra…
Kamforka Sep 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .coveragerc

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: integration-tests [experimental]
on: [pull_request]
jobs:
integration_tests:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install dependencies
run: pip install --no-cache-dir -U pip .['test']
- name: Docker login
run: docker login -u kamforka -p ${{ secrets.DOCKER_TOKEN }}
- name: Run integration tests
run: scripts/ci.py --test
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml → .github/workflows/static-checks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: static-checks
on: [pull_request]
jobs:
build:
Expand All @@ -15,12 +15,12 @@ jobs:
- name: Install dependencies
run: pip install --no-cache-dir -U pip .['dev']
- name: Lint check with flake8
run: scripts/ci.py lint
run: scripts/ci.py --lint
- name: Format check with black
run: scripts/ci.py format
run: scripts/ci.py --format
- name: Type check with mypy
run: scripts/ci.py type
run: scripts/ci.py --type
- name: CVE check with pip-audit
run: scripts/ci.py cve
run: scripts/ci.py --cve
- name: Security check with bandit
run: scripts/ci.py security
run: scripts/ci.py --security
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ authors = [{ name = "Szabolcs Antal", email = "antalszabolcs01@gmail.com" }]
audit = ["bandit", "pip-audit"]
build = ["build", "twine"]
lint = ["black", "flake8", "mypy", "pre-commit"]
test = ["pytest"]
test = ["pytest", "pytest-cov"]
dev = ["thehive4py[audit, lint, test, build]"]

[tool.setuptools.packages.find]
include = ["thehive4py*"]

[tool.setuptools.package-data]
thehive4py = ["py.typed"]

[tool.coverage.run]
omit = ["tests/*", "thehive4py/types/*"]
167 changes: 90 additions & 77 deletions scripts/ci.py
Original file line number Diff line number Diff line change
@@ -1,141 +1,154 @@
#!/usr/bin/env python
import argparse
import subprocess
from typing import List


def _run_subprocess(
args: str,
command: str,
init_message: str,
success_message: str,
error_message: str,
verbose=False,
quiet=False,
):
print(init_message)
proc = subprocess.run(args, shell=True, capture_output=True)

process_output = proc.stdout.decode() or proc.stderr.decode()
indented_process_output = "\n".join(
[f"\t{output_line}" for output_line in process_output.splitlines()]
)

if proc.returncode != 0:
exit_message = "\n".join([error_message, indented_process_output])
exit(exit_message)
if not quiet:
stdout = stderr = None
else:
stdout = stderr = subprocess.DEVNULL

if verbose:
print(indented_process_output)
import shlex

print(success_message)
try:
subprocess.run(shlex.split(command), stdout=stdout, stderr=stderr, check=True)
except subprocess.CalledProcessError as err:
error_output = (
f"ERROR: Execution of command '{command}' returned: {err.returncode}\n"
)
print(error_output)
exit(err.returncode)
else:
print(success_message, end="\n\n")


def check_all(verbose=False):
def check_all(quiet=False):
print("Run all checks...")
check_lint(verbose=verbose)
check_format(verbose=verbose)
check_type(verbose=verbose)
check_cve(verbose=verbose)
check_security(verbose=verbose)
check_lint(quiet=quiet)
check_format(quiet=quiet)
check_type(quiet=quiet)
check_cve(quiet=quiet)
check_security(quiet=quiet)
print("All checks succeeded!")


def check_lint(verbose=False):
def check_lint(quiet=False):
_run_subprocess(
args="flake8 thehive4py/ tests/",
command="flake8 thehive4py/ tests/",
init_message="Run lint checks with flake8...",
success_message="Lint checks succeeded!",
error_message="Lint checks failed due to:",
verbose=verbose,
quiet=quiet,
)


def check_format(verbose=False):
def check_format(quiet=False):
_run_subprocess(
args="black --diff thehive4py/ tests/",
command="black --check thehive4py/ tests/",
init_message="Run format checks with black...",
success_message="Format checks succeeded!",
error_message="Lint checks failed due to:",
verbose=verbose,
quiet=quiet,
)


def check_type(verbose=False):
def check_type(quiet=False):
_run_subprocess(
args="mypy --install-types --non-interactive thehive4py/",
command="mypy --install-types --non-interactive thehive4py/",
init_message="Run type checks with mypy...",
success_message="Type checks succeeded!",
error_message="Type checks failed due to:",
verbose=verbose,
quiet=quiet,
)


def check_cve(verbose=False):
def check_cve(quiet=False):
_run_subprocess(
args="pip-audit .",
command="pip-audit .",
init_message="Run CVE checks with pip-audit...",
success_message="CVE checks succeeded!",
error_message="CVE checks failed due to:",
verbose=verbose,
quiet=quiet,
)


def check_security(verbose=False):
def check_security(quiet=False):
_run_subprocess(
args="bandit -r thehive4py/",
command="bandit -r thehive4py/",
init_message="Run security checks with bandit...",
success_message="Security checks succeeded!",
error_message="Security checks failed due to:",
verbose=verbose,
quiet=quiet,
)


def check_test(quiet=False):
_run_subprocess(
command="pytest -v --cov",
init_message="Run integration tests with pytest...",
success_message="Integration tests succeeded!",
quiet=quiet,
)


def parse_arguments():
main_parser = argparse.ArgumentParser(
def build_check_options() -> List[dict]:
return [
{"name": "lint", "help": "run lint checks", "check": check_lint},
{"name": "format", "help": "run format checks", "check": check_format},
{"name": "type", "help": "run type checks", "check": check_type},
{"name": "cve", "help": "run cve checks", "check": check_cve},
{"name": "security", "help": "run security checks", "check": check_security},
{"name": "test", "help": "run integration tests", "check": check_test},
]


def parse_arguments(check_options: List[dict]):
parser = argparse.ArgumentParser(
prog="thehive4py-ci",
description=(
"run all ci checks or use sub commands to run ci checks individually"
"run all ci checks except tests by default, "
"use options to run ci checks selectively"
),
)
main_parser.add_argument(
"-v",
"--verbose",
parser.add_argument(
"-q",
"--quiet",
action="store_true",
default=False,
help="generate verbose output",
help="silence verbose output",
)
main_parser.set_defaults(func=check_all)

subparsers = main_parser.add_subparsers(help="commands")
subparser_options = [
{"name": "lint", "help": "run lint checks only", "default_func": check_lint},
{
"name": "format",
"help": "run format checks only",
"default_func": check_format,
},
{"name": "type", "help": "run type checks only", "default_func": check_type},
{"name": "cve", "help": "run cve checks only", "default_func": check_cve},
{
"name": "security",
"help": "run security checks",
"default_func": check_security,
},
]

for subparser_option in subparser_options:
_subparser = subparsers.add_parser(
name=subparser_option["name"],
help=subparser_option["help"],
parents=[main_parser],
add_help=False,
for check_option in check_options:
parser.add_argument(
f"--{check_option['name']}",
help=check_option["help"],
action="store_true",
)
_subparser.set_defaults(func=subparser_option["default_func"])

return main_parser.parse_args()
return parser.parse_args()


def main():
args = parse_arguments()
args.func(verbose=args.verbose)
check_options = build_check_options()
args = parse_arguments(check_options=check_options)

quiet = args.quiet

selective_checks = [
check_option["check"]
for check_option in check_options
if getattr(args, check_option["name"])
]

if selective_checks:
for check in selective_checks:
check(quiet=quiet)
else:
check_all(quiet=quiet)
print()


if __name__ == "__main__":
Expand Down
Loading