-
Notifications
You must be signed in to change notification settings - Fork 0
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
[TOOL-95] Add whois info to the host string. #2
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import ipaddress | ||
import socket | ||
from ipwhois import IPWhois | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to declare this as a new dependency in pyproject.toml |
||
from ipwhois.exceptions import HTTPLookupError, IPDefinedError | ||
|
||
import pytest | ||
|
||
|
@@ -16,9 +18,15 @@ class SocketConnectBlockedError(RuntimeError): | |
def __init__(self, allowed, host, *_args, **_kwargs): | ||
if allowed: | ||
allowed = ",".join(allowed) | ||
try: | ||
ip_whois = IPWhois(host).lookup_rdap(depth=1) | ||
host_description = ip_whois.get("asn_description", None) | ||
except (HTTPLookupError, IPDefinedError): | ||
host_description = None | ||
host_text = f"{host} ({host_description})" if host_description else host | ||
super().__init__( | ||
"A test tried to use socket.socket.connect() " | ||
f'with host "{host}" (allowed: "{allowed}").' | ||
f'with host "{host_text}" (allowed: "{allowed}").' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't it break any test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For libraries meant to be reused by many applications, strict dependencies are discouraged since they lock every dependent app to use that specific version and block them from upgrading to
1.4.0
for example.We should be as lax as possible here, and as strict as possible in
shiphero_app
.For example here
ipwhois = ">= 1.0.0"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This article is a good reference to understand why.
setup.py
here would be ourpyproject.toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done. Good catch.