|
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 abort |
|
17
|
|
|
import six |
|
18
|
|
|
|
|
19
|
|
|
from st2common import log as logging |
|
20
|
|
|
from st2common.constants.keyvalue import ALLOWED_SCOPES |
|
21
|
|
|
from st2common.models.api.base import jsexpose |
|
22
|
|
|
|
|
23
|
|
|
http_client = six.moves.http_client |
|
24
|
|
|
|
|
25
|
|
|
LOG = logging.getLogger(__name__) |
|
26
|
|
|
|
|
27
|
|
|
__all__ = [ |
|
28
|
|
|
'ScopedKeyValuePairController' |
|
29
|
|
|
] |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class ScopedKeyValuePairController(object): |
|
33
|
|
|
""" |
|
34
|
|
|
Implements the REST endpoint for managing the scoped key value store. |
|
35
|
|
|
""" |
|
36
|
|
|
|
|
37
|
|
|
@jsexpose |
|
38
|
|
|
def _lookup(self, *remainder): |
|
39
|
|
|
LOG.info('Hitting lookup method!!!') |
|
40
|
|
|
scope = remainder[0] |
|
41
|
|
|
if not self._is_allowed_scope(scope): |
|
42
|
|
|
msg = 'Scope %s is not in allowed scopes list: %s.' % (scope, ALLOWED_SCOPES) |
|
43
|
|
|
abort(http_client.BAD_REQUEST, msg) |
|
44
|
|
|
return |
|
45
|
|
|
LOG.info('Got a valid scope. Now should route to key value controller.') |
|
46
|
|
|
return {'dummy': 'silly'} |
|
47
|
|
|
|
|
48
|
|
|
@staticmethod |
|
49
|
|
|
def _is_allowed_scope(scope): |
|
50
|
|
|
return scope in ALLOWED_SCOPES |
|
51
|
|
|
|