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
14 changes: 12 additions & 2 deletions src/sentry/uptime/rdap/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import logging
from urllib.parse import urlparse

from sentry.tasks.base import instrumented_task
from sentry.uptime.models import UptimeSubscription
from sentry.uptime.rdap.query import resolve_rdap_network_details

logger = logging.getLogger(__name__)


@instrumented_task(
name="sentry.uptime.rdap.tasks.fetch_subscription_rdap_info",
Expand All @@ -21,7 +26,12 @@ def fetch_subscription_rdap_info(subscription_id: int):
# the rdap details.
return

host = f"{sub.url_domain}.{sub.url_domain_suffix}"
details = resolve_rdap_network_details(host)
parsed_url = urlparse(sub.url)

if parsed_url.hostname is None:
logger.warning("rdap_url_missing_hostname", extra={"url": sub.url})
return

details = resolve_rdap_network_details(parsed_url.hostname)

sub.update(host_provider_id=details["handle"], host_provider_name=details["owner_name"])
6 changes: 2 additions & 4 deletions tests/sentry/uptime/rdap/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ def test(self, mock_fetch_subscription_rdap_info):
mock_fetch_subscription_rdap_info.return_value = test_info

uptime_subscription = self.create_uptime_subscription(
url="https://example.com",
url_domain="example",
url_domain_suffix="com",
url="https://some.example.com/health",
)
fetch_subscription_rdap_info(uptime_subscription.id)
uptime_subscription.refresh_from_db()

mock_fetch_subscription_rdap_info.assert_called_with("example.com")
mock_fetch_subscription_rdap_info.assert_called_with("some.example.com")
assert uptime_subscription.host_provider_id == "TEST-HANDLE"
assert uptime_subscription.host_provider_name == "Rick Sanchez"
Loading