Skip to content

Commit

Permalink
filter for only values that have been migrated, indicated by the aes-…
Browse files Browse the repository at this point in the history
…cbc prefix
  • Loading branch information
Jtang-1 committed Jan 22, 2025
1 parent 64d97ca commit 8779e6a
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db.migrations import RunPython

from corehq.util.django_migrations import skip_on_fresh_install
from corehq.apps.geospatial.const import ALGO_AES, ALGO_AES_CBC
from corehq.motech.const import ALGO_AES, ALGO_AES_CBC
from corehq.motech.utils import (
reencrypt_ecb_to_cbc_mode,
reencrypt_cbc_to_ecb_mode,
Expand Down Expand Up @@ -31,14 +31,13 @@ def reencrypt_api_keys(apps, schema_editor):
def reversion_api_keys(apps, schema_editor):
GeoConfig = apps.get_model('geospatial', 'GeoConfig')

geo_configs_to_revert = GeoConfig.objects.exclude(
api_token__startswith=f'${ALGO_AES}$'
).exclude(api_token=None)
geo_configs_to_revert = GeoConfig.objects.filter(
api_token__startswith=f'${ALGO_AES_CBC}$'
)

for config in geo_configs_to_revert:
if config.api_token.startswith(f'${ALGO_AES_CBC}$'):
config.api_token = reencrypt_cbc_to_ecb_mode(config.api_token,
f'${ALGO_AES_CBC}$')
config.api_token = reencrypt_cbc_to_ecb_mode(config.api_token,
f'${ALGO_AES_CBC}$')
config.save()


Expand Down

0 comments on commit 8779e6a

Please sign in to comment.