Skip to content

Commit

Permalink
added sql.upload_pm_cves, added 'sqlite3' as accepted value to sql.db…
Browse files Browse the repository at this point in the history
…_connect
  • Loading branch information
jake-lindsay-tfs committed Dec 4, 2024
1 parent 78858a9 commit 7ec04a1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ The final optional parameter is ```table_name```. If you want to specify a custo
| ```upload_pm_jobs``` | Patch Management | ```pm.list_jobs()``` | ```pm_jobs``` |
| ```upload_pm_job_results``` | Patch Management | ```pm.get_job_results()``` | ```pm_job_results_jobResults``` for job summaries and ```pm_job_results_assets``` for assets (key = jobResults.id -> assets.jobId)|
| ```upload_pm_job_runs``` | Patch Management | ```pm.get_job_runs()``` | ```pm_job_runs``` |
| ```upload_pm_cves``` | Patch Management | ```pm.lookup_cves()``` | ```pm_cves_for_qids``` |
| ```upload_cert_certs``` | Certificate View | ```cert.list_certs()``` | ```cert_certs``` for certificates and ```cert_assets``` for assets (key = certs.id -> assets.certId) |


Expand Down
7 changes: 6 additions & 1 deletion qualysdk/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@
upload_was_authentication_records,
upload_was_findings,
)
from .pm import upload_pm_jobs, upload_pm_job_results, upload_pm_job_runs
from .pm import (
upload_pm_jobs,
upload_pm_job_results,
upload_pm_job_runs,
upload_pm_cves,
)
from .cert import upload_cert_certs
2 changes: 2 additions & 0 deletions qualysdk/sql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def db_connect(
conn_str = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{db}"
case "sqlite":
conn_str = f"sqlite:///{db}"
case "sqlite3":
conn_str = f"sqlite:///{db}"
case _:
raise ValueError("Database type not supported.")

Expand Down
38 changes: 38 additions & 0 deletions qualysdk/sql/pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,41 @@ def upload_pm_job_runs(

# Upload the data:
return upload_data(df, table_name, cnxn, COLS, override_import_dt)


def upload_pm_cves(
qids: BaseList,
cnxn: Connection,
table_name: str = "pm_cves_for_qids",
override_import_dt: datetime = None,
) -> int:
"""
Upload results from ```pm.lookup_cves```
to a SQL database.
Args:
qids (BaseList): A BaseList of QID objects.
cnxn (Connection): The Connection object to the SQL database.
table_name (str): The name of the table to upload to. Defaults to "pm_cves_for_qids".
override_import_dt (datetime): If provided, will override the import_datetime column with this value.
Returns:
int: The number of rows uploaded.
"""

COLS = {
"id": types.Integer(),
"title": types.String().with_variant(TEXT(charset="utf8"), "mysql", "mariadb"),
"cves": types.String().with_variant(TEXT(charset="utf8"), "mysql", "mariadb"),
"detectedDate": types.DateTime(),
"severity": types.Integer(),
"vulnType": types.String().with_variant(
TEXT(charset="utf8"), "mysql", "mariadb"
),
}

# Prepare the dataclass for insertion:
df = DataFrame([prepare_dataclass(qid) for qid in qids])

# Upload the data:
return upload_data(df, table_name, cnxn, COLS, override_import_dt)

0 comments on commit 7ec04a1

Please sign in to comment.