|
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
|
|
|
""" |
|
17
|
|
|
A script which applies RBAC definitions and role assignments stored on disk. |
|
18
|
|
|
""" |
|
19
|
|
|
|
|
20
|
|
|
from oslo_config import cfg |
|
21
|
|
|
|
|
22
|
|
|
from st2common import config |
|
23
|
|
|
from st2common.script_setup import setup as common_setup |
|
24
|
|
|
from st2common.script_setup import teardown as common_teardown |
|
25
|
|
|
from st2common.rbac.loader import RBACDefinitionsLoader |
|
26
|
|
|
from st2common.rbac.syncer import RBACDefinitionsDBSyncer |
|
27
|
|
|
|
|
28
|
|
|
__all__ = [ |
|
29
|
|
|
'main' |
|
30
|
|
|
] |
|
31
|
|
|
|
|
32
|
|
|
cfg.CONF.register_cli_opt(cfg.BoolOpt('verbose', short='v', default=False)) |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
def setup(argv): |
|
36
|
|
|
common_setup(config=config, setup_db=True, register_mq_exchanges=True) |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
def teartown(): |
|
40
|
|
|
common_teardown() |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
def apply_definitions(): |
|
44
|
|
|
loader = RBACDefinitionsLoader() |
|
45
|
|
|
result = loader.load() |
|
46
|
|
|
|
|
47
|
|
|
role_definition_apis = result['roles'].values() |
|
48
|
|
|
role_assignment_apis = result['role_assignments'].values() |
|
49
|
|
|
|
|
50
|
|
|
syncer = RBACDefinitionsDBSyncer() |
|
51
|
|
|
result = syncer.sync(role_definition_apis=role_definition_apis, |
|
52
|
|
|
role_assignment_apis=role_assignment_apis) |
|
53
|
|
|
|
|
54
|
|
|
return result |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
def main(argv): |
|
58
|
|
|
setup(argv) |
|
59
|
|
|
apply_definitions() |
|
60
|
|
|
teartown() |
|
61
|
|
|
|