mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 14:27:42 -02:30
remove backwords migraiton support for inv plugins
* Do not write out inventory source_vars to a file on disk as they _may_ contain sensitive information. This also removes support for backwards migrations. This is fine, backwards migration is really only useful during development.
This commit is contained in:
committed by
Ryan Petrello
parent
dcf5917a4e
commit
03ad1aa141
@@ -1,7 +1,6 @@
|
|||||||
# Generated by Django 2.2.11 on 2020-07-20 19:56
|
# Generated by Django 2.2.11 on 2020-07-20 19:56
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import json
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
@@ -12,7 +11,6 @@ from ._inventory_source_vars import FrozenInjectors
|
|||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.migrations')
|
logger = logging.getLogger('awx.main.migrations')
|
||||||
BACKUP_FILENAME = '/tmp/tower_migration_inventory_source_vars.json'
|
|
||||||
|
|
||||||
|
|
||||||
def _get_inventory_sources(InventorySource):
|
def _get_inventory_sources(InventorySource):
|
||||||
@@ -34,8 +32,6 @@ def inventory_source_vars_forward(apps, schema_editor):
|
|||||||
|
|
||||||
if inv_source_obj.source in FrozenInjectors:
|
if inv_source_obj.source in FrozenInjectors:
|
||||||
source_vars_backup[inv_source_obj.id] = dict(inv_source_obj.source_vars_dict)
|
source_vars_backup[inv_source_obj.id] = dict(inv_source_obj.source_vars_dict)
|
||||||
with open(BACKUP_FILENAME, 'w') as fh:
|
|
||||||
json.dump(source_vars_backup, fh)
|
|
||||||
|
|
||||||
injector = FrozenInjectors[inv_source_obj.source]()
|
injector = FrozenInjectors[inv_source_obj.source]()
|
||||||
new_inv_source_vars = injector.inventory_as_dict(inv_source_obj, None)
|
new_inv_source_vars = injector.inventory_as_dict(inv_source_obj, None)
|
||||||
@@ -43,21 +39,6 @@ def inventory_source_vars_forward(apps, schema_editor):
|
|||||||
inv_source_obj.save()
|
inv_source_obj.save()
|
||||||
|
|
||||||
|
|
||||||
def inventory_source_vars_backward(apps, schema_editor):
|
|
||||||
InventorySource = apps.get_model("main", "InventorySource")
|
|
||||||
try:
|
|
||||||
with open(BACKUP_FILENAME, 'r') as fh:
|
|
||||||
source_vars_backup = json.load(fh)
|
|
||||||
except FileNotFoundError:
|
|
||||||
print(f"Rollback file not found {BACKUP_FILENAME}")
|
|
||||||
return
|
|
||||||
|
|
||||||
for inv_source_obj in _get_inventory_sources(InventorySource):
|
|
||||||
if inv_source_obj.id in source_vars_backup:
|
|
||||||
inv_source_obj.source_vars = source_vars_backup[inv_source_obj.id]
|
|
||||||
inv_source_obj.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -65,7 +46,7 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RunPython(inventory_source_vars_forward, inventory_source_vars_backward,),
|
migrations.RunPython(inventory_source_vars_forward),
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
model_name='inventorysource',
|
model_name='inventorysource',
|
||||||
name='group_by',
|
name='group_by',
|
||||||
|
|||||||
Reference in New Issue
Block a user