Skip to content

Commit bf421a3

Browse files
committed
Don't break the DB abstraction and use persistance class to query for
the model in question. Also only retrieve fields we need for the masking operation.
1 parent dcfe02f commit bf421a3

File tree

1 file changed

+18
-12
lines changed
  • st2common/st2common/models/db

1 file changed

+18
-12
lines changed

st2common/st2common/models/db/rule.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,42 @@ def mask_secrets(self, value):
116116
:rtype: ``dict``
117117
"""
118118
result = copy.deepcopy(value)
119-
if('action' not in result):
119+
120+
action_ref = result.get('action', {}).get('ref', None)
121+
122+
if not action_ref:
120123
return result
121-
action_db = self._get_referenced_models(rule=result)
122124

123-
secret_parameters = get_secret_parameters(parameters=action_db['parameters'])
125+
action_db = self._get_referenced_action_model(action_ref=action_ref)
126+
127+
if not action_db:
128+
return result
129+
130+
secret_parameters = get_secret_parameters(parameters=action_db.parameters)
124131
result['action']['parameters'] = mask_secret_parameters(
125132
parameters=result['action']['parameters'],
126133
secret_parameters=secret_parameters)
127134

128135
return result
129136

130-
def _get_referenced_models(self, rule):
137+
def _get_referenced_action_model(self, action_ref):
131138
"""
139+
Return Action object for the action referenced in a rule.
132140
Return the action model referenced from rule.
133141
134142
:type rule: ``dict``
135143
:param rule: rule
136144
137145
:rtype: ``ActionDB``
138146
"""
139-
action_ref = rule['action']['ref']
140-
141-
def ref_query_args(ref):
142-
return {'ref': ref}
147+
# NOTE: We need to retrieve pack and name since that's needed for the PK
148+
action_dbs = Action.query(only_fields=['pack', 'ref', 'name', 'parameters'],
149+
ref=action_ref, limit=1)
143150

144-
action_db = self._get_entity(model_persistence=Action,
145-
ref=action_ref,
146-
query_args=ref_query_args)
151+
if action_dbs:
152+
return action_dbs[0]
147153

148-
return action_db
154+
return None
149155

150156
def _get_entity(self, model_persistence, ref, query_args):
151157
q = Q(**query_args(ref))

0 commit comments

Comments
 (0)