Skip to content

Commit

Permalink
forbid extra inputs in device inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
mtache committed Nov 24, 2023
1 parent f07f2e7 commit ebb420d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion anta/inventory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import List, Optional, Union

# Need to keep List for pydantic in python 3.8
from pydantic import BaseModel, IPvAnyAddress, IPvAnyNetwork, conint, constr
from pydantic import BaseModel, ConfigDict, IPvAnyAddress, IPvAnyNetwork, conint, constr

logger = logging.getLogger(__name__)

Expand All @@ -30,6 +30,8 @@ class AntaInventoryHost(BaseModel):
disable_cache (bool): Disable cache per host. Defaults to False.
"""

model_config = ConfigDict(extra="forbid")

name: Optional[str] = None
host: Union[constr(pattern=RFC_1123_REGEX), IPvAnyAddress] # type: ignore
port: Optional[conint(gt=1, lt=65535)] = None # type: ignore
Expand All @@ -47,6 +49,8 @@ class AntaInventoryNetwork(BaseModel):
disable_cache (bool): Disable cache per network. Defaults to False.
"""

model_config = ConfigDict(extra="forbid")

network: IPvAnyNetwork
tags: Optional[List[str]] = None
disable_cache: bool = False
Expand All @@ -63,6 +67,8 @@ class AntaInventoryRange(BaseModel):
disable_cache (bool): Disable cache per range of hosts. Defaults to False.
"""

model_config = ConfigDict(extra="forbid")

start: IPvAnyAddress
end: IPvAnyAddress
tags: Optional[List[str]] = None
Expand All @@ -79,6 +85,8 @@ class AntaInventoryInput(BaseModel):
range (list[AntaInventoryRange],Optional): List of AntaInventoryRange objects for ranges.
"""

model_config = ConfigDict(extra="forbid")

networks: Optional[List[AntaInventoryNetwork]] = None
hosts: Optional[List[AntaInventoryHost]] = None
ranges: Optional[List[AntaInventoryRange]] = None

0 comments on commit ebb420d

Please sign in to comment.