Merge "Remove usage of sqlalchemy mutables"
This commit is contained in:
commit
21a420a2e0
@ -1137,7 +1137,7 @@ def db_version(engine):
|
|||||||
def db_encrypt_parameters_and_properties(ctxt, encryption_key):
|
def db_encrypt_parameters_and_properties(ctxt, encryption_key):
|
||||||
from heat.engine import template
|
from heat.engine import template
|
||||||
session = get_session()
|
session = get_session()
|
||||||
session.begin()
|
with session.begin():
|
||||||
|
|
||||||
raw_templates = session.query(models.RawTemplate).all()
|
raw_templates = session.query(models.RawTemplate).all()
|
||||||
|
|
||||||
@ -1161,15 +1161,17 @@ def db_encrypt_parameters_and_properties(ctxt, encryption_key):
|
|||||||
encrypted_val
|
encrypted_val
|
||||||
encrypted_params.append(param_name)
|
encrypted_params.append(param_name)
|
||||||
|
|
||||||
raw_template.environment['encrypted_param_names'] = \
|
if encrypted_params:
|
||||||
encrypted_params
|
environment = raw_template.environment.copy()
|
||||||
|
environment['encrypted_param_names'] = encrypted_params
|
||||||
session.commit()
|
raw_template_update(ctxt, raw_template.id,
|
||||||
|
{'environment': environment})
|
||||||
|
|
||||||
|
|
||||||
def db_decrypt_parameters_and_properties(ctxt, encryption_key):
|
def db_decrypt_parameters_and_properties(ctxt, encryption_key):
|
||||||
session = get_session()
|
session = get_session()
|
||||||
session.begin()
|
|
||||||
|
with session.begin():
|
||||||
raw_templates = session.query(models.RawTemplate).all()
|
raw_templates = session.query(models.RawTemplate).all()
|
||||||
|
|
||||||
for raw_template in raw_templates:
|
for raw_template in raw_templates:
|
||||||
@ -1182,12 +1184,13 @@ def db_decrypt_parameters_and_properties(ctxt, encryption_key):
|
|||||||
decrypted_val = decrypt_function(parameters[param_name][1],
|
decrypted_val = decrypt_function(parameters[param_name][1],
|
||||||
encryption_key)
|
encryption_key)
|
||||||
try:
|
try:
|
||||||
parameters[param_name] = encodeutils.safe_decode(decrypted_val)
|
parameters[param_name] = encodeutils.safe_decode(
|
||||||
|
decrypted_val)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# if the incorrect encryption_key was used then we can
|
# if the incorrect encryption_key was used then we can get
|
||||||
# get total gibberish here and safe_decode() will freak out.
|
# total gibberish here and safe_decode() will freak out.
|
||||||
parameters[param_name] = decrypted_val
|
parameters[param_name] = decrypted_val
|
||||||
|
environment = raw_template.environment.copy()
|
||||||
raw_template.environment['encrypted_param_names'] = []
|
environment['encrypted_param_names'] = []
|
||||||
|
raw_template_update(ctxt, raw_template.id,
|
||||||
session.commit()
|
{'environment': environment})
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from sqlalchemy.dialects import mysql
|
from sqlalchemy.dialects import mysql
|
||||||
from sqlalchemy.ext import mutable
|
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
|
|
||||||
|
|
||||||
@ -42,42 +41,6 @@ class Json(LongText):
|
|||||||
return loads(value)
|
return loads(value)
|
||||||
|
|
||||||
|
|
||||||
class MutableList(mutable.Mutable, list):
|
|
||||||
@classmethod
|
|
||||||
def coerce(cls, key, value):
|
|
||||||
if not isinstance(value, cls):
|
|
||||||
if isinstance(value, list):
|
|
||||||
return cls(value)
|
|
||||||
return mutable.Mutable.coerce(key, value)
|
|
||||||
else:
|
|
||||||
return value
|
|
||||||
|
|
||||||
def __delitem__(self, key):
|
|
||||||
list.__delitem__(self, key)
|
|
||||||
self.changed()
|
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
|
||||||
list.__setitem__(self, key, value)
|
|
||||||
self.changed()
|
|
||||||
|
|
||||||
def __getstate__(self):
|
|
||||||
return list(self)
|
|
||||||
|
|
||||||
def __setstate__(self, state):
|
|
||||||
len = list.__len__(self)
|
|
||||||
list.__delslice__(self, 0, len)
|
|
||||||
list.__add__(self, state)
|
|
||||||
self.changed()
|
|
||||||
|
|
||||||
def append(self, value):
|
|
||||||
list.append(self, value)
|
|
||||||
self.changed()
|
|
||||||
|
|
||||||
def remove(self, value):
|
|
||||||
list.remove(self, value)
|
|
||||||
self.changed()
|
|
||||||
|
|
||||||
|
|
||||||
class List(types.TypeDecorator):
|
class List(types.TypeDecorator):
|
||||||
impl = types.Text
|
impl = types.Text
|
||||||
|
|
||||||
@ -94,8 +57,3 @@ class List(types.TypeDecorator):
|
|||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
return loads(value)
|
return loads(value)
|
||||||
|
|
||||||
|
|
||||||
MutableList.associate_with(List)
|
|
||||||
mutable.MutableDict.associate_with(LongText)
|
|
||||||
mutable.MutableDict.associate_with(Json)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user