feat: add permissions on hostname view

This commit is contained in:
Aaron3S
2026-03-13 14:33:17 +08:00
parent 87926a8acd
commit 447225aa12

View File

@@ -1,13 +1,22 @@
from django.conf import settings
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.permissions import AllowAny
from common.permissions import OnlySuperUser
## 此 api 返回 /etc/hostname 的值, 可以匿名访问
# 此 api 返回 /etc/hostname 的值
# 在 DEBUG_DEV 配置下可以匿名访问
class HostnameView(APIView):
permission_classes = (AllowAny,)
def get_permissions(self):
if getattr(settings, 'DEV_DEBUG', False):
return [AllowAny()]
return [OnlySuperUser()]
def get(self, request):
try:
with open('/etc/hostname', 'r') as f: