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

Allow 'Internet' for data providers IP #2247

Draft
wants to merge 4 commits into
base: latest
Choose a base branch
from
Draft
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
5 changes: 2 additions & 3 deletions data_safe_haven/config/config_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ConfigSectionSRE(BaseModel, validate_assignment=True):
admin_email_address: EmailAddress
admin_ip_addresses: list[IpAddress] = []
databases: UniqueList[DatabaseSystem] = []
data_provider_ip_addresses: list[IpAddress] = []
data_provider_ip_addresses: list[IpAddress] | AzureServiceTag = []
remote_desktop: ConfigSubsectionRemoteDesktopOpts
research_user_ip_addresses: list[IpAddress] | AzureServiceTag = []
storage_quota_gb: ConfigSubsectionStorageQuotaGB
Expand All @@ -67,8 +67,6 @@ class ConfigSectionSRE(BaseModel, validate_assignment=True):

@field_validator(
"admin_ip_addresses",
"data_provider_ip_addresses",
# "research_user_ip_addresses",
mode="after",
)
@classmethod
Expand All @@ -81,6 +79,7 @@ def ensure_non_overlapping(cls, v: list[IpAddress]) -> list[IpAddress]:
return v

@field_validator(
"data_provider_ip_addresses",
"research_user_ip_addresses",
mode="after",
)
Expand Down
2 changes: 1 addition & 1 deletion data_safe_haven/validators/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def ip_address(ip_address: str) -> str:
try:
return str(ipaddress.ip_network(ip_address))
except Exception as exc:
msg = "Expected valid IPv4 address, for example '1.1.1.1', or 'Internet'."
msg = "Expected valid IPv4 address, for example '1.1.1.1'."
raise ValueError(msg) from exc


Expand Down
18 changes: 18 additions & 0 deletions tests/config/test_config_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ def test_all_databases_must_be_unique(self) -> None:
databases=[DatabaseSystem.POSTGRESQL, DatabaseSystem.POSTGRESQL],
)

def test_data_provider_tag_internet(
self,
config_subsection_remote_desktop: ConfigSubsectionRemoteDesktopOpts,
config_subsection_storage_quota_gb: ConfigSubsectionStorageQuotaGB,
):
sre_config = ConfigSectionSRE(
admin_email_address="[email protected]",
remote_desktop=config_subsection_remote_desktop,
storage_quota_gb=config_subsection_storage_quota_gb,
data_provider_ip_addresses="Internet",
)
assert isinstance(sre_config.data_provider_ip_addresses, AzureServiceTag)
assert sre_config.data_provider_ip_addresses == "Internet"

def test_data_provider_tag_invalid(self):
with pytest.raises(ValueError, match="Input should be 'Internet'"):
ConfigSectionSRE(data_provider_ip_addresses="Not a tag")

def test_ip_overlap_admin(self):
with pytest.raises(ValueError, match="IP addresses must not overlap."):
ConfigSectionSRE(
Expand Down
2 changes: 1 addition & 1 deletion tests/validators/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_ip_address(self, ip_address, output):
def test_ip_address_fail(self, ip_address):
with pytest.raises(
ValueError,
match="Expected valid IPv4 address, for example '1.1.1.1', or 'Internet'.",
match="Expected valid IPv4 address, for example '1.1.1.1'.",
):
validators.ip_address(ip_address)

Expand Down
Loading