diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index e8cf770f5..1640c7f32 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -87,6 +87,9 @@ class SystemUser(BaseUser): (PROTOCOL_POSTGRESQL, 'postgresql'), (PROTOCOL_K8S, 'k8s'), ) + + SUPPORT_PUSH_PROTOCOLS = [PROTOCOL_SSH, PROTOCOL_RDP] + ASSET_CATEGORY_PROTOCOLS = [ PROTOCOL_SSH, PROTOCOL_RDP, PROTOCOL_TELNET, PROTOCOL_VNC ] @@ -151,11 +154,15 @@ class SystemUser(BaseUser): return self.get_login_mode_display() def is_need_push(self): - if self.auto_push and self.protocol in [self.PROTOCOL_SSH, self.PROTOCOL_RDP]: + if self.auto_push and self.is_protocol_support_push: return True else: return False + @property + def is_protocol_support_push(self): + return self.protocol in self.SUPPORT_PUSH_PROTOCOLS + @property def is_need_cmd_filter(self): return self.protocol not in [self.PROTOCOL_RDP, self.PROTOCOL_VNC] diff --git a/apps/assets/signals_handler/common.py b/apps/assets/signals_handler/common.py index af6a7895c..50f7f41f1 100644 --- a/apps/assets/signals_handler/common.py +++ b/apps/assets/signals_handler/common.py @@ -193,7 +193,8 @@ def on_asset_nodes_add(instance, action, reverse, pk_set, **kwargs): systemuser_id=system_user_id, asset_id=asset_id )) - push_system_user_to_assets.delay(system_user_id, asset_ids_to_push) + if asset_ids_to_push: + push_system_user_to_assets.delay(system_user_id, asset_ids_to_push) m2m_model.objects.bulk_create(to_create) diff --git a/apps/assets/tasks/utils.py b/apps/assets/tasks/utils.py index 9956665ee..93aaa4bfc 100644 --- a/apps/assets/tasks/utils.py +++ b/apps/assets/tasks/utils.py @@ -25,10 +25,13 @@ def check_asset_can_run_ansible(asset): def check_system_user_can_run_ansible(system_user): - if not system_user.is_need_push(): - msg = _("Push system user task skip, auto push not enable or " - "protocol is not ssh or rdp: {}").format(system_user.name) - logger.info(msg) + if not system_user.auto_push: + logger.warn(f'Push system user task skip, auto push not enable: system_user={system_user.name}') + return False + if not system_user.is_protocol_support_push: + logger.warn(f'Push system user task skip, protocol not support: ' + f'system_user={system_user.name} protocol={system_user.protocol} ' + f'support_protocol={system_user.SUPPORT_PUSH_PROTOCOLS}') return False # Push root as system user is dangerous @@ -37,10 +40,6 @@ def check_system_user_can_run_ansible(system_user): logger.info(msg) return False - # if system_user.protocol != "ssh": - # msg = _("System user protocol not ssh: {}".format(system_user)) - # logger.info(msg) - # return False return True