mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-12-16 09:02:49 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6a9eb3e70 | ||
|
|
802d6136d6 | ||
|
|
7e8bb9752c | ||
|
|
3fb0197e99 | ||
|
|
7127b2da93 | ||
|
|
48b3699591 |
@@ -1,13 +1,13 @@
|
|||||||
from django_filters import rest_framework as drf_filters
|
from django_filters import rest_framework as drf_filters
|
||||||
|
|
||||||
from assets.const import Protocol
|
|
||||||
from accounts import serializers
|
from accounts import serializers
|
||||||
from accounts.models import AccountTemplate
|
from accounts.models import AccountTemplate
|
||||||
from orgs.mixins.api import OrgBulkModelViewSet
|
from assets.const import Protocol
|
||||||
from rbac.permissions import RBACPermission
|
from common.drf.filters import BaseFilterSet
|
||||||
from common.permissions import UserConfirmation, ConfirmType
|
from common.permissions import UserConfirmation, ConfirmType
|
||||||
from common.views.mixins import RecordViewLogMixin
|
from common.views.mixins import RecordViewLogMixin
|
||||||
from common.drf.filters import BaseFilterSet
|
from orgs.mixins.api import OrgBulkModelViewSet
|
||||||
|
from rbac.permissions import RBACPermission
|
||||||
|
|
||||||
|
|
||||||
class AccountTemplateFilterSet(BaseFilterSet):
|
class AccountTemplateFilterSet(BaseFilterSet):
|
||||||
@@ -27,6 +27,8 @@ class AccountTemplateFilterSet(BaseFilterSet):
|
|||||||
continue
|
continue
|
||||||
_st = protocol_secret_type_map[p].get('secret_types', [])
|
_st = protocol_secret_type_map[p].get('secret_types', [])
|
||||||
secret_types.update(_st)
|
secret_types.update(_st)
|
||||||
|
if not secret_types:
|
||||||
|
secret_types = ['password']
|
||||||
queryset = queryset.filter(secret_type__in=secret_types)
|
queryset = queryset.filter(secret_type__in=secret_types)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class ChangeSecretMixin(models.Model):
|
|||||||
default=SSHKeyStrategy.add, verbose_name=_('SSH key change strategy')
|
default=SSHKeyStrategy.add, verbose_name=_('SSH key change strategy')
|
||||||
)
|
)
|
||||||
|
|
||||||
accounts: list[str] # account usernames
|
|
||||||
get_all_assets: callable # get all assets
|
get_all_assets: callable # get all assets
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from rest_framework.decorators import action
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from common.api import JMSGenericViewSet
|
from common.api import JMSGenericViewSet
|
||||||
|
from common.permissions import IsValidUser
|
||||||
from assets.serializers import CategorySerializer, TypeSerializer
|
from assets.serializers import CategorySerializer, TypeSerializer
|
||||||
from assets.const import AllTypes
|
from assets.const import AllTypes
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ class CategoryViewSet(ListModelMixin, JMSGenericViewSet):
|
|||||||
'default': CategorySerializer,
|
'default': CategorySerializer,
|
||||||
'types': TypeSerializer
|
'types': TypeSerializer
|
||||||
}
|
}
|
||||||
permission_classes = ()
|
permission_classes = (IsValidUser,)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return AllTypes.categories()
|
return AllTypes.categories()
|
||||||
|
|||||||
@@ -57,11 +57,23 @@ class SerializeToTreeNodeMixin:
|
|||||||
]
|
]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@lazyproperty
|
||||||
|
def support_types(self):
|
||||||
|
from assets.const import AllTypes
|
||||||
|
return AllTypes.get_types_values(exclude_custom=True)
|
||||||
|
|
||||||
|
def get_icon(self, asset):
|
||||||
|
if asset.type in self.support_types:
|
||||||
|
return asset.type
|
||||||
|
else:
|
||||||
|
return 'file'
|
||||||
|
|
||||||
@timeit
|
@timeit
|
||||||
def serialize_assets(self, assets, node_key=None):
|
def serialize_assets(self, assets, node_key=None):
|
||||||
sftp_enabled_platform = PlatformProtocol.objects \
|
sftp_enabled_platform = PlatformProtocol.objects \
|
||||||
.filter(name='ssh', setting__sftp_enabled=True) \
|
.filter(name='ssh', setting__sftp_enabled=True) \
|
||||||
.values_list('platform', flat=True).distinct()
|
.values_list('platform', flat=True) \
|
||||||
|
.distinct()
|
||||||
if node_key is None:
|
if node_key is None:
|
||||||
get_pid = lambda asset: getattr(asset, 'parent_key', '')
|
get_pid = lambda asset: getattr(asset, 'parent_key', '')
|
||||||
else:
|
else:
|
||||||
@@ -75,7 +87,7 @@ class SerializeToTreeNodeMixin:
|
|||||||
'pId': get_pid(asset),
|
'pId': get_pid(asset),
|
||||||
'isParent': False,
|
'isParent': False,
|
||||||
'open': False,
|
'open': False,
|
||||||
'iconSkin': asset.type,
|
'iconSkin': self.get_icon(asset),
|
||||||
'chkDisabled': not asset.is_active,
|
'chkDisabled': not asset.is_active,
|
||||||
'meta': {
|
'meta': {
|
||||||
'type': 'asset',
|
'type': 'asset',
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ def get_platform_automation_methods(path):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
print("path: ", path)
|
|
||||||
manifest = yaml_load_with_i18n(f)
|
manifest = yaml_load_with_i18n(f)
|
||||||
check_platform_method(manifest, path)
|
check_platform_method(manifest, path)
|
||||||
manifest['dir'] = os.path.dirname(path)
|
manifest['dir'] = os.path.dirname(path)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class CustomTypes(BaseType):
|
|||||||
platforms = list(cls.get_custom_platforms())
|
platforms = list(cls.get_custom_platforms())
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
types = [p.type for p in platforms]
|
types = set([p.type for p in platforms])
|
||||||
return [(t, t) for t in types]
|
return [(t, t) for t in types]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -48,11 +48,7 @@ class CustomTypes(BaseType):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def internal_platforms(cls):
|
def internal_platforms(cls):
|
||||||
return {
|
return {}
|
||||||
# cls.PUBLIC: [],
|
|
||||||
# cls.PRIVATE: [{'name': 'Vmware-vSphere'}],
|
|
||||||
# cls.K8S: [{'name': 'Kubernetes'}],
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_custom_platforms(cls):
|
def get_custom_platforms(cls):
|
||||||
|
|||||||
@@ -151,15 +151,18 @@ class AllTypes(ChoicesMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_types(cls):
|
def get_types(cls, exclude_custom=False):
|
||||||
choices = []
|
choices = []
|
||||||
for i in dict(cls.category_types()).values():
|
|
||||||
choices.extend(i.get_types())
|
for name, tp in dict(cls.category_types()).items():
|
||||||
|
if name == Category.CUSTOM and exclude_custom:
|
||||||
|
continue
|
||||||
|
choices.extend(tp.get_types())
|
||||||
return choices
|
return choices
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_types_values(cls):
|
def get_types_values(cls, exclude_custom=False):
|
||||||
choices = cls.get_types()
|
choices = cls.get_types(exclude_custom=exclude_custom)
|
||||||
return [c.value for c in choices]
|
return [c.value for c in choices]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer, WritableNestedModelSeriali
|
|||||||
'name': {'label': _("Name")},
|
'name': {'label': _("Name")},
|
||||||
'address': {'label': _('Address')},
|
'address': {'label': _('Address')},
|
||||||
'nodes_display': {'label': _('Node path')},
|
'nodes_display': {'label': _('Node path')},
|
||||||
|
'nodes': {'allow_empty': True},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from assets.const.web import FillType
|
from assets.const.web import FillType
|
||||||
from common.serializers import WritableNestedModelSerializer
|
from common.serializers import WritableNestedModelSerializer, type_field_map
|
||||||
from common.serializers.fields import LabeledChoiceField
|
from common.serializers.fields import LabeledChoiceField
|
||||||
from common.utils import lazyproperty
|
from common.utils import lazyproperty
|
||||||
from ..const import Category, AllTypes
|
from ..const import Category, AllTypes
|
||||||
@@ -88,14 +88,7 @@ class PlatformProtocolSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class PlatformCustomField(serializers.Serializer):
|
class PlatformCustomField(serializers.Serializer):
|
||||||
TYPE_CHOICES = [
|
TYPE_CHOICES = [(t, t) for t, c in type_field_map.items()]
|
||||||
("str", "str"),
|
|
||||||
("text", "text"),
|
|
||||||
("int", "int"),
|
|
||||||
("bool", "bool"),
|
|
||||||
("choice", "choice"),
|
|
||||||
("list", "list"),
|
|
||||||
]
|
|
||||||
name = serializers.CharField(label=_("Name"), max_length=128)
|
name = serializers.CharField(label=_("Name"), max_length=128)
|
||||||
label = serializers.CharField(label=_("Label"), max_length=128)
|
label = serializers.CharField(label=_("Label"), max_length=128)
|
||||||
type = serializers.ChoiceField(choices=TYPE_CHOICES, label=_("Type"), default='str')
|
type = serializers.ChoiceField(choices=TYPE_CHOICES, label=_("Type"), default='str')
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ example_info = [
|
|||||||
|
|
||||||
type_field_map = {
|
type_field_map = {
|
||||||
"str": serializers.CharField,
|
"str": serializers.CharField,
|
||||||
|
"password": serializers.CharField,
|
||||||
"int": serializers.IntegerField,
|
"int": serializers.IntegerField,
|
||||||
"bool": serializers.BooleanField,
|
"bool": serializers.BooleanField,
|
||||||
"text": serializers.CharField,
|
"text": serializers.CharField,
|
||||||
@@ -27,6 +28,8 @@ def set_default_if_need(data, i):
|
|||||||
def set_default_by_type(tp, data, field_info):
|
def set_default_by_type(tp, data, field_info):
|
||||||
if tp == 'str':
|
if tp == 'str':
|
||||||
data['max_length'] = 4096
|
data['max_length'] = 4096
|
||||||
|
elif tp == 'password':
|
||||||
|
data['write_only'] = True
|
||||||
elif tp == 'choice':
|
elif tp == 'choice':
|
||||||
choices = field_info.pop('choices', [])
|
choices = field_info.pop('choices', [])
|
||||||
if isinstance(choices, str):
|
if isinstance(choices, str):
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:2dd0610d610c2660f35d50dc2871ac08cc09080d2503e1080a57d97c47fea471
|
oid sha256:591b458d6f8ea8d125bd584ca57768cd5aa5a7103b42e345eaadac744a73d475
|
||||||
size 114418
|
size 114412
|
||||||
|
|||||||
@@ -1060,7 +1060,7 @@ msgstr "Web"
|
|||||||
|
|
||||||
#: assets/const/category.py:15
|
#: assets/const/category.py:15
|
||||||
msgid "Custom type"
|
msgid "Custom type"
|
||||||
msgstr "自定义类型"
|
msgstr "自定义"
|
||||||
|
|
||||||
#: assets/const/cloud.py:7
|
#: assets/const/cloud.py:7
|
||||||
msgid "Public cloud"
|
msgid "Public cloud"
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer):
|
|||||||
for i in range(0, len(account_ids), slice_count):
|
for i in range(0, len(account_ids), slice_count):
|
||||||
push_accounts_to_assets_task.delay(account_ids[i:i + slice_count])
|
push_accounts_to_assets_task.delay(account_ids[i:i + slice_count])
|
||||||
|
|
||||||
def validate_accounts(self, usernames: list[str]):
|
def validate_accounts(self, usernames):
|
||||||
template_ids = []
|
template_ids = []
|
||||||
account_usernames = []
|
account_usernames = []
|
||||||
for username in usernames:
|
for username in usernames:
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class Applet(JMSBaseModel):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(d, 'platform.yml')) as f:
|
with open(os.path.join(d, 'platform.yml')) as f:
|
||||||
data = yaml.safe_load(f)
|
data = yaml_load_with_i18n(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValidationError({'error': _('Load platform.yml failed: {}').format(e)})
|
raise ValidationError({'error': _('Load platform.yml failed: {}').format(e)})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user