mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
refactor: ruff autofixes
This commit is contained in:
455 files changed
+12322
-14762
No files matched your search
@@ -48,16 +48,15 @@ def _extract_alg(token: str) -> str:
|
||||
|
||||
|
||||
class AuthService:
|
||||
|
||||
def hash_password(self, password: str) -> str:
|
||||
|
||||
salt = bcrypt.gensalt()
|
||||
hashed_password = bcrypt.hashpw(password=password.encode('utf-8'), salt=salt)
|
||||
return hashed_password.decode('utf-8')
|
||||
hashed_password = bcrypt.hashpw(password=password.encode("utf-8"), salt=salt)
|
||||
return hashed_password.decode("utf-8")
|
||||
|
||||
def verify_password(self, password, hashed_password) -> bool:
|
||||
|
||||
return bcrypt.checkpw(password=password.encode('utf-8'), hashed_password=hashed_password.encode('utf-8'))
|
||||
return bcrypt.checkpw(password=password.encode("utf-8"), hashed_password=hashed_password.encode("utf-8"))
|
||||
|
||||
def _create_token(self, username, token_version, token_type, expires_in, secret_key=None) -> str:
|
||||
"""Shared helper to create any kind of signed JWT token."""
|
||||
@@ -80,7 +79,9 @@ class AuthService:
|
||||
expires_in = Config.instance().settings.Controller.jwt_access_token_expire_minutes
|
||||
return self._create_token(username, token_version, "access", expires_in, secret_key)
|
||||
|
||||
def create_refresh_token(self, username, token_version: int = 0, secret_key: str = None, expires_in: int = 0) -> str:
|
||||
def create_refresh_token(
|
||||
self, username, token_version: int = 0, secret_key: str = None, expires_in: int = 0
|
||||
) -> str:
|
||||
|
||||
if not expires_in:
|
||||
expires_in = Config.instance().settings.Controller.jwt_refresh_token_expire_minutes
|
||||
|
||||
@@ -158,11 +158,11 @@ BUILTIN_TEMPLATES = [
|
||||
|
||||
|
||||
class TemplatesService:
|
||||
|
||||
def __init__(self, templates_repo: TemplatesRepository):
|
||||
|
||||
self._templates_repo = templates_repo
|
||||
from gns3server.controller import Controller
|
||||
|
||||
self._controller = Controller.instance()
|
||||
|
||||
# resolve built-in template symbols
|
||||
@@ -233,8 +233,10 @@ class TemplatesService:
|
||||
|
||||
if await self._templates_repo.get_template_by_name_and_version(template_create.name, template_create.version):
|
||||
if template_create.version:
|
||||
raise ControllerError(f"A template with name '{template_create.name}' and "
|
||||
f"version {template_create.version} already exists")
|
||||
raise ControllerError(
|
||||
f"A template with name '{template_create.name}' and "
|
||||
f"version {template_create.version} already exists"
|
||||
)
|
||||
else:
|
||||
raise ControllerError(f"A template with name '{template_create.name}' already exists")
|
||||
|
||||
@@ -364,11 +366,7 @@ class TemplatesService:
|
||||
if not os.path.exists(path):
|
||||
return []
|
||||
|
||||
return [
|
||||
{"filename": f}
|
||||
for f in sorted(os.listdir(path))
|
||||
if os.path.isfile(os.path.join(path, f))
|
||||
]
|
||||
return [{"filename": f} for f in sorted(os.listdir(path)) if os.path.isfile(os.path.join(path, f))]
|
||||
|
||||
def get_file(self, template_id: str, filename: str):
|
||||
safe_filename = os.path.basename(filename)
|
||||
@@ -395,4 +393,4 @@ class TemplatesService:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
except OSError as e:
|
||||
raise ControllerError(str(e))
|
||||
raise ControllerError(str(e))
|
||||
Reference in new issue
Block a user