|
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
|
|
|
from st2common.util import schema as util_schema |
|
17
|
|
|
from st2common.models.api.base import BaseAPI |
|
18
|
|
|
from st2common.models.db.pack import PackDB |
|
19
|
|
|
from st2common.models.db.pack import ConfigSchemaDB |
|
20
|
|
|
|
|
21
|
|
|
__all__ = [ |
|
22
|
|
|
'PackAPI', |
|
23
|
|
|
'ConfigSchemaAPI' |
|
24
|
|
|
] |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
class PackAPI(BaseAPI): |
|
28
|
|
|
model = PackDB |
|
29
|
|
|
schema = { |
|
30
|
|
|
'type': 'object', |
|
31
|
|
|
'properties': { |
|
32
|
|
|
'id': { |
|
33
|
|
|
'type': 'string', |
|
34
|
|
|
'default': None |
|
35
|
|
|
}, |
|
36
|
|
|
'ref': { |
|
37
|
|
|
'type': 'string', |
|
38
|
|
|
'default': None |
|
39
|
|
|
}, |
|
40
|
|
|
"uid": { |
|
41
|
|
|
"type": "string" |
|
42
|
|
|
}, |
|
43
|
|
|
'name': { |
|
44
|
|
|
'type': 'string', |
|
45
|
|
|
'required': True |
|
46
|
|
|
}, |
|
47
|
|
|
'description': { |
|
48
|
|
|
'type': 'string' |
|
49
|
|
|
}, |
|
50
|
|
|
'keywords': { |
|
51
|
|
|
'type': 'array', |
|
52
|
|
|
'items': {'type': 'string'}, |
|
53
|
|
|
'default': [] |
|
54
|
|
|
}, |
|
55
|
|
|
'version': { |
|
56
|
|
|
'type': 'string' |
|
57
|
|
|
}, |
|
58
|
|
|
'author': { |
|
59
|
|
|
'type': 'string' |
|
60
|
|
|
}, |
|
61
|
|
|
'email': { |
|
62
|
|
|
'type': 'string' |
|
63
|
|
|
}, |
|
64
|
|
|
'files': { |
|
65
|
|
|
'type': 'array', |
|
66
|
|
|
'items': {'type': 'string'}, |
|
67
|
|
|
'default': [] |
|
68
|
|
|
} |
|
69
|
|
|
}, |
|
70
|
|
|
'additionalProperties': False |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
@classmethod |
|
74
|
|
|
def to_model(cls, pack): |
|
75
|
|
|
name = pack.name |
|
76
|
|
|
description = pack.description |
|
77
|
|
|
ref = pack.ref |
|
78
|
|
|
keywords = getattr(pack, 'keywords', []) |
|
79
|
|
|
version = str(pack.version) |
|
80
|
|
|
author = pack.author |
|
81
|
|
|
email = pack.email |
|
82
|
|
|
files = getattr(pack, 'files', []) |
|
83
|
|
|
|
|
84
|
|
|
model = cls.model(name=name, description=description, ref=ref, keywords=keywords, |
|
85
|
|
|
version=version, author=author, email=email, files=files) |
|
86
|
|
|
|
|
87
|
|
|
return model |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
class ConfigSchemaAPI(BaseAPI): |
|
91
|
|
|
model = ConfigSchemaDB |
|
92
|
|
|
schema = { |
|
93
|
|
|
"title": "ConfigSchema", |
|
94
|
|
|
"description": "Pack config schema.", |
|
95
|
|
|
"type": "object", |
|
96
|
|
|
"properties": { |
|
97
|
|
|
"id": { |
|
98
|
|
|
"description": "The unique identifier for the config schema.", |
|
99
|
|
|
"type": "string" |
|
100
|
|
|
}, |
|
101
|
|
|
"pack": { |
|
102
|
|
|
"description": "The content pack this config schema belongs to.", |
|
103
|
|
|
"type": "string" |
|
104
|
|
|
}, |
|
105
|
|
|
"attributes": { |
|
106
|
|
|
"description": "Config schema attributes.", |
|
107
|
|
|
"type": "object", |
|
108
|
|
|
"patternProperties": { |
|
109
|
|
|
"^\w+$": util_schema.get_action_parameters_schema() |
|
|
|
|
|
|
110
|
|
|
}, |
|
111
|
|
|
"default": {} |
|
112
|
|
|
} |
|
113
|
|
|
}, |
|
114
|
|
|
"additionalProperties": False |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
@classmethod |
|
118
|
|
|
def to_model(cls, config_schema): |
|
119
|
|
|
pack = config_schema.pack |
|
120
|
|
|
attributes = config_schema.attributes |
|
121
|
|
|
|
|
122
|
|
|
model = cls.model(pack=pack, attributes=attributes) |
|
123
|
|
|
|
|
124
|
|
|
return model |
|
125
|
|
|
|
Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with
rorRare they interpreted as regular expressions.The escape sequence that was used indicates that you might have intended to write a regular expression.
Learn more about the available escape sequences. in the Python documentation.