33"""
44from __future__ import annotations
55from dataclasses import asdict
6- from pydantic import Field , validator
6+ from pydantic import Field , field_validator , model_validator
77from pydantic .dataclasses import dataclass
88from datetime import datetime , date
99from typing import Optional , List , Dict , Union , Any
@@ -40,7 +40,7 @@ class Statements:
4040 NotResource : Optional [Union [str , List [str ]]] = None
4141 Condition : Optional [Dict [str , Dict [str , Union [str , List [str ]]]]] = None
4242
43- @validator ("Principal" , pre = True )
43+ @field_validator ("Principal" , mode = "before" )
4444 def principal_is_list (cls , v ):
4545 if not v :
4646 return v
@@ -51,7 +51,7 @@ def principal_is_list(cls, v):
5151 v [key ] = [value ]
5252 return v
5353
54- @validator ("NotPrincipal" , pre = True )
54+ @field_validator ("NotPrincipal" , mode = "before" )
5555 def notprincipal_is_list (cls , v ):
5656 if not v :
5757 return v
@@ -62,11 +62,11 @@ def notprincipal_is_list(cls, v):
6262 v [key ] = [value ]
6363 return v
6464
65- @validator ( "NotAction" , always = True )
66- def at_least_action_or_not_action (cls , v , values , ** kwargs ) :
67- if not (( values . get ( " Action" , None ) is not None ) ^ ( v is not None )) :
65+ @model_validator ( mode = "after" )
66+ def at_least_action_or_not_action (self ) -> Self :
67+ if not self . Action and not self . NotAction :
6868 raise ValueError ("At least one of Action and NotAction must be specified" )
69- return v
69+ return self
7070
7171
7272@dataclass
@@ -75,7 +75,7 @@ class Document:
7575 Id : Optional [str ] = None
7676 Statement : List [Statements ] = Field (default_factory = list )
7777
78- @validator ("Statement" , pre = True )
78+ @field_validator ("Statement" , mode = "before" )
7979 def make_sure_statements_is_list (cls , v ):
8080 if not isinstance (v , list ):
8181 return [v ]
@@ -96,7 +96,7 @@ class ManagedPolicy:
9696
9797@dataclass
9898class PermissionBoundary :
99- PermissionsBoundaryType : str = Field (..., regex = "^Policy$" )
99+ PermissionsBoundaryType : str = Field (..., pattern = "^Policy$" )
100100 PermissionsBoundaryArn : str = Field (...)
101101
102102
@@ -248,7 +248,7 @@ class OrganizationAccount:
248248 JoinedMethod : str
249249 JoinedTimestamp : datetime
250250 Policies : List [SCPPolicy ]
251- Type : str = Field (..., regex = "^Account$" )
251+ Type : str = Field (..., pattern = "^Account$" )
252252 Parent : Optional [Union [RootOrganization , OrganizationUnit ]] = Field (None )
253253
254254 @property
@@ -273,7 +273,7 @@ class OrganizationUnit:
273273 Name : str
274274 Policies : List [SCPPolicy ]
275275 Children : List [Union [OrganizationUnit , OrganizationAccount ]]
276- Type : str = Field (..., regex = "^OU$" )
276+ Type : str = Field (..., pattern = "^OU$" )
277277 Parent : Optional [Union [RootOrganization , OrganizationUnit ]] = Field (None )
278278
279279 @property
0 commit comments