Passed
Pull Request — master (#3462)
by Lakshmi
05:23
created

generate_spec()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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 pkg_resources
17
18
import jinja2
19
import yaml
20
21
import st2common.constants.pack
22
import st2common.constants.action
23
from st2common.rbac.types import PermissionType
24
from st2common.util import isotime
25
26
__all__ = [
27
    'load_spec',
28
    'generate_spec'
29
]
30
31
ARGUMENTS = {
32
    'DEFAULT_PACK_NAME': st2common.constants.pack.DEFAULT_PACK_NAME,
33
    'LIVEACTION_STATUSES': st2common.constants.action.LIVEACTION_STATUSES,
34
    'PERMISSION_TYPE': PermissionType,
35
    'ISO8601_UTC_REGEX': isotime.ISO8601_UTC_REGEX
36
}
37
38
39
def load_spec(module_name, spec_file):
40
    spec_string = generate_spec(module_name, spec_file)
41
    spec = yaml.load(spec_string)
42
43
    return spec
44
45
46
def generate_spec(module_name, spec_file):
47
    spec_template = pkg_resources.resource_string(module_name, spec_file)
48
    spec_string = jinja2.Template(spec_template).render(**ARGUMENTS)
49
50
    return spec_string
51