Skip to content

Commit

Permalink
🐛 Enforce 0 <= index <= 256 and require uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
jemrobinson committed Jan 24, 2024
1 parent 93e1773 commit 7f42d27
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion data_safe_haven/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ConfigSectionSRE(BaseModel, validate_assignment=True):
data_provider_ip_addresses: list[IpAddress] = Field(
..., default_factory=list[IpAddress]
)
index: int = Field(..., ge=0)
index: int = Field(..., ge=0, le=256)
remote_desktop: ConfigSubsectionRemoteDesktopOpts = Field(
..., default_factory=ConfigSubsectionRemoteDesktopOpts
)
Expand Down Expand Up @@ -258,6 +258,17 @@ def __init__(self, context: Context, **kwargs: dict[Any, Any]):
tags = ConfigSectionTags(context)
super().__init__(context=context, tags=tags, **kwargs)

@field_validator("sres")
@classmethod
def all_sre_indices_must_be_unique(
cls, v: dict[str, ConfigSectionSRE]
) -> dict[str, ConfigSectionSRE]:
indices = [s.index for s in v.values()]
if len(indices) != len(set(indices)):
msg = "all SRE indices must be unique"
raise ValueError(msg)
return v

@property
def work_directory(self) -> Path:
return self.context.work_directory
Expand Down

0 comments on commit 7f42d27

Please sign in to comment.