Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Bring the VulnCheck API to your Python applications.
- [PURL](#purl)
- [CPE](#cpe)
- [Backup](#backup)
- [Advisory](#advisory)
- [Backup v4](#backup-v4)
- [Indices](#indices)
- [Index](#index)
- [Pagination](#pagination)
Expand Down Expand Up @@ -392,6 +394,160 @@ if __name__ == "__main__":
```


</details>

### Advisory

List all advisory feeds and query advisories filtered by feed

```python
import vulncheck_sdk
from vulncheck_sdk.models.search_v4_advisory_return_value import SearchV4AdvisoryReturnValue
from vulncheck_sdk.models.search_v4_list_feed_return_value import SearchV4ListFeedReturnValue
import os

TOKEN = os.environ["VULNCHECK_API_TOKEN"]

configuration = vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] = TOKEN

with vulncheck_sdk.ApiClient(configuration) as api_client:
advisory_client = vulncheck_sdk.AdvisoryApi(api_client)

# List all available advisory feeds (/v4/advisory)
feeds: SearchV4ListFeedReturnValue = advisory_client.v4_list_advisory_feeds()
print(f"Available feeds: {feeds.data}")

# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)
advisories: SearchV4AdvisoryReturnValue = advisory_client.v4_query_advisories(name="wolfi")
print(f"Wolfi advisories (page 1): {len(advisories.data)} results")
for advisory in advisories.data:
print(f" - {advisory.id}")
```


<details><summary><b>Click to View Async Implementation</b></summary>

```python
import asyncio
import os
import vulncheck_sdk.aio as vcaio
from vulncheck_sdk.aio.models.search_v4_advisory_return_value import SearchV4AdvisoryReturnValue
from vulncheck_sdk.aio.models.search_v4_list_feed_return_value import SearchV4ListFeedReturnValue

TOKEN = os.environ.get("VULNCHECK_API_TOKEN")

configuration = vcaio.Configuration()
configuration.api_key["Bearer"] = TOKEN


async def main():
async with vcaio.ApiClient(configuration) as api_client:
advisory_client = vcaio.AdvisoryApi(api_client)

# List all available advisory feeds (/v4/advisory)
feeds: SearchV4ListFeedReturnValue = await advisory_client.v4_list_advisory_feeds()
print(f"Available feeds: {feeds.data}")

# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)
advisories: SearchV4AdvisoryReturnValue = await advisory_client.v4_query_advisories(name="wolfi")
print(f"Wolfi advisories (page 1): {len(advisories.data)} results")
for advisory in advisories.data:
print(f" - {advisory.id}")


if __name__ == "__main__":
asyncio.run(main())
```


</details>

### Backup v4

List available v4 backups and download a backup by feed name

```python
import urllib.request
import vulncheck_sdk
from vulncheck_sdk.models.backup_list_backups_response import BackupListBackupsResponse
from vulncheck_sdk.models.backup_feed_item import BackupFeedItem
import os

TOKEN = os.environ["VULNCHECK_API_TOKEN"]

configuration = vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] = TOKEN

with vulncheck_sdk.ApiClient(configuration) as api_client:
backup_client = vulncheck_sdk.BackupApi(api_client)

# List available backups (/v4/backup)
available: BackupListBackupsResponse = backup_client.v4_list_backups()
for potential in available.data:
print(f"found: {potential.name}")

# Get backup for the wolfi feed (/v4/backup/wolfi)
feed = "wolfi"
response = backup_client.v4_get_backup_by_name(feed)

file_path = f"{feed}.zip"
with urllib.request.urlopen(response.url) as r:
with open(file_path, "wb") as f:
f.write(r.read())

print(f"Successfully saved to {file_path}")
```


<details><summary><b>Click to View Async Implementation</b></summary>

```python
import asyncio
import os
import urllib.request
import vulncheck_sdk.aio as vcaio
from vulncheck_sdk.aio.models.backup_list_backups_response import BackupListBackupsResponse
from vulncheck_sdk.aio.models.backup_backup_response import BackupBackupResponse

TOKEN = os.environ.get("VULNCHECK_API_TOKEN")

configuration = vcaio.Configuration()
configuration.api_key["Bearer"] = TOKEN


def download_sync(url, file_path):
with urllib.request.urlopen(url) as response:
with open(file_path, "wb") as file:
file.write(response.read())


async def main():
async with vcaio.ApiClient(configuration) as api_client:
backup_client = vcaio.BackupApi(api_client)

# List available backups (/v4/backup)
available: BackupListBackupsResponse = await backup_client.v4_list_backups()
for potential in available.data:
print(f"Found backup: {potential.name}")

# Get backup for the wolfi feed (/v4/backup/wolfi)
feed = "wolfi"
response: BackupBackupResponse = await backup_client.v4_get_backup_by_name(feed)

file_path = f"{feed}.zip"
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")

await asyncio.to_thread(download_sync, response.url, file_path)

print(f"Successfully saved to {file_path}")


if __name__ == "__main__":
asyncio.run(main())
```


</details>

### Indices
Expand Down
25 changes: 25 additions & 0 deletions tests/advisory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import vulncheck_sdk
from vulncheck_sdk.models.search_v4_advisory_return_value import SearchV4AdvisoryReturnValue
from vulncheck_sdk.models.search_v4_list_feed_return_value import SearchV4ListFeedReturnValue
import os

TOKEN = os.environ["VULNCHECK_API_TOKEN"]

configuration = vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] = TOKEN

with vulncheck_sdk.ApiClient(configuration) as api_client:
advisory_client = vulncheck_sdk.AdvisoryApi(api_client)

# List all available advisory feeds (/v4/advisory)
feeds: SearchV4ListFeedReturnValue = advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
for feed in feeds.data:
print(f"name: {feed.name}")

feed = "wolfi"
# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)
advisories: SearchV4AdvisoryReturnValue = advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
for advisory in advisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")
32 changes: 32 additions & 0 deletions tests/advisory_aio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import asyncio
import os
import vulncheck_sdk.aio as vcaio
from vulncheck_sdk.aio.models.search_v4_advisory_return_value import SearchV4AdvisoryReturnValue
from vulncheck_sdk.aio.models.search_v4_list_feed_return_value import SearchV4ListFeedReturnValue

TOKEN = os.environ.get("VULNCHECK_API_TOKEN")

configuration = vcaio.Configuration()
configuration.api_key["Bearer"] = TOKEN


async def main():
async with vcaio.ApiClient(configuration) as api_client:
advisory_client = vcaio.AdvisoryApi(api_client)

# List all available advisory feeds (/v4/advisory)
feeds: SearchV4ListFeedReturnValue = await advisory_client.v4_list_advisory_feeds()
print("Available feeds:")
for feed in feeds.data:
print(f"name: {feed.name}")

feed = "wolfi"
# Query advisories filtered by feed=wolfi (/v4/advisory?feed=wolfi)
advisories: SearchV4AdvisoryReturnValue = await advisory_client.v4_query_advisories(name=feed)
print(f"{feed.capitalize()} advisories (page 1): {len(advisories.data)} results")
for advisory in advisories.data:
print(f"cve: {advisory.cve_metadata.cve_id}")


if __name__ == "__main__":
asyncio.run(main())
31 changes: 31 additions & 0 deletions tests/backupv4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import urllib.request
import vulncheck_sdk
from vulncheck_sdk.models.backup_list_backups_response import BackupListBackupsResponse
from vulncheck_sdk.models.backup_feed_item import BackupFeedItem
import os

TOKEN = os.environ["VULNCHECK_API_TOKEN"]

configuration = vulncheck_sdk.Configuration()
configuration.api_key["Bearer"] = TOKEN

with vulncheck_sdk.ApiClient(configuration) as api_client:
backup_client = vulncheck_sdk.BackupApi(api_client)

# List available backups (/v4/backup)
available: BackupListBackupsResponse = backup_client.v4_list_backups()

for potential_backup in available.data:
print(f"Found backup: {potential_backup.name}")

# Get backup for the wolfi feed (/v4/backup/wolfi)
feed = "wolfi"
response: BackupListBackupsResponse = backup_client.v4_get_backup_by_name(feed)

print(f"Downloading {feed} backup")
file_path = f"{feed}.zip"
with urllib.request.urlopen(response.url) as r:
with open(file_path, "wb") as f:
f.write(r.read())

print(f"Successfully saved to {file_path}")
47 changes: 47 additions & 0 deletions tests/backupv4_aio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import asyncio
import os
import urllib.request
import vulncheck_sdk.aio as vcaio
from vulncheck_sdk.aio.models.backup_list_backups_response import BackupListBackupsResponse
from vulncheck_sdk.aio.models.backup_backup_response import BackupBackupResponse

TOKEN = os.environ.get("VULNCHECK_API_TOKEN")

configuration = vcaio.Configuration()
configuration.api_key["Bearer"] = TOKEN


def download_sync(url, file_path):
"""
Standard synchronous download using urllib.request.
This runs in a separate thread to avoid blocking the event loop.
"""
with urllib.request.urlopen(url) as response:
with open(file_path, "wb") as file:
file.write(response.read())


async def main():
async with vcaio.ApiClient(configuration) as api_client:
backup_client = vcaio.BackupApi(api_client)

# List available backups (/v4/backup)
available: BackupListBackupsResponse = await backup_client.v4_list_backups()
for potential_backup in available.data:
print(f"Found backup: {potential_backup.name}")

# Get backup for the wolfi feed (/v4/backup/wolfi)
feed = "wolfi"
response: BackupBackupResponse = await backup_client.v4_get_backup_by_name(feed)


file_path = f"{feed}.zip"
print(f"Downloading {feed} backup via urllib (offloaded to thread)...")

await asyncio.to_thread(download_sync, response.url, file_path)

print(f"Successfully saved to {file_path}")


if __name__ == "__main__":
asyncio.run(main())
4 changes: 4 additions & 0 deletions tests/readme_examples_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

# List of python programs to test
PROGRAMS = [
"./tests/advisory.py",
"./tests/advisory_aio.py",
"./tests/backup.py",
"./tests/backupv4.py",
"./tests/backup_aio.py",
"./tests/backupv4_aio.py",
"./tests/cpe.py",
"./tests/cpe_aio.py",
"./tests/index.py",
Expand Down
Loading