-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cisagov/first-commits
Boosh!
- Loading branch information
Showing
50 changed files
with
3,209 additions
and
313 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
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
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
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[pytest] | ||
addopts = -v -ra --cov | ||
addopts = -v -ra --cov --log-cli-level=INFO | ||
asyncio_default_fixture_loop_scope = session | ||
asyncio_mode = auto |
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
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
"""The example library.""" | ||
"""The cyhy_db package provides an interface to a CyHy database.""" | ||
|
||
# We disable a Flake8 check for "Module imported but unused (F401)" here because | ||
# although this import is not directly used, it populates the value | ||
# package_name.__version__, which is used to get version information about this | ||
# Python package. | ||
|
||
from ._version import __version__ # noqa: F401 | ||
from .example import example_div | ||
from .db import initialize_db | ||
|
||
__all__ = ["example_div"] | ||
__all__ = ["initialize_db"] |
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 @@ | ||
__version__ = "1.0.0" |
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,54 @@ | ||
"""CyHy database top-level functions.""" | ||
|
||
# Third-Party Libraries | ||
from beanie import Document, View, init_beanie | ||
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase | ||
|
||
from .models import ( | ||
CVEDoc, | ||
HostDoc, | ||
HostScanDoc, | ||
KEVDoc, | ||
NotificationDoc, | ||
PlaceDoc, | ||
PortScanDoc, | ||
ReportDoc, | ||
RequestDoc, | ||
SnapshotDoc, | ||
SystemControlDoc, | ||
TallyDoc, | ||
TicketDoc, | ||
VulnScanDoc, | ||
) | ||
|
||
ALL_MODELS: list[type[Document] | type[View] | str] = [ | ||
CVEDoc, | ||
HostDoc, | ||
HostScanDoc, | ||
KEVDoc, | ||
NotificationDoc, | ||
PlaceDoc, | ||
PortScanDoc, | ||
RequestDoc, | ||
ReportDoc, | ||
SnapshotDoc, | ||
SystemControlDoc, | ||
TallyDoc, | ||
TicketDoc, | ||
VulnScanDoc, | ||
] | ||
|
||
# Note: ScanDoc is intentionally excluded from the list of models to be imported | ||
# or initialized because it is an abstract base class. | ||
|
||
|
||
async def initialize_db(db_uri: str, db_name: str) -> AsyncIOMotorDatabase: | ||
"""Initialize the database.""" | ||
try: | ||
client: AsyncIOMotorClient = AsyncIOMotorClient(db_uri) | ||
db: AsyncIOMotorDatabase = client[db_name] | ||
await init_beanie(database=db, document_models=ALL_MODELS) | ||
return db | ||
except Exception as e: | ||
print(f"Failed to initialize database with error: {e}") | ||
raise |
Oops, something went wrong.