Determine if the trigger_type_ref is actually a trigger ref based if the
value is a valid UUID4.
# limitations under the License.
from __future__ import absolute_import
-import six
+import six
+import uuid
from oslo_config import cfg
from apscheduler.triggers.cron import CronTrigger
@@ -144,20 +145,25 @@ def validate_trigger_payload(trigger_type_ref, payload, throw_on_inexistent_trig
# System trigger
payload_schema = SYSTEM_TRIGGER_TYPES[trigger_type_ref]['payload_schema']
else:
- # 1. First assume we received TriggerType reference
- trigger_type_db = triggers.get_trigger_type_db(trigger_type_ref)
+ # We assume Trigger ref and not TriggerType ref is passed in if second
+ # part (trigger name) is a valid UUID version 4
+ try:
+ trigger_uuid = uuid.UUID(trigger_type_ref.split('.')[-1])
+ except ValueError:
+ is_trigger_db = False
+ else:
+ is_trigger_db = (trigger_uuid.version == 4)
- if not trigger_type_db:
- # 2. If TriggerType was not found, assume we received a Trigger reference
- # Trigger doesn't exist in the database
+ if is_trigger_db:
trigger_db = triggers.get_trigger_db_by_ref(trigger_type_ref)
if trigger_db:
- trigger_type_db = triggers.get_trigger_type_db(trigger_db.type)
- else:
- trigger_type_db = None
+ trigger_type_ref = trigger_db.type
+
+ trigger_type_db = triggers.get_trigger_type_db(trigger_type_ref)
if not trigger_type_db:
+ # Trigger doesn't exist in the database
if throw_on_inexistent_trigger:
msg = ('Trigger type with reference "%s" doesn\'t exist in the database' %
(trigger_type_ref))
