mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Reduce I/O from cert_expiry (#94399)
This commit is contained in:
parent
ece5de73a4
commit
aa71c8e8f0
@ -1,4 +1,5 @@
|
|||||||
"""Helper functions for the Cert Expiry platform."""
|
"""Helper functions for the Cert Expiry platform."""
|
||||||
|
from functools import cache
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
@ -14,12 +15,18 @@ from .errors import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def _get_default_ssl_context():
|
||||||
|
"""Return the default SSL context."""
|
||||||
|
return ssl.create_default_context()
|
||||||
|
|
||||||
|
|
||||||
def get_cert(
|
def get_cert(
|
||||||
host: str,
|
host: str,
|
||||||
port: int,
|
port: int,
|
||||||
):
|
):
|
||||||
"""Get the certificate for the host and port combination."""
|
"""Get the certificate for the host and port combination."""
|
||||||
ctx = ssl.create_default_context()
|
ctx = _get_default_ssl_context()
|
||||||
address = (host, port)
|
address = (host, port)
|
||||||
with socket.create_connection(address, timeout=TIMEOUT) as sock, ctx.wrap_socket(
|
with socket.create_connection(address, timeout=TIMEOUT) as sock, ctx.wrap_socket(
|
||||||
sock, server_hostname=address[0]
|
sock, server_hostname=address[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user