From 4e8e4e4bb76df2db5c181b10791be26e35342f47 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 14 Oct 2022 19:40:51 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?gather=20facts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0110_gatherfactsautomation.py | 24 +++++++++++++++++++ apps/assets/models/automations/__init__.py | 1 + .../assets/models/automations/gather_facts.py | 3 +++ apps/common/hashers/sm3.py | 12 +++++----- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 apps/assets/migrations/0110_gatherfactsautomation.py diff --git a/apps/assets/migrations/0110_gatherfactsautomation.py b/apps/assets/migrations/0110_gatherfactsautomation.py new file mode 100644 index 000000000..8c26d5cf8 --- /dev/null +++ b/apps/assets/migrations/0110_gatherfactsautomation.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.14 on 2022-10-14 11:40 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0109_auto_20221013_1751'), + ] + + operations = [ + migrations.CreateModel( + name='GatherFactsAutomation', + fields=[ + ('baseautomation_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='assets.baseautomation')), + ], + options={ + 'verbose_name': 'Gather asset facts', + }, + bases=('assets.baseautomation',), + ), + ] diff --git a/apps/assets/models/automations/__init__.py b/apps/assets/models/automations/__init__.py index 4e46ff150..5aa130c6d 100644 --- a/apps/assets/models/automations/__init__.py +++ b/apps/assets/models/automations/__init__.py @@ -2,3 +2,4 @@ from .change_secret import * from .account_discovery import * from .account_reconcile import * from .account_verify import * +from .gather_facts import * diff --git a/apps/assets/models/automations/gather_facts.py b/apps/assets/models/automations/gather_facts.py index d86ead8e8..251e63944 100644 --- a/apps/assets/models/automations/gather_facts.py +++ b/apps/assets/models/automations/gather_facts.py @@ -3,6 +3,9 @@ from django.utils.translation import ugettext_lazy as _ from .base import BaseAutomation +__all__ = ['GatherFactsAutomation'] + + class GatherFactsAutomation(BaseAutomation): class Meta: verbose_name = _("Gather asset facts") diff --git a/apps/common/hashers/sm3.py b/apps/common/hashers/sm3.py index a675dc9df..da360ea30 100644 --- a/apps/common/hashers/sm3.py +++ b/apps/common/hashers/sm3.py @@ -8,11 +8,11 @@ class Hasher: block_size = 64 digest_size = 32 - def __init__(self, key): - self.key = key + def __init__(self, data): + self.__data = data def hexdigest(self): - return sm3.sm3_hash(func.bytes_to_list(self.key)) + return sm3.sm3_hash(func.bytes_to_list(self.__data)) def digest(self): return bytes.fromhex(self.hexdigest()) @@ -21,11 +21,11 @@ class Hasher: def hash(msg=b''): return Hasher(msg) - def update(self, msg): - self.key += msg + def update(self, data): + self.__data += data def copy(self): - return Hasher(self.key) + return Hasher(self.__data) class PBKDF2SM3PasswordHasher(PBKDF2PasswordHasher):