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

Add command to queue packages #203

Merged
merged 6 commits into from
Jul 14, 2024
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
9 changes: 9 additions & 0 deletions src/bot/dragonfly_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,12 @@ async def report_package(
"""Report a package to Dragonfly."""
data = dataclasses.asdict(report)
await self.make_request("POST", "/report", json=data)

async def queue_package(self: Self, name: str, version: str) -> None:
"""Add a package to the Dragonfly scan queue."""
data = {
"name": name,
"version": version,
import-pandas-as-numpy marked this conversation as resolved.
Show resolved Hide resolved
}

await self.make_request("POST", "/package", json=data)
Robin5605 marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions src/bot/exts/dragonfly/dragonfly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
from logging import getLogger
from typing import Self

Expand Down Expand Up @@ -582,6 +583,34 @@ async def before_scan_loop(self: Self) -> None:
"""Wait until the bot is ready."""
await self.bot.wait_until_ready()

@commands.has_role(Roles.vipyr_security)
@commands.hybrid_command()
async def queue(self: Self, ctx: commands.Context, name: str, version: str) -> None:
"""Add a package to the Dragonfly scan queue."""
try:
await self.bot.dragonfly_services.queue_package(name=name, version=version)
await ctx.send(f"Successfully queued package `{name} v{version}`")
except aiohttp.ClientResponseError as http_error:
status_code = http_error.status

if status_code == HTTPStatus.NOT_FOUND:
await ctx.send(f"Package `{name} v{version}` was not found on PyPI")

if status_code == HTTPStatus.CONFLICT:
Robin5605 marked this conversation as resolved.
Show resolved Hide resolved
scan_results = await self.bot.dragonfly_services.get_scanned_packages(
name=name,
version=version,
)

if scan_results:
embed = _build_package_scan_result_embed(scan_results[0])
await ctx.send(f"Package `{name} v{version}` has already been scanned.", embed=embed)
else:
await ctx.send(f"Package `{name} v{version}` is already waiting to be scanned.")
except Exception as e:
await ctx.send(str(e))
raise

@commands.has_role(Roles.vipyr_security)
@commands.command()
async def start(self: Self, ctx: commands.Context) -> None: # type: ignore[type-arg]
Expand Down
Loading