mirror of https://github.com/jumpserver/jumpserver
pref: 修改 automations
parent
d6e36c873d
commit
076afb2b8b
|
@ -25,7 +25,7 @@ class CloudTypes(BaseType):
|
|||
'gather_facts_enabled': False,
|
||||
'verify_account_enabled': False,
|
||||
'change_secret_enabled': False,
|
||||
'create_account_enabled': False,
|
||||
'push_account_enabled': False,
|
||||
'gather_accounts_enabled': False,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class DatabaseTypes(BaseType):
|
|||
'gather_accounts_enabled': True,
|
||||
'verify_account_enabled': True,
|
||||
'change_secret_enabled': True,
|
||||
'create_account_enabled': True,
|
||||
'push_account_enabled': True,
|
||||
}
|
||||
}
|
||||
return constrains
|
||||
|
|
|
@ -40,7 +40,7 @@ class DeviceTypes(BaseType):
|
|||
'gather_accounts_enabled': False,
|
||||
'verify_account_enabled': False,
|
||||
'change_secret_enabled': False,
|
||||
'create_account_enabled': False,
|
||||
'push_account_enabled': False,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class HostTypes(BaseType):
|
|||
'gather_accounts_enabled': True,
|
||||
'verify_account_enabled': True,
|
||||
'change_secret_enabled': True,
|
||||
'create_account_enabled': True,
|
||||
'push_account_enabled': True,
|
||||
},
|
||||
cls.WINDOWS: {
|
||||
'ansible_config': {
|
||||
|
@ -73,8 +73,8 @@ class HostTypes(BaseType):
|
|||
{'name': 'macOS'},
|
||||
{'name': 'BSD'},
|
||||
{'name': 'AIX', 'automation': {
|
||||
'create_account_method': 'create_account_aix',
|
||||
'change_secret_method': 'change_secret_aix'
|
||||
'push_account_method': 'push_account_aix',
|
||||
'change_secret_method': 'push_secret_aix'
|
||||
}},
|
||||
],
|
||||
cls.WINDOWS: [
|
||||
|
|
|
@ -204,18 +204,18 @@ class AllTypes(ChoicesMixin):
|
|||
def create_or_update_internal_platforms(cls):
|
||||
print("Create internal platforms")
|
||||
for category, type_cls in cls.category_types():
|
||||
print("## Category: {}".format(category.label))
|
||||
print("\t## Category: {}".format(category.label))
|
||||
data = type_cls.internal_platforms()
|
||||
|
||||
for tp, platform_datas in data.items():
|
||||
print(" >> Type: {}".format(tp.label))
|
||||
print("\t >> Type: {}".format(tp.label))
|
||||
default_platform_data = cls.get_type_default_platform(category, tp)
|
||||
default_automation = default_platform_data.pop('automation', {})
|
||||
default_protocols = default_platform_data.pop('protocols', [])
|
||||
|
||||
for d in platform_datas:
|
||||
name = d['name']
|
||||
print(" - Platform: {}".format(name))
|
||||
print("\t - Platform: {}".format(name))
|
||||
_automation = d.pop('automation', {})
|
||||
_protocols = d.pop('_protocols', [])
|
||||
_protocols_setting = d.pop('protocols_setting', {})
|
||||
|
@ -246,7 +246,7 @@ class AllTypes(ChoicesMixin):
|
|||
user_platforms.update(internal=False)
|
||||
|
||||
for platform in user_platforms:
|
||||
print("Update platform: {}".format(platform.name))
|
||||
print("\t- Update platform: {}".format(platform.name))
|
||||
platform_data = cls.get_type_default_platform(platform.category, platform.type)
|
||||
cls.create_or_update_by_platform_data(platform.name, platform_data)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class WebTypes(BaseType):
|
|||
'gather_facts_enabled': False,
|
||||
'verify_account_enabled': False,
|
||||
'change_secret_enabled': False,
|
||||
'create_account_enabled': False,
|
||||
'push_account_enabled': False,
|
||||
'gather_accounts_enabled': False,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ class Migration(migrations.Migration):
|
|||
('port', models.IntegerField(verbose_name='Port')),
|
||||
('setting', models.JSONField(default=dict, verbose_name='Setting')),
|
||||
('platform', models.ForeignKey(on_delete=models.deletion.CASCADE, related_name='protocols', to='assets.platform'),),
|
||||
('default', models.BooleanField(default=True, verbose_name='Default')),
|
||||
('required', models.BooleanField(default=False, verbose_name='Required')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
|
@ -31,8 +33,8 @@ class Migration(migrations.Migration):
|
|||
('ping_method', models.CharField(blank=True, max_length=32, null=True, verbose_name='Ping method')),
|
||||
('gather_facts_enabled', models.BooleanField(default=False, verbose_name='Gather facts enabled')),
|
||||
('gather_facts_method', models.TextField(blank=True, max_length=32, null=True, verbose_name='Gather facts method')),
|
||||
('create_account_enabled', models.BooleanField(default=False, verbose_name='Create account enabled')),
|
||||
('create_account_method', models.TextField(blank=True, max_length=32, null=True, verbose_name='Create account method')),
|
||||
('push_account_enabled', models.BooleanField(default=False, verbose_name='Create account enabled')),
|
||||
('push_account_method', models.TextField(blank=True, max_length=32, null=True, verbose_name='Create account method')),
|
||||
('change_secret_enabled', models.BooleanField(default=False, verbose_name='Change password enabled')),
|
||||
('change_secret_method', models.TextField(blank=True, max_length=32, null=True, verbose_name='Change password method')),
|
||||
('verify_account_enabled', models.BooleanField(default=False, verbose_name='Verify account enabled')),
|
||||
|
|
|
@ -41,7 +41,7 @@ def migrate_database_to_asset(apps, *args):
|
|||
org_id=app.org_id
|
||||
)
|
||||
try:
|
||||
print("Create database: ", app.name)
|
||||
print("\t- Create database: ", app.name)
|
||||
db.save()
|
||||
except:
|
||||
failed_apps.append(app)
|
||||
|
@ -59,7 +59,7 @@ def migrate_cloud_to_asset(apps, *args):
|
|||
|
||||
for app in applications:
|
||||
attrs = app.attrs
|
||||
print("Create cloud: {}".format(app.name))
|
||||
print("\t- Create cloud: {}".format(app.name))
|
||||
cloud = cloud_model(
|
||||
id=app.id, name=app.name,
|
||||
address=attrs.get('cluster', ''),
|
||||
|
@ -115,7 +115,7 @@ def migrate_to_nodes(apps, *args):
|
|||
)
|
||||
if not node:
|
||||
continue
|
||||
print("Set node asset: ", node)
|
||||
print("\t- Set node asset: ", node)
|
||||
node.assets_amount = len(assets)
|
||||
node.save()
|
||||
node.assets.set(assets)
|
||||
|
|
|
@ -19,23 +19,13 @@ class Migration(migrations.Migration):
|
|||
migrations.CreateModel(
|
||||
name='HistoricalAccount',
|
||||
fields=[
|
||||
('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
|
||||
('id', models.UUIDField(db_index=True, default=uuid.uuid4)),
|
||||
('name', models.CharField(max_length=128, verbose_name='Name')),
|
||||
('username', models.CharField(blank=True, db_index=True, max_length=128, verbose_name='Username')),
|
||||
('secret_type', models.CharField(choices=[('password', 'Password'), ('ssh_key', 'SSH key'), ('access_key', 'Access key'), ('token', 'Token')], default='password', max_length=16, verbose_name='Secret type')),
|
||||
('secret', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Secret')),
|
||||
('comment', models.TextField(blank=True, verbose_name='Comment')),
|
||||
('date_created', models.DateTimeField(blank=True, editable=False, verbose_name='Date created')),
|
||||
('date_updated', models.DateTimeField(blank=True, editable=False, verbose_name='Date updated')),
|
||||
('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')),
|
||||
('privileged', models.BooleanField(default=False, verbose_name='Privileged')),
|
||||
('version', models.IntegerField(default=0, verbose_name='Version')),
|
||||
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('history_date', models.DateTimeField(db_index=True)),
|
||||
('history_change_reason', models.CharField(max_length=100, null=True)),
|
||||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
|
||||
('asset', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='assets.asset', verbose_name='Asset')),
|
||||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
|
@ -74,11 +64,6 @@ class Migration(migrations.Migration):
|
|||
name='su_from',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='su_to', to='assets.account', verbose_name='Su from'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='historicalaccount',
|
||||
name='su_from',
|
||||
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='assets.account', verbose_name='Su from'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AccountTemplate',
|
||||
fields=[
|
||||
|
|
|
@ -11,7 +11,7 @@ def migrate_accounts(apps, schema_editor):
|
|||
|
||||
count = 0
|
||||
bulk_size = 1000
|
||||
print("\nStart migrate accounts")
|
||||
print("\n\tStart migrate accounts")
|
||||
while True:
|
||||
start = time.time()
|
||||
auth_books = auth_book_model.objects \
|
||||
|
@ -71,7 +71,7 @@ def migrate_accounts(apps, schema_editor):
|
|||
accounts.append(account)
|
||||
|
||||
account_model.objects.bulk_create(accounts, ignore_conflicts=True)
|
||||
print("Create accounts: {}-{} using: {:.2f}s".format(
|
||||
print("\t - Create accounts: {}-{} using: {:.2f}s".format(
|
||||
count - len(auth_books), count, time.time()-start
|
||||
))
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ def migrate_asset_protocols(apps, schema_editor):
|
|||
|
||||
count = 0
|
||||
bulk_size = 1000
|
||||
print("\nStart migrate asset protocols")
|
||||
print("\n\tStart migrate asset protocols")
|
||||
while True:
|
||||
start = time.time()
|
||||
assets = asset_model.objects.all()[count:count+bulk_size]
|
||||
|
@ -36,7 +36,7 @@ def migrate_asset_protocols(apps, schema_editor):
|
|||
assets_protocols.append(protocol)
|
||||
|
||||
protocol_model.objects.bulk_create(assets_protocols, ignore_conflicts=True)
|
||||
print("Create asset protocols: {}-{} using: {:.2f}s".format(
|
||||
print("\t - Create asset protocols: {}-{} using: {:.2f}s".format(
|
||||
count - len(assets), count, time.time()-start
|
||||
))
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ def migrate_command_filter_to_assets(apps, schema_editor):
|
|||
|
||||
count = 0
|
||||
bulk_size = 1000
|
||||
print("\nStart migrate command filters to assets")
|
||||
print("\n\tStart migrate command filters to assets")
|
||||
while True:
|
||||
start = time.time()
|
||||
command_filters = command_filter_model.objects.all() \
|
||||
|
@ -23,7 +23,7 @@ def migrate_command_filter_to_assets(apps, schema_editor):
|
|||
updated.append(command_filter)
|
||||
command_filter_model.objects.bulk_update(updated, ['accounts'])
|
||||
|
||||
print("Create assets: {}-{} using: {:.2f}s".format(
|
||||
print("\tCreate assets: {}-{} using: {:.2f}s".format(
|
||||
count - len(command_filters), count, time.time() - start
|
||||
))
|
||||
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
# Generated by Django 3.2.13 on 2022-10-09 08:50
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def migrate_create_history_account(apps, schema_editor):
|
||||
db_alias = schema_editor.connection.alias
|
||||
account_model = apps.get_model('assets', 'Account')
|
||||
history_account_model = apps.get_model('assets', 'HistoricalAccount')
|
||||
history_accounts = []
|
||||
for account in account_model.objects.using(db_alias).all():
|
||||
data = {
|
||||
'id': account.id,
|
||||
'secret': account.secret,
|
||||
'secret_type': account.secret_type,
|
||||
'history_date': account.date_created,
|
||||
}
|
||||
history_accounts.append(history_account_model(**data))
|
||||
history_account_model.objects.using(db_alias).bulk_create(history_accounts)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('assets', '0106_auto_20220916_1556'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='asset',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='comment',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='created_by',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='date_created',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='date_updated',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='name',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='org_id',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='privileged',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='su_from',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='username',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='historicalaccount',
|
||||
name='version',
|
||||
),
|
||||
migrations.RunPython(migrate_create_history_account),
|
||||
]
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.2.14 on 2022-10-10 01:59
|
||||
# Generated by Django 3.2.14 on 2022-10-19 03:15
|
||||
|
||||
import common.db.fields
|
||||
from django.conf import settings
|
||||
|
@ -11,10 +11,26 @@ class Migration(migrations.Migration):
|
|||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('assets', '0107_account_history'),
|
||||
('assets', '0106_auto_20220916_1556'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AutomationExecution',
|
||||
fields=[
|
||||
('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
|
||||
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
|
||||
('status', models.CharField(default='pending', max_length=16)),
|
||||
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date created')),
|
||||
('date_start', models.DateTimeField(db_index=True, null=True, verbose_name='Date start')),
|
||||
('date_finished', models.DateTimeField(null=True, verbose_name='Date finished')),
|
||||
('snapshot', common.db.fields.EncryptJsonDictTextField(blank=True, default=dict, null=True, verbose_name='Automation snapshot')),
|
||||
('trigger', models.CharField(choices=[('manual', 'Manual trigger'), ('timing', 'Timing trigger')], default='manual', max_length=128, verbose_name='Trigger mode')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Automation strategy execution',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='BaseAutomation',
|
||||
fields=[
|
||||
|
@ -30,6 +46,7 @@ class Migration(migrations.Migration):
|
|||
('crontab', models.CharField(blank=True, max_length=128, null=True, verbose_name='Regularly perform')),
|
||||
('accounts', models.JSONField(default=list, verbose_name='Accounts')),
|
||||
('type', models.CharField(max_length=16, verbose_name='Type')),
|
||||
('is_active', models.BooleanField(default=True, verbose_name='Is active')),
|
||||
('comment', models.TextField(blank=True, verbose_name='Comment')),
|
||||
('assets', models.ManyToManyField(blank=True, to='assets.Asset', verbose_name='Assets')),
|
||||
('nodes', models.ManyToManyField(blank=True, to='assets.Node', verbose_name='Nodes')),
|
||||
|
@ -54,64 +71,103 @@ class Migration(migrations.Migration):
|
|||
name='updated_by',
|
||||
field=models.CharField(blank=True, max_length=32, null=True, verbose_name='Updated by'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='platformautomation',
|
||||
name='push_account_enabled',
|
||||
field=models.BooleanField(default=False, verbose_name='Push account enabled'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='platformautomation',
|
||||
name='push_account_method',
|
||||
field=models.TextField(blank=True, max_length=32, null=True, verbose_name='Push account method'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='platformprotocol',
|
||||
name='default',
|
||||
field=models.BooleanField(default=False, verbose_name='Default'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DiscoveryAutomation',
|
||||
name='DiscoveryAccountAutomation',
|
||||
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': 'Discovery strategy',
|
||||
'verbose_name': 'Discovery account automation',
|
||||
},
|
||||
bases=('assets.baseautomation',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ReconcileAutomation',
|
||||
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': 'Reconcile strategy',
|
||||
'verbose_name': 'Gather asset facts',
|
||||
},
|
||||
bases=('assets.baseautomation',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='VerifyAutomation',
|
||||
name='PushAccountAutomation',
|
||||
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': 'Verify strategy',
|
||||
'verbose_name': 'Push automation',
|
||||
},
|
||||
bases=('assets.baseautomation',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AutomationExecution',
|
||||
name='VerifySecretAutomation',
|
||||
fields=[
|
||||
('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
|
||||
('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': 'Verify secret automation',
|
||||
},
|
||||
bases=('assets.baseautomation',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ChangeSecretRecord',
|
||||
fields=[
|
||||
('created_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Created by')),
|
||||
('updated_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Updated by')),
|
||||
('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
|
||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
|
||||
('old_secret', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Old secret')),
|
||||
('new_secret', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Secret')),
|
||||
('date_started', models.DateTimeField(blank=True, null=True, verbose_name='Date started')),
|
||||
('date_finished', models.DateTimeField(blank=True, null=True, verbose_name='Date finished')),
|
||||
('status', models.CharField(default='pending', max_length=16)),
|
||||
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date created')),
|
||||
('date_start', models.DateTimeField(db_index=True, null=True, verbose_name='Date start')),
|
||||
('date_finished', models.DateTimeField(null=True, verbose_name='Date finished')),
|
||||
('snapshot', common.db.fields.EncryptJsonDictTextField(blank=True, default=dict, null=True, verbose_name='Automation snapshot')),
|
||||
('trigger', models.CharField(choices=[('manual', 'Manual trigger'), ('timing', 'Timing trigger')], default='manual', max_length=128, verbose_name='Trigger mode')),
|
||||
('automation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='executions', to='assets.baseautomation', verbose_name='Automation strategy')),
|
||||
('error', models.TextField(blank=True, null=True, verbose_name='Error')),
|
||||
('account', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='assets.account')),
|
||||
('execution', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assets.automationexecution')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Automation strategy execution',
|
||||
'verbose_name': 'Change secret',
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='automationexecution',
|
||||
name='automation',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='executions', to='assets.baseautomation', verbose_name='Automation strategy'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ChangePasswordAutomation',
|
||||
name='ChangeSecretAutomation',
|
||||
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')),
|
||||
('secret_types', models.JSONField(default=list, verbose_name='Secret types')),
|
||||
('password_strategy', models.CharField(choices=[('specific', 'Specific'), ('random_one', 'All assets use the same random password'), ('random_all', 'All assets use different random password')], default='random_one', max_length=16, verbose_name='Password strategy')),
|
||||
('password', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Secret')),
|
||||
('recipients', models.ManyToManyField(blank=True, related_name='recipients_change_auth_strategy', to=settings.AUTH_USER_MODEL, verbose_name='Recipient')),
|
||||
('password_rules', models.JSONField(default=dict, verbose_name='Password rules')),
|
||||
('ssh_key_strategy', models.CharField(choices=[('specific', 'Specific'), ('random_one', 'All assets use the same random password'), ('random_all', 'All assets use different random password')], default='random_one', max_length=16)),
|
||||
('ssh_key', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='SSH key')),
|
||||
('ssh_key_change_strategy', models.CharField(choices=[('add', 'Append SSH KEY'), ('set', 'Empty and append SSH KEY'), ('set_jms', 'Replace (The key generated by JumpServer) ')], default='add', max_length=16, verbose_name='SSH key strategy')),
|
||||
('recipients', models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL, verbose_name='Recipient')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Change auth strategy',
|
||||
'verbose_name': 'Change secret automation',
|
||||
},
|
||||
bases=('assets.baseautomation',),
|
||||
),
|
||||
|
||||
]
|
|
@ -1,83 +0,0 @@
|
|||
# Generated by Django 3.2.14 on 2022-10-13 09:51
|
||||
|
||||
import common.db.fields
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('assets', '0108_migrate_automation'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='ChangePasswordAutomation',
|
||||
new_name='ChangeSecretAutomation',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='baseautomation',
|
||||
name='is_active',
|
||||
field=models.BooleanField(default=True, verbose_name='Is active'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='changesecretautomation',
|
||||
name='password_rules',
|
||||
field=models.JSONField(default=dict, verbose_name='Password rules'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='changesecretautomation',
|
||||
name='password_strategy',
|
||||
field=models.CharField(choices=[('specific', 'Specific'), ('random_one', 'All assets use the same random password'), ('random_all', 'All assets use different random password')], default='random_one', max_length=16, verbose_name='Password strategy'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='changesecretautomation',
|
||||
name='secret_types',
|
||||
field=models.JSONField(default=list, verbose_name='Secret types'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='changesecretautomation',
|
||||
name='ssh_key',
|
||||
field=common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='SSH key'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='changesecretautomation',
|
||||
name='ssh_key_change_strategy',
|
||||
field=models.CharField(choices=[('add', 'Append SSH KEY'), ('set', 'Empty and append SSH KEY'), ('set_jms', 'Replace (The key generated by JumpServer) ')], default='add', max_length=16, verbose_name='SSH key strategy'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='changesecretautomation',
|
||||
name='ssh_key_strategy',
|
||||
field=models.CharField(choices=[('specific', 'Specific'), ('random_one', 'All assets use the same random password'), ('random_all', 'All assets use different random password')], default='random_one', max_length=16),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='changesecretautomation',
|
||||
name='recipients',
|
||||
field=models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL, verbose_name='Recipient'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ChangeSecretRecord',
|
||||
fields=[
|
||||
('created_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Created by')),
|
||||
('updated_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Updated by')),
|
||||
('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
|
||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
|
||||
('old_secret', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Old secret')),
|
||||
('new_secret', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Secret')),
|
||||
('date_started', models.DateTimeField(blank=True, null=True, verbose_name='Date started')),
|
||||
('date_finished', models.DateTimeField(blank=True, null=True, verbose_name='Date finished')),
|
||||
('status', models.CharField(default='pending', max_length=16)),
|
||||
('error', models.TextField(blank=True, null=True, verbose_name='Error')),
|
||||
('account', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='assets.account')),
|
||||
('execution', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assets.automationexecution')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Change secret',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -1,24 +0,0 @@
|
|||
# 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',),
|
||||
),
|
||||
]
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 3.2.14 on 2022-10-17 06:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0110_gatherfactsautomation'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='platformprotocol',
|
||||
name='default',
|
||||
field=models.BooleanField(default=True, verbose_name='Default'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='platformprotocol',
|
||||
name='required',
|
||||
field=models.BooleanField(default=False, verbose_name='Required'),
|
||||
),
|
||||
]
|
|
@ -1,5 +1,5 @@
|
|||
from .change_secret import *
|
||||
from .account_discovery import *
|
||||
from .account_reconcile import *
|
||||
from .account_verify import *
|
||||
from .discovery_account import *
|
||||
from .push_account import *
|
||||
from .verify_secret import *
|
||||
from .gather_facts import *
|
||||
|
|
|
@ -39,7 +39,7 @@ class ChangeSecretAutomation(BaseAutomation):
|
|||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Change auth strategy")
|
||||
verbose_name = _("Change secret automation")
|
||||
|
||||
|
||||
class ChangeSecretRecord(JMSBaseModel):
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from ops.const import StrategyChoice
|
||||
from .base import BaseAutomation
|
||||
|
||||
|
||||
class ReconcileAutomation(BaseAutomation):
|
||||
class DiscoveryAccountAutomation(BaseAutomation):
|
||||
class Meta:
|
||||
verbose_name = _("Reconcile strategy")
|
||||
verbose_name = _("Discovery account automation")
|
||||
|
||||
def to_attr_json(self):
|
||||
attr_json = super().to_attr_json()
|
||||
attr_json.update({
|
||||
'type': StrategyChoice.push
|
||||
'type': 'discover_account'
|
||||
})
|
||||
return attr_json
|
|
@ -1,17 +1,15 @@
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from ops.const import StrategyChoice
|
||||
from ops.ansible.runner import PlaybookRunner
|
||||
from .base import BaseAutomation
|
||||
|
||||
|
||||
class DiscoveryAutomation(BaseAutomation):
|
||||
class PushAccountAutomation(BaseAutomation):
|
||||
class Meta:
|
||||
verbose_name = _("Discovery strategy")
|
||||
verbose_name = _("Push automation")
|
||||
|
||||
def to_attr_json(self):
|
||||
attr_json = super().to_attr_json()
|
||||
attr_json.update({
|
||||
'type': StrategyChoice.collect
|
||||
'type': 'push_account'
|
||||
})
|
||||
return attr_json
|
|
@ -4,10 +4,10 @@ from ops.const import StrategyChoice
|
|||
from .base import BaseAutomation
|
||||
|
||||
|
||||
class VerifyAutomation(BaseAutomation):
|
||||
class VerifySecretAutomation(BaseAutomation):
|
||||
class Meta:
|
||||
verbose_name = _("Verify strategy")
|
||||
verbose_name = _("Verify secret automation")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.type = 'verify'
|
||||
self.type = 'verify_secret'
|
||||
super().save(*args, **kwargs)
|
|
@ -46,8 +46,8 @@ class PlatformAutomation(models.Model):
|
|||
ping_method = models.CharField(max_length=32, blank=True, null=True, verbose_name=_("Ping method"))
|
||||
gather_facts_enabled = models.BooleanField(default=False, verbose_name=_("Gather facts enabled"))
|
||||
gather_facts_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Gather facts method"))
|
||||
create_account_enabled = models.BooleanField(default=False, verbose_name=_("Create account enabled"))
|
||||
create_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Create account method"))
|
||||
push_account_enabled = models.BooleanField(default=False, verbose_name=_("Push account enabled"))
|
||||
push_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Push account method"))
|
||||
change_secret_enabled = models.BooleanField(default=False, verbose_name=_("Change password enabled"))
|
||||
change_secret_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Change password method"))
|
||||
verify_account_enabled = models.BooleanField(default=False, verbose_name=_("Verify account enabled"))
|
||||
|
|
|
@ -32,7 +32,7 @@ def update_internal_platforms(platform_model):
|
|||
{'name': 'Windows', 'category': 'host', 'type': 'unix'},
|
||||
{
|
||||
'name': 'AIX', 'category': 'host', 'type': 'unix',
|
||||
'create_account_method': 'create_account_aix',
|
||||
'push_account_method': 'create_account_aix',
|
||||
'change_secret_method': 'change_secret_aix',
|
||||
},
|
||||
{'name': 'Windows', 'category': 'host', 'type': 'windows'},
|
||||
|
|
|
@ -38,7 +38,7 @@ class PlatformAutomationSerializer(serializers.ModelSerializer):
|
|||
'id', 'ansible_enabled', 'ansible_config',
|
||||
'ping_enabled', 'ping_method',
|
||||
'gather_facts_enabled', 'gather_facts_method',
|
||||
'create_account_enabled', 'create_account_method',
|
||||
'push_account_enabled', 'push_account_method',
|
||||
'change_secret_enabled', 'change_secret_method',
|
||||
'verify_account_enabled', 'verify_account_method',
|
||||
'gather_accounts_enabled', 'gather_accounts_method',
|
||||
|
@ -50,8 +50,8 @@ class PlatformAutomationSerializer(serializers.ModelSerializer):
|
|||
'gather_facts_method': {'label': '收集信息方式'},
|
||||
'verify_account_enabled': {'label': '启用校验账号'},
|
||||
'verify_account_method': {'label': '校验账号方式'},
|
||||
'create_account_enabled': {'label': '启用推送账号'},
|
||||
'create_account_method': {'label': '推送账号方式'},
|
||||
'push_account_enabled': {'label': '启用推送账号'},
|
||||
'push_account_method': {'label': '推送账号方式'},
|
||||
'change_secret_enabled': {'label': '启用账号改密'},
|
||||
'change_secret_method': {'label': '账号创建改密方式'},
|
||||
'gather_accounts_enabled': {'label': '启用账号收集'},
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -30,7 +30,7 @@ def init_user_msg_subscription(apps, schema_editor):
|
|||
|
||||
to_create.append(UserMsgSubscription(user=user, receive_backends=receive_backends))
|
||||
UserMsgSubscription.objects.bulk_create(to_create)
|
||||
print(f'\n Init user message subscription: {len(to_create)}')
|
||||
print(f'\n\tInit user message subscription: {len(to_create)}')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
|
|
@ -164,7 +164,7 @@ class BuiltinRole:
|
|||
@classmethod
|
||||
def sync_to_db(cls, show_msg=False):
|
||||
roles = cls.get_roles()
|
||||
print("\n Update builtin roles")
|
||||
print("\n\tUpdate builtin roles")
|
||||
|
||||
for pre_role in roles.values():
|
||||
role, created = pre_role.update_or_create_role()
|
||||
|
|
|
@ -29,7 +29,7 @@ def migrate_system_role_binding(apps, schema_editor):
|
|||
role_bindings.append(role_binding)
|
||||
|
||||
role_binding_model.objects.bulk_create(role_bindings, ignore_conflicts=True)
|
||||
print("Create role binding: {}-{} using: {:.2f}s".format(
|
||||
print("\tCreate role binding: {}-{} using: {:.2f}s".format(
|
||||
count, count + len(users), time.time()-start
|
||||
))
|
||||
count += len(users)
|
||||
|
@ -62,7 +62,7 @@ def migrate_org_role_binding(apps, schema_editor):
|
|||
)
|
||||
role_bindings.append(role_binding)
|
||||
role_binding_model.objects.bulk_create(role_bindings, ignore_conflicts=True)
|
||||
print("Create role binding: {}-{} using: {:.2f}s".format(
|
||||
print("\tCreate role binding: {}-{} using: {:.2f}s".format(
|
||||
count, count + len(members), time.time()-start
|
||||
))
|
||||
count += len(members)
|
||||
|
|
|
@ -11,7 +11,7 @@ def after_migrate_update_builtin_role_permissions(sender, app_config, **kwargs):
|
|||
# 最后一个 app migrations 后执行, 更新内置角色的权限
|
||||
last_app = list(apps.get_app_configs())[-1]
|
||||
if app_config.name == last_app.name:
|
||||
print("After migration, update builtin role permissions")
|
||||
print("\tAfter migration, update builtin role permissions")
|
||||
BuiltinRole.sync_to_db()
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ def fill_ticket_serial_number(apps, schema_editor):
|
|||
curr_day = '00000000'
|
||||
curr_num = 1
|
||||
|
||||
print(f'\nFill ticket serial number ... ', end='')
|
||||
print(f'\n Fill ticket serial number ... ')
|
||||
for ticket in tickets:
|
||||
# 跑这个脚本的时候,所有 ticket.serial_num == null
|
||||
date_created = as_current_tz(ticket.date_created)
|
||||
|
|
|
@ -15,7 +15,7 @@ def migrate_system_to_account(apps, schema_editor):
|
|||
(apply_login_asset_ticket_model, 'apply_login_system_user', 'apply_login_account', False),
|
||||
)
|
||||
|
||||
print("\nStart migrate system user to account")
|
||||
print("\n Start migrate system user to account")
|
||||
for model, old_field, new_field, m2m in model_system_user_account:
|
||||
print(" - migrate '{}'".format(model.__name__))
|
||||
count = 0
|
||||
|
|
|
@ -254,7 +254,7 @@ class RoleManager(models.Manager):
|
|||
self.user.expire_users_rbac_perms_cache()
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error('Create role binding error: {}'.format(e))
|
||||
logger.error('\tCreate role binding error: {}'.format(e))
|
||||
|
||||
def set(self, roles, clear=False):
|
||||
if clear:
|
||||
|
|
|
@ -42,7 +42,7 @@ def migrate_system_role_binding(apps, schema_editor):
|
|||
role_bindings.append(role_binding)
|
||||
|
||||
role_binding_model.objects.bulk_create(role_bindings, ignore_conflicts=True)
|
||||
print("Create role binding: {}-{} using: {:.2f}s".format(
|
||||
print("\tCreate role binding: {}-{} using: {:.2f}s".format(
|
||||
count, count + len(users), time.time()-start
|
||||
))
|
||||
count += len(users)
|
||||
|
|
Loading…
Reference in New Issue