1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
3
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
4
|
|
|
# this work for additional information regarding copyright ownership. |
5
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
6
|
|
|
# (the "License"); you may not use this file except in compliance with |
7
|
|
|
# the License. You may obtain a copy of the License at |
8
|
|
|
# |
9
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
# |
11
|
|
|
# Unless required by applicable law or agreed to in writing, software |
12
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
# See the License for the specific language governing permissions and |
15
|
|
|
# limitations under the License. |
16
|
|
|
|
17
|
|
|
import logging |
18
|
|
|
import six |
19
|
|
|
|
20
|
|
|
from orchestra import exceptions as exc |
21
|
|
|
|
22
|
|
|
from st2common.persistence import auth as auth_db_access |
23
|
|
|
from st2common.util import keyvalue as kvp_util |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
LOG = logging.getLogger(__name__) |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
def st2kv_(context, key, decrypt=False): |
30
|
|
|
if not isinstance(key, six.string_types): |
31
|
|
|
raise TypeError('Given key is not typeof string.') |
32
|
|
|
|
33
|
|
|
if not isinstance(decrypt, bool): |
34
|
|
|
raise TypeError('Decrypt parameter is not typeof bool.') |
35
|
|
|
|
36
|
|
|
try: |
37
|
|
|
username = context['__vars']['st2']['user'] |
38
|
|
|
user = auth_db_access.User.get(username) |
39
|
|
|
except KeyError: |
40
|
|
|
raise KeyError('Could not get user from context.') |
41
|
|
|
|
42
|
|
|
LOG.debug('ST2KV Decrypt: %s', decrypt) |
43
|
|
|
|
44
|
|
|
kvp = kvp_util.get_key(key=key, user=user, decrypt=decrypt) |
45
|
|
|
|
46
|
|
|
if not kvp: |
47
|
|
|
raise exc.ExpressionEvaluationException( |
48
|
|
|
'Key %s does not exist in StackStorm datastore.' % key |
49
|
|
|
) |
50
|
|
|
|
51
|
|
|
return kvp |
52
|
|
|
|