jumpserver/apps/accounts/api/account/pam_dashboard.py

46 lines
1.6 KiB
Python
Raw Normal View History

2025-01-03 09:47:18 +00:00
# -*- coding: utf-8 -*-
#
from django.http.response import JsonResponse
from rest_framework.views import APIView
from accounts.models import Account, RiskChoice
__all__ = ['PamDashboardApi']
class PamDashboardApi(APIView):
http_method_names = ['get']
rbac_perms = {
'GET': 'accounts.view_account',
}
def get(self, request, *args, **kwargs):
query_params = self.request.query_params
data = {}
account_count = Account.objects.count()
privileged_account_count = Account.objects.filter(privileged=True).count()
2025-01-03 10:37:43 +00:00
if query_params.get('total_accounts'):
data['total_accounts'] = account_count
2025-01-03 09:47:18 +00:00
if query_params.get('total_privileged_accounts'):
data['total_privileged_accounts'] = privileged_account_count
if query_params.get('total_ordinary_accounts'):
data['total_ordinary_accounts'] = account_count - privileged_account_count
if query_params.get('total_unmanaged_accounts'):
data['total_unmanaged_accounts'] = Account.get_risks(RiskChoice.new_found).count()
if query_params.get('total_unavailable_accounts'):
data['total_unavailable_accounts'] = Account.objects.filter(is_active=False).count()
if query_params.get('total_weak_password_accounts'):
data['total_weak_password_accounts'] = Account.get_risks(RiskChoice.weak_password)
if query_params.get('total_long_time_change_password_accounts'):
data['total_long_time_change_password_accounts'] = Account.get_risks(RiskChoice.long_time_password)
return JsonResponse(data, status=200)