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 pecan import expose |
17
|
|
|
|
18
|
|
|
from st2common import __version__ |
19
|
|
|
from st2common import log as logging |
20
|
|
|
import st2api.controllers.v1.root as v1_root |
21
|
|
|
import st2api.controllers.exp.root as exp_root |
22
|
|
|
|
23
|
|
|
__all__ = [ |
24
|
|
|
'RootController' |
25
|
|
|
] |
26
|
|
|
|
27
|
|
|
LOG = logging.getLogger(__name__) |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class RootController(object): |
31
|
|
|
|
32
|
|
|
def __init__(self): |
33
|
|
|
v1_controller = v1_root.RootController() |
34
|
|
|
exp_controller = exp_root.RootController() |
35
|
|
|
self.controllers = { |
36
|
|
|
'v1': v1_controller, |
37
|
|
|
'exp': exp_controller |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
self.default_controller = v1_controller |
41
|
|
|
|
42
|
|
|
@expose(generic=True, template='index.html') |
43
|
|
|
def index(self): |
44
|
|
|
data = {} |
45
|
|
|
|
46
|
|
|
if 'dev' in __version__: |
47
|
|
|
docs_url = 'http://docs.stackstorm.com/latest' |
48
|
|
|
else: |
49
|
|
|
docs_version = '.'.join(__version__.split('.')[:2]) |
50
|
|
|
docs_url = 'http://docs.stackstorm.com/%s' % docs_version |
51
|
|
|
|
52
|
|
|
data['version'] = __version__ |
53
|
|
|
data['docs_url'] = docs_url |
54
|
|
|
return data |
55
|
|
|
|
56
|
|
|
@expose() |
57
|
|
|
def _lookup(self, *remainder): |
58
|
|
|
version = '' |
59
|
|
|
if len(remainder) > 0: |
60
|
|
|
version = remainder[0] |
61
|
|
|
|
62
|
|
|
if remainder[len(remainder) - 1] == '': |
63
|
|
|
# If the url has a trailing '/' remainder will contain an empty string. |
64
|
|
|
# In order for further pecan routing to work this method needs to remove |
65
|
|
|
# the empty string from end of the tuple. |
66
|
|
|
remainder = remainder[:len(remainder) - 1] |
67
|
|
|
versioned_controller = self.controllers.get(version, None) |
68
|
|
|
if versioned_controller: |
69
|
|
|
return versioned_controller, remainder[1:] |
70
|
|
|
LOG.debug('No version specified in URL. Will use default controller.') |
71
|
|
|
return self.default_controller, remainder |
72
|
|
|
|