Skip to content

Commit

Permalink
Add cyhy_db package and models
Browse files Browse the repository at this point in the history
Delete example package and files

Update Python version to 3.12 in build workflows

Update package name and description in setup.py

Update dependencies in setup.py
  • Loading branch information
felddy committed Jan 24, 2024
1 parent c455048 commit 2f4454a
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 290 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://coverage.readthedocs.io/en/latest/config.html

[run]
source = src/example
source = src/cyhy_db
omit =
branch = true

Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.12"
# We need the Go version and Go cache location for the actions/cache step,
# so the Go installation must happen before that.
- id: setup-go
Expand Down Expand Up @@ -155,15 +155,11 @@ jobs:
os:
- ubuntu-latest
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
include:
- os: ubuntu-20.04
python-version: "3.6"
steps:
- id: harden-runner
name: Harden the runner
Expand Down Expand Up @@ -224,7 +220,7 @@ jobs:
- id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.12"
- uses: actions/cache@v3
env:
BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\
Expand Down Expand Up @@ -264,15 +260,11 @@ jobs:
os:
- ubuntu-latest
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
include:
- os: ubuntu-20.04
python-version: "3.6"
steps:
- id: harden-runner
name: Harden the runner
Expand Down Expand Up @@ -324,15 +316,11 @@ jobs:
os:
- ubuntu-latest
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
include:
- os: ubuntu-20.04
python-version: "3.6"
steps:
- id: harden-runner
name: Harden the runner
Expand Down
26 changes: 15 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def get_version(version_file):


setup(
name="example",
name="cyhy-db",
# Versions should comply with PEP440
version=get_version("src/example/_version.py"),
description="Example Python library",
version=get_version("src/cyhy_db/_version.py"),
description="CyHy Database Python library",
long_description=readme(),
long_description_content_type="text/markdown",
# Landing page for CISA's cybersecurity mission
Expand Down Expand Up @@ -75,26 +75,30 @@ def get_version(version_file):
# that you indicate whether you support Python 2, Python 3 or both.
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
],
python_requires=">=3.6",
python_requires=">=3.8",
# What does your project relate to?
keywords="skeleton",
keywords=["cyhy", "database"],
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={"example": ["data/*.txt"]},
package_data={},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
include_package_data=True,
install_requires=["docopt", "schema", "setuptools >= 24.2.0"],
install_requires=[
"docopt == 0.6.2",
"odmantic == 1.0.0",
"schema == 0.7.5",
"setuptools >= 69.0.3",
],
extras_require={
"test": [
"pytest-asyncio",
"coverage",
# coveralls 1.11.0 added a service number for calls from
# GitHub Actions. This caused a regression which resulted in a 422
Expand All @@ -103,11 +107,11 @@ def get_version(version_file):
# 1.11.1 fixed this issue, but to ensure expected behavior we'll pin
# to never grab the regression version.
"coveralls != 1.11.0",
"docker == 7.0.0",
"pre-commit",
"pytest-cov",
"pytest",
]
},
# Conveniently allows one to run the CLI tool as `example`
entry_points={"console_scripts": ["example = example.example:main"]},
entry_points={},
)
1 change: 1 addition & 0 deletions src/cyhy_db/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1"
43 changes: 43 additions & 0 deletions src/cyhy_db/models/cve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from odmantic import Model, Field
from pydantic import ValidationInfo, field_validator
from typing import Literal

class CVE(Model):
id: str = Field(primary_field=True)
cvss_score: float
cvss_version: Literal["2.0", "3.0", "3.1"]
severity: Literal[1,2,3,4] = Field(default_factory=lambda: 1)

model_config = {
"collection": "cves"
}

@field_validator("cvss_score")
def validate_cvss_score(cls, v: float) -> float:
if v < 0.0 or v > 10.0:
raise ValueError("CVSS score must be between 0.0 and 10.0 inclusive")
return v

def calculate_severity(self):
if self.cvss_version == "2.0":
if self.cvss_score == 10:
self.severity = 4
elif self.cvss_score >= 7.0:
self.severity = 3
elif self.cvss_score >= 4.0:
self.severity = 2
else:
self.severity = 1
else: # 3.0 or 3.1
if self.cvss_score >= 9.0:
self.severity = 4
elif self.cvss_score >= 7.0:
self.severity = 3
elif self.cvss_score >= 4.0:
self.severity = 2
else:
self.severity = 1

async def save(self, engine):
self.calculate_severity()
await engine.save(self)
Empty file added src/cyhy_db/utils/__init__.py
Empty file.
9 changes: 0 additions & 9 deletions src/example/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions src/example/__main__.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/example/_version.py

This file was deleted.

1 change: 0 additions & 1 deletion src/example/data/secret.txt

This file was deleted.

103 changes: 0 additions & 103 deletions src/example/example.py

This file was deleted.

Loading

0 comments on commit 2f4454a

Please sign in to comment.