|
1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
3
|
|
|
# this work for additional information regarding copyright ownership. |
|
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
6
|
|
|
# the License. You may obtain a copy of the License at |
|
7
|
|
|
# |
|
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
9
|
|
|
# |
|
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13
|
|
|
# See the License for the specific language governing permissions and |
|
14
|
|
|
# limitations under the License. |
|
15
|
|
|
|
|
16
|
|
|
import mongoengine as me |
|
17
|
|
|
|
|
18
|
|
|
from st2common import log as logging |
|
19
|
|
|
from st2common.models.db import MongoDBAccess |
|
20
|
|
|
from st2common.models.db import stormbase |
|
21
|
|
|
from st2common.constants.types import ResourceType |
|
22
|
|
|
|
|
23
|
|
|
__all__ = [ |
|
24
|
|
|
'ActionAliasDB' |
|
25
|
|
|
] |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
LOG = logging.getLogger(__name__) |
|
29
|
|
|
|
|
30
|
|
|
PACK_SEPARATOR = '.' |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
class ActionAliasDB(stormbase.StormBaseDB, stormbase.ContentPackResourceMixin, |
|
34
|
|
|
stormbase.UIDFieldMixin): |
|
35
|
|
|
""" |
|
36
|
|
|
Database entity that represent an Alias for an action. |
|
37
|
|
|
|
|
38
|
|
|
Attribute: |
|
39
|
|
|
pack: Pack to which this alias belongs to. |
|
40
|
|
|
name: Alias name. |
|
41
|
|
|
ref: Alias reference (pack + name). |
|
42
|
|
|
enabled: A flag indicating whether this alias is enabled in the system. |
|
43
|
|
|
action_ref: Reference of an action this alias belongs to. |
|
44
|
|
|
formats: Alias format strings. |
|
45
|
|
|
""" |
|
46
|
|
|
|
|
47
|
|
|
RESOURCE_TYPE = ResourceType.ACTION |
|
48
|
|
|
UID_FIELDS = ['pack', 'name'] |
|
49
|
|
|
|
|
50
|
|
|
ref = me.StringField(required=True) |
|
51
|
|
|
pack = me.StringField( |
|
52
|
|
|
required=True, |
|
53
|
|
|
help_text='Name of the content pack.') |
|
54
|
|
|
enabled = me.BooleanField( |
|
55
|
|
|
required=True, default=True, |
|
56
|
|
|
help_text='A flag indicating whether the action alias is enabled.') |
|
57
|
|
|
action_ref = me.StringField( |
|
58
|
|
|
required=True, |
|
59
|
|
|
help_text='Reference of the Action map this alias.') |
|
60
|
|
|
formats = me.ListField( |
|
61
|
|
|
help_text='Possible parameter formats that an alias supports.') |
|
62
|
|
|
ack = me.DictField( |
|
63
|
|
|
help_text='Parameters pertaining to the acknowledgement message.' |
|
64
|
|
|
) |
|
65
|
|
|
result = me.DictField( |
|
66
|
|
|
help_text='Parameters pertaining to the execution result message.' |
|
67
|
|
|
) |
|
68
|
|
|
extra = me.DictField( |
|
69
|
|
|
help_text='Additional parameters (usually adapter-specific) not covered in the schema.' |
|
70
|
|
|
) |
|
71
|
|
|
|
|
72
|
|
|
meta = { |
|
73
|
|
|
'indexes': ['name'] |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
def __init__(self, *args, **values): |
|
77
|
|
|
super(ActionAliasDB, self).__init__(*args, **values) |
|
78
|
|
|
self.ref = self.get_reference().ref |
|
79
|
|
|
self.uid = self.get_uid() |
|
80
|
|
|
|
|
81
|
|
|
def get_format_strings(self): |
|
82
|
|
|
""" |
|
83
|
|
|
Return a list of all the supported format strings. |
|
84
|
|
|
|
|
85
|
|
|
:rtype: ``list`` of ``str`` |
|
86
|
|
|
""" |
|
87
|
|
|
result = [] |
|
88
|
|
|
|
|
89
|
|
|
formats = getattr(self, 'formats', []) |
|
90
|
|
|
for format_string in formats: |
|
91
|
|
|
if isinstance(format_string, dict) and format_string.get('representation', None): |
|
92
|
|
|
result.extend(format_string['representation']) |
|
93
|
|
|
else: |
|
94
|
|
|
result.append(format_string) |
|
95
|
|
|
|
|
96
|
|
|
return result |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
# specialized access objects |
|
100
|
|
|
actionalias_access = MongoDBAccess(ActionAliasDB) |
|
101
|
|
|
|
|
102
|
|
|
MODELS = [ActionAliasDB] |
|
103
|
|
|
|