mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-26 07:22:27 +00:00
feat: 账号推送附加参数 (#10080)
* feat: 账号推送附加参数 * perf: 通过节点 资产 过滤平台api * perf: push automation params * perf: 修改playbook * perf: params serializer * perf: 账号推送playbook 调整 * perf: Automation serializer add params field * perf: params 非必填 * perf: 添加is_params 给前端判断 * perf: is_params bool * perf: 修改push account ansible逻辑 * perf: 修改获取push_kwargs方法 * perf: platform migrate * perf: 修改api * perf: 单个推送 * perf: push account * perf: 修改asset auto_config --------- Co-authored-by: feng <1304903146@qq.com> Co-authored-by: feng626 <57284900+feng626@users.noreply.github.com>
This commit is contained in:
@@ -27,13 +27,16 @@ class AccountCreateUpdateSerializerMixin(serializers.Serializer):
|
||||
push_now = serializers.BooleanField(
|
||||
default=False, label=_("Push now"), write_only=True
|
||||
)
|
||||
params = serializers.JSONField(
|
||||
decoder=None, encoder=None, required=False, style={'base_template': 'textarea.html'}
|
||||
)
|
||||
on_invalid = LabeledChoiceField(
|
||||
choices=AccountInvalidPolicy.choices, default=AccountInvalidPolicy.ERROR,
|
||||
write_only=True, label=_('Exist policy')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
fields = ['template', 'push_now', 'on_invalid']
|
||||
fields = ['template', 'push_now', 'params', 'on_invalid']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -93,10 +96,10 @@ class AccountCreateUpdateSerializerMixin(serializers.Serializer):
|
||||
initial_data.update(attrs)
|
||||
|
||||
@staticmethod
|
||||
def push_account_if_need(instance, push_now, stat):
|
||||
def push_account_if_need(instance, push_now, params, stat):
|
||||
if not push_now or stat != 'created':
|
||||
return
|
||||
push_accounts_to_assets_task.delay([str(instance.id)])
|
||||
push_accounts_to_assets_task.delay([str(instance.id)], params)
|
||||
|
||||
def get_validators(self):
|
||||
_validators = super().get_validators()
|
||||
@@ -147,8 +150,9 @@ class AccountCreateUpdateSerializerMixin(serializers.Serializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
push_now = validated_data.pop('push_now', None)
|
||||
params = validated_data.pop('params', None)
|
||||
instance, stat = self.do_create(validated_data)
|
||||
self.push_account_if_need(instance, push_now, stat)
|
||||
self.push_account_if_need(instance, push_now, params, stat)
|
||||
return instance
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
@@ -156,9 +160,10 @@ class AccountCreateUpdateSerializerMixin(serializers.Serializer):
|
||||
validated_data.pop('username', None)
|
||||
validated_data.pop('on_invalid', None)
|
||||
push_now = validated_data.pop('push_now', None)
|
||||
params = validated_data.pop('params', None)
|
||||
validated_data['source_id'] = None
|
||||
instance = super().update(instance, validated_data)
|
||||
self.push_account_if_need(instance, push_now, 'updated')
|
||||
self.push_account_if_need(instance, push_now, params, 'updated')
|
||||
return instance
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user