@@ -83,12 +83,20 @@ def __hash__(self) -> int:
83
83
"""Mechanism properties for GSSAPI authentication."""
84
84
85
85
86
- _CANONICALIZE_HOST_NAME_VALUES = ["false" , "true" , "none" , "forward" , "forwardAndReverse" ]
87
-
88
86
_AWSProperties = namedtuple ("_AWSProperties" , ["aws_session_token" ])
89
87
"""Mechanism properties for MONGODB-AWS authentication."""
90
88
91
89
90
+ def _validate_canonicalize_host_name (value : str | bool ) -> str | bool :
91
+ valid_names = [False , True , "none" , "forward" , "forwardAndReverse" ]
92
+ if value in ["true" , "false" , True , False ]:
93
+ return value in ["true" , True ]
94
+
95
+ if value not in valid_names :
96
+ raise ValueError (f"CANONICALIZE_HOST_NAME '{ value } ' not in valid options: { valid_names } " )
97
+ return value
98
+
99
+
92
100
def _build_credentials_tuple (
93
101
mech : str ,
94
102
source : Optional [str ],
@@ -107,10 +115,7 @@ def _build_credentials_tuple(
107
115
service_name = properties .get ("SERVICE_NAME" , "mongodb" )
108
116
service_host = properties .get ("SERVICE_HOST" , None )
109
117
canonicalize = properties .get ("CANONICALIZE_HOST_NAME" , "false" )
110
- if canonicalize not in _CANONICALIZE_HOST_NAME_VALUES :
111
- raise ConfigurationError (
112
- f"CANONICALIZE_HOST_NAME '{ canonicalize } ' not in valid options: { _CANONICALIZE_HOST_NAME_VALUES } "
113
- )
118
+ canonicalize = _validate_canonicalize_host_name (canonicalize )
114
119
service_realm = properties .get ("SERVICE_REALM" )
115
120
props = GSSAPIProperties (
116
121
service_name = service_name ,
0 commit comments