-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
689 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI | ||
on: [pull_request] | ||
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: scripts/ci.py lint | ||
- name: Format check with black | ||
run: scripts/ci.py format | ||
- name: Type check with mypy | ||
run: scripts/ci.py type | ||
- name: CVE check with pip-audit | ||
run: scripts/ci.py cve | ||
- name: Security check with bandit | ||
run: scripts/ci.py security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# experimental (works from the terminal but not from vscode and possibly from other IDEs) | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: ci-checks | ||
name: ci-checks | ||
entry: scripts/ci.py | ||
language: system | ||
pass_filenames: false | ||
always_run: true | ||
stages: [push] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[build-system] | ||
requires = ["setuptools", "setuptools-scm"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "thehive4py" | ||
description = "Python client for TheHive5" | ||
version = "2.0.0b4" | ||
requires-python = ">=3.8" | ||
dependencies = ["requests>=2.27"] | ||
readme = "README.md" | ||
keywords = ["thehive5", "api", "client"] | ||
license = { text = "AGPL-V3" } | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: Information Technology", | ||
"Natural Language :: English", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"License :: OSI Approved :: GNU Affero General Public License v3", | ||
] | ||
authors = [{ name = "Szabolcs Antal", email = "[email protected]" }] | ||
|
||
[project.optional-dependencies] | ||
audit = ["bandit", "pip-audit"] | ||
build = ["build", "twine"] | ||
lint = ["black", "flake8", "mypy", "pre-commit"] | ||
test = ["pytest"] | ||
dev = ["thehive4py[audit, lint, test, build]"] | ||
|
||
[tool.setuptools.packages.find] | ||
include = ["thehive4py*"] | ||
|
||
[tool.setuptools.package-data] | ||
thehive4py = ["py.typed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
import subprocess | ||
|
||
|
||
def _run_subprocess( | ||
args: str, | ||
init_message: str, | ||
success_message: str, | ||
error_message: str, | ||
verbose=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 verbose: | ||
print(indented_process_output) | ||
|
||
print(success_message) | ||
|
||
|
||
def run_all(verbose=False): | ||
print("Run all deployment tasks...") | ||
run_build(verbose=verbose) | ||
run_publish(verbose=verbose) | ||
print("All tasks succeeded!") | ||
|
||
|
||
def run_build(verbose: bool): | ||
_run_subprocess( | ||
args=("rm -rf build/ dist/ && python -m build --sdist --wheel"), | ||
init_message="Building the package with the build module...", | ||
success_message="Package build succeeded!", | ||
error_message="Package build failed due to:", | ||
verbose=verbose, | ||
) | ||
|
||
|
||
def run_publish(verbose: bool): | ||
_run_subprocess( | ||
args=("echo 'Publish command is not implemented yet...' && exit 1 "), | ||
init_message="Publishing the package with twine...", | ||
success_message="Publish succeeded!", | ||
error_message="Publish failed due to:", | ||
verbose=verbose, | ||
) | ||
|
||
|
||
def parse_arguments(): | ||
main_parser = argparse.ArgumentParser( | ||
prog="thehive4py-cd", | ||
description="run all cd tasks or use sub commands to run cd tasks individually", | ||
) | ||
main_parser.add_argument( | ||
"-v", | ||
"--verbose", | ||
action="store_true", | ||
default=False, | ||
help="generate verbose output", | ||
) | ||
main_parser.set_defaults(func=run_all) | ||
|
||
subparsers = main_parser.add_subparsers(help="commands") | ||
subparser_options = [ | ||
{ | ||
"name": "build", | ||
"help": "task to build the package", | ||
"default_func": run_build, | ||
}, | ||
{ | ||
"name": "publish", | ||
"help": "task to publish the package", | ||
"default_func": run_publish, | ||
}, | ||
] | ||
|
||
for subparser_option in subparser_options: | ||
_subparser = subparsers.add_parser( | ||
name=subparser_option["name"], | ||
help=subparser_option["help"], | ||
parents=[main_parser], | ||
add_help=False, | ||
) | ||
_subparser.set_defaults(func=subparser_option["default_func"]) | ||
|
||
return main_parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_arguments() | ||
args.func(verbose=args.verbose) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
import subprocess | ||
|
||
|
||
def _run_subprocess( | ||
args: str, | ||
init_message: str, | ||
success_message: str, | ||
error_message: str, | ||
verbose=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 verbose: | ||
print(indented_process_output) | ||
|
||
print(success_message) | ||
|
||
|
||
def check_all(verbose=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) | ||
print("All checks succeeded!") | ||
|
||
|
||
def check_lint(verbose=False): | ||
_run_subprocess( | ||
args="flake8 thehive4py/ tests/", | ||
init_message="Run lint checks with flake8...", | ||
success_message="Lint checks succeeded!", | ||
error_message="Lint checks failed due to:", | ||
verbose=verbose, | ||
) | ||
|
||
|
||
def check_format(verbose=False): | ||
_run_subprocess( | ||
args="black --diff thehive4py/ tests/", | ||
init_message="Run format checks with black...", | ||
success_message="Format checks succeeded!", | ||
error_message="Lint checks failed due to:", | ||
verbose=verbose, | ||
) | ||
|
||
|
||
def check_type(verbose=False): | ||
_run_subprocess( | ||
args="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, | ||
) | ||
|
||
|
||
def check_cve(verbose=False): | ||
_run_subprocess( | ||
args="pip-audit .", | ||
init_message="Run CVE checks with pip-audit...", | ||
success_message="CVE checks succeeded!", | ||
error_message="CVE checks failed due to:", | ||
verbose=verbose, | ||
) | ||
|
||
|
||
def check_security(verbose=False): | ||
_run_subprocess( | ||
args="bandit -r thehive4py/", | ||
init_message="Run security checks with bandit...", | ||
success_message="Security checks succeeded!", | ||
error_message="Security checks failed due to:", | ||
verbose=verbose, | ||
) | ||
|
||
|
||
def parse_arguments(): | ||
main_parser = argparse.ArgumentParser( | ||
prog="thehive4py-ci", | ||
description=( | ||
"run all ci checks or use sub commands to run ci checks individually" | ||
), | ||
) | ||
main_parser.add_argument( | ||
"-v", | ||
"--verbose", | ||
action="store_true", | ||
default=False, | ||
help="generate 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, | ||
) | ||
_subparser.set_defaults(func=subparser_option["default_func"]) | ||
|
||
return main_parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_arguments() | ||
args.func(verbose=args.verbose) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.