MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / _canonicalize_hostname

Function _canonicalize_hostname

pymongo/asynchronous/auth.py:181–207  ·  view source on GitHub ↗

Canonicalize hostname following MIT-krb5 behavior.

(hostname: str, option: str | bool)

Source from the content-addressed store, hash-verified

179
180
181async def _canonicalize_hostname(hostname: str, option: str | bool) -> str:
182 """Canonicalize hostname following MIT-krb5 behavior."""
183 # https://github.com/krb5/krb5/blob/d406afa363554097ac48646a29249c04f498c88e/src/util/k5test.py#L505-L520
184 if option in [False, "none"]:
185 return hostname
186
187 af, socktype, proto, canonname, sockaddr = (
188 await _getaddrinfo(
189 hostname,
190 None,
191 family=0,
192 type=0,
193 proto=socket.IPPROTO_TCP,
194 flags=socket.AI_CANONNAME,
195 )
196 )[0] # type: ignore[index]
197
198 # For forward just to resolve the cname as dns.lookup() will not return it.
199 if option == "forward":
200 return canonname.lower()
201
202 try:
203 name = socket.getnameinfo(sockaddr, socket.NI_NAMEREQD)
204 except socket.gaierror:
205 return canonname.lower()
206
207 return name[0].lower()
208
209
210async def _authenticate_gssapi(credentials: MongoCredential, conn: AsyncConnection) -> None:

Callers 1

_authenticate_gssapiFunction · 0.70

Calls 1

_getaddrinfoFunction · 0.90

Tested by

no test coverage detected