25
25
'CustomStrengthOptionsConfig' ,
26
26
]
27
27
28
- class PasswordPolicyServerConfig :
28
+
29
+ class PasswordPolicyServerConfig :
29
30
"""Represents password policy configuration response received from the server and
30
31
converts it to user format.
31
32
"""
@@ -39,11 +40,11 @@ def __init__(self, data):
39
40
@property
40
41
def enforcement_state (self ):
41
42
return self ._data .get ('enforcementState' , None )
42
-
43
+
43
44
@property
44
45
def force_upgrade_on_signin (self ):
45
46
return self ._data .get ('forceUpgradeOnSignin' , None )
46
-
47
+
47
48
@property
48
49
def constraints (self ):
49
50
data = self ._data .get ('passwordPolicyVersions' )
@@ -65,11 +66,11 @@ def __init__(self, data):
65
66
@property
66
67
def require_uppercase (self ):
67
68
return self ._data .get ('containsUppercaseCharacter' , None )
68
-
69
+
69
70
@property
70
71
def require_lowercase (self ):
71
72
return self ._data .get ('containsLowercaseCharacter' , None )
72
-
73
+
73
74
@property
74
75
def require_non_alphanumeric (self ):
75
76
return self ._data .get ('containsNonAlphanumericCharacter' , None )
@@ -81,11 +82,11 @@ def require_numeric(self):
81
82
@property
82
83
def min_length (self ):
83
84
return self ._data .get ('minPasswordLength' , None )
84
-
85
+
85
86
@property
86
87
def max_length (self ):
87
88
return self ._data .get ('maxPasswordLength' , None )
88
-
89
+
89
90
90
91
def validate_keys (keys , valid_keys , config_name ):
91
92
for key in keys :
@@ -116,7 +117,7 @@ def __init__(
116
117
117
118
def to_dict (self ) -> dict :
118
119
data = {}
119
- constraints_request = {};
120
+ constraints_request = {}
120
121
if self .max_length is not None :
121
122
constraints_request ['maxPasswordLength' ] = self .max_length
122
123
if self .min_length is not None :
@@ -131,28 +132,29 @@ def to_dict(self) -> dict:
131
132
constraints_request ['containsNumericCharacter' ] = self .require_numeric
132
133
data ['customStrengthOptions' ] = constraints_request
133
134
return data
134
-
135
+
135
136
def validate (self ):
136
137
"""Validates a constraints object.
137
138
138
139
Raises:
139
140
ValueError: In case of an unsuccessful validation.
140
141
"""
141
142
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' },
149
150
config_name = 'CustomStrengthOptionsConfig' )
150
151
if not isinstance (self .require_lowercase , bool ):
151
152
raise ValueError ('constraints.require_lowercase must be a boolean' )
152
153
if not isinstance (self .require_uppercase , bool ):
153
154
raise ValueError ('constraints.require_uppercase must be a boolean' )
154
155
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' )
156
158
if not isinstance (self .require_numeric , bool ):
157
159
raise ValueError ('constraints.require_numeric must be a boolean' )
158
160
if not isinstance (self .min_length , int ):
@@ -161,16 +163,17 @@ def validate(self):
161
163
raise ValueError ('constraints.max_length must be an integer' )
162
164
if not (self .min_length >= 6 and self .min_length <= 30 ):
163
165
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 ):
165
167
raise ValueError ('constraints.max_length can be atmost 4096' )
166
168
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' )
168
171
169
-
170
172
def build_server_request (self ):
171
173
self .validate ()
172
174
return self .to_dict ()
173
175
176
+
174
177
class PasswordPolicyConfig :
175
178
"""Represents the configuration for the password policy on the project"""
176
179
@@ -197,7 +200,7 @@ def to_dict(self) -> dict:
197
200
if self .constraints :
198
201
data ['passwordPolicyVersions' ] = [self .constraints .to_dict ()]
199
202
return data
200
-
203
+
201
204
def validate (self ):
202
205
"""Validates a password_policy_config object.
203
206
@@ -212,21 +215,22 @@ def validate(self):
212
215
'constraints' },
213
216
config_name = 'PasswordPolicyConfig' )
214
217
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.' )
216
220
if not isinstance (self .enforcement_state , PasswordPolicyConfig .EnforcementState ):
217
221
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' )
219
223
if not isinstance (self .force_upgrade_on_signin , bool ):
220
224
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' )
222
226
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' )
224
229
if not isinstance (self .constraints , CustomStrengthOptionsConfig ):
225
230
raise ValueError (
226
- 'password_policy_config.constraints must be of type CustomStrengthOptionsConfig' )
231
+ 'password_policy_config.constraints must be of type CustomStrengthOptionsConfig' )
227
232
self .constraints .validate ()
228
233
229
234
def build_server_request (self ):
230
235
self .validate ()
231
236
return self .to_dict ()
232
-
0 commit comments