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 orquesta 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 | except KeyError: |
||
39 | raise KeyError('Could not get user from context.') |
||
40 | |||
41 | try: |
||
42 | user_db = auth_db_access.User.get(username) |
||
43 | except Exception as e: |
||
44 | raise Exception('Failed to retrieve User object for user "%s" % (username)' % (str(e))) |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
45 | |||
46 | kvp = kvp_util.get_key(key=key, user_db=user_db, decrypt=decrypt) |
||
47 | |||
48 | if not kvp: |
||
49 | raise exc.ExpressionEvaluationException( |
||
50 | 'Key %s does not exist in StackStorm datastore.' % key |
||
51 | ) |
||
52 | |||
53 | return kvp |
||
54 |