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

First commits to create cyhy-db #5

Merged
merged 140 commits into from
Oct 21, 2024
Merged

First commits to create cyhy-db #5

merged 140 commits into from
Oct 21, 2024

Conversation

felddy
Copy link
Member

@felddy felddy commented Sep 25, 2024

🗣 Description

This PR contains the initial functionality of the cyhy-db module, which provides a object model for accessing the various document collections in a Cyber Hygiene database.

This PR also includes an assortment of unit tests, though more testing will likely be added later.

💭 Motivation and context

We have two main motivations here:

  1. To migrate from our legacy data model which was built on outdated Python 2 libraries to a more modern model that uses Python 3 (hello Beanie!)
  2. To break the CyHy database model out into its own repository and module thus making it more testable and maintainable.

🧪 Testing

All unit tests currently pass in pytest. This code has also been partially tested by its use in the cyhy-kevsync module (initial PR coming soon).

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All future TODOs are captured in issues, which are referenced
    in code comments.
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All relevant repo and/or project documentation has been updated
    to reflect the changes in this PR.
  • Tests have been added and/or modified to cover the changes in this PR.
  • All new and existing tests pass.

✅ Pre-merge checklist

  • Finalize version.

✅ Post-merge checklist

  • Create a release.
  • Create (or move) v1 tag that points to new release.

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
Add comments to severity calculation.
This commit refactors the CVE model and test in the `cyhy_db` package. The changes include:
- Replacing the `odmantic` library with `mongoengine` for the model definition.
- Updating the field types and constraints in the CVE model.
- Removing the `calculate_severity` method and integrating the severity calculation directly in the `save` method.
- Updating the test cases to reflect the changes in the model.
@felddy felddy requested a review from mcdonnnj as a code owner October 11, 2024 17:31
Copy link
Member

@jsf9k jsf9k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the quibbles below, when I run ./setup-env -p 3.13.0 -f I get an error:

src/cyhy_db/models/tally_doc.py:41: error: Incompatible types in assignment (expression has type "str", base class "Document" defined the type as "PydanticObjectId | None")  [assignment]

I did confirm that all tests pass by running pytest -vs --mongo-express.

.github/dependabot.yml Show resolved Hide resolved
.github/workflows/build.yml Outdated Show resolved Hide resolved
.github/workflows/build.yml Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
felddy and others added 4 commits October 11, 2024 17:09
- Remove unnecessary pins.
- Remove unused dependencies.
- `coveralls` comment is no longer required.
- `setuptools` pin and comment is no longer required.

See:
- cisagov/cyhy-config@8df2e69
Add a mypy ignore directive to TallyDoc.
Document all uses of this directive in a new issue.
@felddy
Copy link
Member Author

felddy commented Oct 15, 2024

In addition to the quibbles below, when I run ./setup-env -p 3.13.0 -f I get an error:

src/cyhy_db/models/tally_doc.py:41: error: Incompatible types in assignment (expression has type "str", base class "Document" defined the type as "PydanticObjectId | None")  [assignment]

I was able to replicate this. I've applied the same "fix" to TallyDoc that we used in the other model id fields. I've opened a new issue to track why this is the case, and added comments pointing to the issue.

See:

@jsf9k
Copy link
Member

jsf9k commented Oct 15, 2024

In addition to the quibbles below, when I run ./setup-env -p 3.13.0 -f I get an error:

src/cyhy_db/models/tally_doc.py:41: error: Incompatible types in assignment (expression has type "str", base class "Document" defined the type as "PydanticObjectId | None")  [assignment]

I was able to replicate this. I've applied the same "fix" to TallyDoc that we used in the other model id fields. I've opened a new issue to track why this is the case, and added comments pointing to the issue.

See:

Thank you! I was able to verify that I am now able to run ./setup-env -p 3.13.0 -f with no errors.

Add a mypy ignore directive to TallyDoc.
Document all uses of this directive in a new issue.
Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strong work! 💪 💼

Please take a look at the couple of minor thangs I noticed.

src/cyhy_db/models/request_doc.py Outdated Show resolved Hide resolved
src/cyhy_db/models/scan_doc.py Outdated Show resolved Hide resolved
dav3r and others added 9 commits October 16, 2024 13:23
The reserved word `from` was replaced with `from_` in `TicketDoc`.  This follows that pattern.

Co-authored-by: David Redmin <[email protected]>
Co-authored-by: Jeremy Frasier <[email protected]>
This breaking change is documented in:
- Data migration from `cyhy-core` database #8

Co-authored-by: David Redmin <[email protected]>
In an attempt to reach 100% coverage I broke out the various ways `reset_latestest_by_ip` could be called... to no avail.

I believe this issue explains why the list comprehension shows a branch part as uncovered:
- nedbat/coveragepy#1617
Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

@felddy felddy merged commit 3faa585 into develop Oct 21, 2024
23 checks passed
@felddy felddy deleted the first-commits branch October 21, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This issue or pull request improves or adds to documentation hacktoberfest-accepted Pull request that should count toward Hacktoberfest participation improvement This issue or pull request will add or improve functionality, maintainability, or ease of use
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants