Passed
Push — develop ( 8c7641...71cfc9 )
by Plexxi
07:22 queued 03:39
created

PackConfigSchemaController.get_all()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
dl 0
loc 4
rs 10
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.services import packs as packs_service
17
from st2common.models.api.base import jsexpose
18
from st2api.controllers.resource import ResourceController
19
from st2common.models.api.pack import ConfigSchemaAPI
20
from st2common.persistence.pack import ConfigSchema
21
from st2common.rbac.types import PermissionType
22
from st2common.rbac.decorators import request_user_has_permission
23
from st2common.rbac.decorators import request_user_has_resource_db_permission
24
25
26
__all__ = [
27
    'PackConfigSchemaController'
28
]
29
30
31
class PackConfigSchemaController(ResourceController):
32
    model = ConfigSchemaAPI
33
    access = ConfigSchema
34
    supported_filters = {}
35
36
    def __init__(self):
37
        super(PackConfigSchemaController, self).__init__()
38
39
        # Note: This method is used to retrieve object for RBAC purposes and in
40
        # this case, RBAC is checked on the parent PackDB object
41
        self.get_one_db_method = packs_service.get_pack_by_ref
42
43
    @request_user_has_permission(permission_type=PermissionType.PACK_LIST)
44
    @jsexpose()
45
    def get_all(self, **kwargs):
46
        return super(PackConfigSchemaController, self)._get_all(**kwargs)
47
48
    @request_user_has_resource_db_permission(permission_type=PermissionType.PACK_VIEW)
49
    @jsexpose(arg_types=[str])
50
    def get_one(self, pack_ref):
51
        """
52
            Retrieve config schema for a particular pack.
53
54
            Handles requests:
55
                GET /packs/config_schema/<pack_ref>
56
        """
57
        return self._get_one_by_pack_ref(pack_ref=pack_ref)
58