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

Remove email #31

Merged
merged 3 commits into from
May 11, 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
1,291 changes: 328 additions & 963 deletions pdm.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ dependencies = [
"httpx>=0.27.0",
"pydantic-settings>=2.2.1",
"uvicorn[standard]>=0.27.1",
"azure-identity>=1.15.0",
"msgraph-sdk>=1.0.0",
"sentry-sdk[fastapi]>=1.40.6",
]
requires-python = ">=3.11"
Expand Down
29 changes: 1 addition & 28 deletions src/reporter/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import logging
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException
from msgraph import GraphServiceClient
from reporter.schemas import ReportPayload
from reporter.constants import Mail
from fastapi import FastAPI, HTTPException
import sentry_sdk

from reporter.constants import GIT_SHA, Sentry
from reporter.pypi_client import ObservationsAPIFailure, PyPIClientDependency
from reporter.models import Observation, ServerMetadata, EchoResponse

from reporter.dependencies import build_graph_client
from reporter.mailer import build_report_email_content, send_mail

log = logging.getLogger(__name__)

sentry_sdk.init(
Expand Down Expand Up @@ -50,23 +43,3 @@ async def report_endpoint(project_name: str, observation: Observation, pypi_clie
sentry_sdk.capture_exception(exc)
log.error(f"PyPI Observations API failed with response code {exc.response.status_code}: {exc.response.text}")
raise HTTPException(400, detail="PyPI Observations API failed")


@app.post("/report/email")
async def report_email_endpoint(
payload: ReportPayload, graph_client: Annotated[GraphServiceClient, Depends(build_graph_client)]
):
content = build_report_email_content(
name=payload.name,
version=payload.version,
inspector_url=payload.inspector_url,
rules_matched=payload.rules_matched,
additional_information=payload.additional_information,
)
await send_mail(
graph_client,
to_addresses=[payload.recipient or Mail.recipient],
bcc_addresses=[],
subject=f"Automated PyPI Malware Report: {payload.name}@{payload.version}",
content=content,
)
23 changes: 0 additions & 23 deletions src/reporter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,3 @@ class _PyPI(EnvConfig, env_prefix="pypi_"): # pyright: ignore


PyPI = _PyPI()


class _Mail(EnvConfig, env_prefix="mail_"): # pyright: ignore
"""Environment variables that are core to the app itself."""

reply_to: str = "[email protected]"
sender: str = "[email protected]"
recipient: str = "[email protected]"


Mail = _Mail()


class _Microsoft(EnvConfig, env_prefix="microsoft_"): # pyright: ignore
"""Environment variables for Microsoft."""

tenant_id: str = ""
client_id: str = ""
client_secret: str = ""
scopes: list[str] = ["https://graph.microsoft.com/.default"]


Microsoft = _Microsoft()
7 changes: 0 additions & 7 deletions src/reporter/dependencies/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions src/reporter/dependencies/microsoft_graph_dependencies.py

This file was deleted.

75 changes: 0 additions & 75 deletions src/reporter/mailer.py

This file was deleted.