2525 'CustomStrengthOptionsConfig' ,
2626]
2727
28- class PasswordPolicyServerConfig :
28+
29+ class PasswordPolicyServerConfig :
2930 """Represents password policy configuration response received from the server and
3031 converts it to user format.
3132 """
@@ -39,11 +40,11 @@ def __init__(self, data):
3940 @property
4041 def enforcement_state (self ):
4142 return self ._data .get ('enforcementState' , None )
42-
43+
4344 @property
4445 def force_upgrade_on_signin (self ):
4546 return self ._data .get ('forceUpgradeOnSignin' , None )
46-
47+
4748 @property
4849 def constraints (self ):
4950 data = self ._data .get ('passwordPolicyVersions' )
@@ -65,11 +66,11 @@ def __init__(self, data):
6566 @property
6667 def require_uppercase (self ):
6768 return self ._data .get ('containsUppercaseCharacter' , None )
68-
69+
6970 @property
7071 def require_lowercase (self ):
7172 return self ._data .get ('containsLowercaseCharacter' , None )
72-
73+
7374 @property
7475 def require_non_alphanumeric (self ):
7576 return self ._data .get ('containsNonAlphanumericCharacter' , None )
@@ -81,11 +82,11 @@ def require_numeric(self):
8182 @property
8283 def min_length (self ):
8384 return self ._data .get ('minPasswordLength' , None )
84-
85+
8586 @property
8687 def max_length (self ):
8788 return self ._data .get ('maxPasswordLength' , None )
88-
89+
8990
9091def validate_keys (keys , valid_keys , config_name ):
9192 for key in keys :
@@ -116,7 +117,7 @@ def __init__(
116117
117118 def to_dict (self ) -> dict :
118119 data = {}
119- constraints_request = {};
120+ constraints_request = {}
120121 if self .max_length is not None :
121122 constraints_request ['maxPasswordLength' ] = self .max_length
122123 if self .min_length is not None :
@@ -131,28 +132,29 @@ def to_dict(self) -> dict:
131132 constraints_request ['containsNumericCharacter' ] = self .require_numeric
132133 data ['customStrengthOptions' ] = constraints_request
133134 return data
134-
135+
135136 def validate (self ):
136137 """Validates a constraints object.
137138
138139 Raises:
139140 ValueError: In case of an unsuccessful validation.
140141 """
141142 validate_keys (keys = vars (self ).keys (),
142- valid_keys = {
143- 'require_numeric' ,
144- 'require_uppercase' ,
145- 'require_lowercase' ,
146- 'require_non_alphanumeric' ,
147- 'min_length' ,
148- 'max_length' },
143+ valid_keys = {
144+ 'require_numeric' ,
145+ 'require_uppercase' ,
146+ 'require_lowercase' ,
147+ 'require_non_alphanumeric' ,
148+ 'min_length' ,
149+ 'max_length' },
149150 config_name = 'CustomStrengthOptionsConfig' )
150151 if not isinstance (self .require_lowercase , bool ):
151152 raise ValueError ('constraints.require_lowercase must be a boolean' )
152153 if not isinstance (self .require_uppercase , bool ):
153154 raise ValueError ('constraints.require_uppercase must be a boolean' )
154155 if not isinstance (self .require_non_alphanumeric , bool ):
155- raise ValueError ('constraints.require_non_alphanumeric must be a boolean' )
156+ raise ValueError (
157+ 'constraints.require_non_alphanumeric must be a boolean' )
156158 if not isinstance (self .require_numeric , bool ):
157159 raise ValueError ('constraints.require_numeric must be a boolean' )
158160 if not isinstance (self .min_length , int ):
@@ -161,16 +163,17 @@ def validate(self):
161163 raise ValueError ('constraints.max_length must be an integer' )
162164 if not (self .min_length >= 6 and self .min_length <= 30 ):
163165 raise ValueError ('constraints.min_length must be between 6 and 30' )
164- if not (self .max_length >= 0 and self .max_length <= 4096 ):
166+ if not (self .max_length >= 0 and self .max_length <= 4096 ):
165167 raise ValueError ('constraints.max_length can be atmost 4096' )
166168 if self .min_length > self .max_length :
167- raise ValueError ('min_length must be less than or equal to max_length' )
169+ raise ValueError (
170+ 'min_length must be less than or equal to max_length' )
168171
169-
170172 def build_server_request (self ):
171173 self .validate ()
172174 return self .to_dict ()
173175
176+
174177class PasswordPolicyConfig :
175178 """Represents the configuration for the password policy on the project"""
176179
@@ -197,7 +200,7 @@ def to_dict(self) -> dict:
197200 if self .constraints :
198201 data ['passwordPolicyVersions' ] = [self .constraints .to_dict ()]
199202 return data
200-
203+
201204 def validate (self ):
202205 """Validates a password_policy_config object.
203206
@@ -212,21 +215,22 @@ def validate(self):
212215 'constraints' },
213216 config_name = 'PasswordPolicyConfig' )
214217 if self .enforcement_state is None :
215- raise ValueError ('password_policy_config.enforcement_state must be defined.' )
218+ raise ValueError (
219+ 'password_policy_config.enforcement_state must be defined.' )
216220 if not isinstance (self .enforcement_state , PasswordPolicyConfig .EnforcementState ):
217221 raise ValueError (
218- 'password_policy_config.enforcement_state must be of type PasswordPolicyConfig.EnforcementState' )
222+ 'password_policy_config.enforcement_state must be of type PasswordPolicyConfig.EnforcementState' )
219223 if not isinstance (self .force_upgrade_on_signin , bool ):
220224 raise ValueError (
221- 'password_policy_config.force_upgrade_on_signin must be a valid boolean' )
225+ 'password_policy_config.force_upgrade_on_signin must be a valid boolean' )
222226 if self .enforcement_state is self .EnforcementState .ENFORCE and self .constraints is None :
223- raise ValueError ('password_policy_config.constraints must be defined' )
227+ raise ValueError (
228+ 'password_policy_config.constraints must be defined' )
224229 if not isinstance (self .constraints , CustomStrengthOptionsConfig ):
225230 raise ValueError (
226- 'password_policy_config.constraints must be of type CustomStrengthOptionsConfig' )
231+ 'password_policy_config.constraints must be of type CustomStrengthOptionsConfig' )
227232 self .constraints .validate ()
228233
229234 def build_server_request (self ):
230235 self .validate ()
231236 return self .to_dict ()
232-
0 commit comments