mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-02-21 14:32:45 +00:00
perf: Gather sqlserver int garbled text
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
l.is_disabled,
|
||||
l.create_date,
|
||||
l.default_database_name,
|
||||
LOGINPROPERTY(name, 'DaysUntilExpiration') AS days_until_expiration,
|
||||
CAST(LOGINPROPERTY(name, 'DaysUntilExpiration') AS INT) AS days_until_expiration,
|
||||
MAX(s.login_time) AS last_login_time
|
||||
FROM
|
||||
sys.sql_logins l
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from ast import literal_eval
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -27,6 +28,31 @@ def parse_date(date_str, default=None):
|
||||
return default
|
||||
|
||||
|
||||
def parse_int(value, default=None):
|
||||
if value is None:
|
||||
return default
|
||||
if isinstance(value, int):
|
||||
return value
|
||||
if isinstance(value, (bytes, bytearray)):
|
||||
return int.from_bytes(value, byteorder="little", signed=False) if value else default
|
||||
if isinstance(value, str):
|
||||
text = value.strip()
|
||||
if not text or text.lower() in {"none", "null"}:
|
||||
return default
|
||||
if text.startswith(("b'", 'b"')):
|
||||
try:
|
||||
maybe_bytes = literal_eval(text)
|
||||
if isinstance(maybe_bytes, (bytes, bytearray)):
|
||||
return int.from_bytes(maybe_bytes, byteorder="little", signed=False) if maybe_bytes else default
|
||||
except (ValueError, SyntaxError):
|
||||
return default
|
||||
try:
|
||||
return int(text)
|
||||
except ValueError:
|
||||
return default
|
||||
return default
|
||||
|
||||
|
||||
class GatherAccountsFilter:
|
||||
def __init__(self, tp):
|
||||
self.tp = tp
|
||||
@@ -74,7 +100,7 @@ class GatherAccountsFilter:
|
||||
return {}
|
||||
result = {}
|
||||
for user_info in info[0][0]:
|
||||
days_until_expiration = user_info.get('days_until_expiration')
|
||||
days_until_expiration = parse_int(user_info.get('days_until_expiration'))
|
||||
date_password_expired = timezone.now() + timezone.timedelta(
|
||||
days=int(days_until_expiration)) if days_until_expiration else None
|
||||
user = {
|
||||
|
||||
Reference in New Issue
Block a user