mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-01 08:10:13 +03:00
fix(typing): resolve mypy errors in utils.http_client
This commit is contained in:
parent
b9192438c9
commit
5bf3c8d203
@ -16,6 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from pydantic import SecretStr
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -28,7 +29,7 @@ class HTTPClient:
|
|||||||
HTTP client for request to computes and external services.
|
HTTP client for request to computes and external services.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_aiohttp_client: aiohttp.ClientSession = None
|
_aiohttp_client: aiohttp.ClientSession | None = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_client(cls, ssl_context=None) -> aiohttp.ClientSession:
|
def get_client(cls, ssl_context=None) -> aiohttp.ClientSession:
|
||||||
@ -44,15 +45,21 @@ class HTTPClient:
|
|||||||
cls._aiohttp_client = None
|
cls._aiohttp_client = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def request(cls, method: str, url: str, user: str = None, password: str = None, ssl_context=None, **kwargs):
|
def request(
|
||||||
|
cls,
|
||||||
|
method: str,
|
||||||
|
url: str,
|
||||||
|
user: str | None = None,
|
||||||
|
password: SecretStr | None = None,
|
||||||
|
ssl_context=None,
|
||||||
|
**kwargs,
|
||||||
|
):
|
||||||
|
|
||||||
client = cls.get_client(ssl_context=ssl_context)
|
client = cls.get_client(ssl_context=ssl_context)
|
||||||
basic_auth = None
|
basic_auth = None
|
||||||
if user:
|
if user:
|
||||||
if not password:
|
|
||||||
password = ""
|
|
||||||
try:
|
try:
|
||||||
basic_auth = aiohttp.BasicAuth(user, password.get_secret_value(), "utf-8")
|
basic_auth = aiohttp.BasicAuth(user, password.get_secret_value() if password else "", "utf-8")
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
log.error(f"Basic authentication set-up error: {e}")
|
log.error(f"Basic authentication set-up error: {e}")
|
||||||
|
|
||||||
|
|||||||
@ -399,7 +399,6 @@ module = [
|
|||||||
"gns3server.services.templates", # 18
|
"gns3server.services.templates", # 18
|
||||||
"gns3server.utils.asyncio.aiozipstream", # 8
|
"gns3server.utils.asyncio.aiozipstream", # 8
|
||||||
"gns3server.utils.encryption", # 2
|
"gns3server.utils.encryption", # 2
|
||||||
"gns3server.utils.http_client", # 4
|
|
||||||
"gns3server.utils.images", # 4
|
"gns3server.utils.images", # 4
|
||||||
"gns3server.utils.packet_filter_validation", # 16
|
"gns3server.utils.packet_filter_validation", # 16
|
||||||
"gns3server.utils.websocket_to_websocket", # 12
|
"gns3server.utils.websocket_to_websocket", # 12
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user