-
Notifications
You must be signed in to change notification settings - Fork 52
/
create_tables_and_add_defaults.py
66 lines (54 loc) · 2.13 KB
/
create_tables_and_add_defaults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
#########
# Copyright (c) 2016 GigaSpaces Technologies Ltd. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
import sys
import json
from flask_migrate import upgrade
from manager_rest.amqp_manager import AMQPManager
from manager_rest.flask_utils import setup_flask_app
from manager_rest.storage.storage_utils import \
create_default_user_tenant_and_roles
def _init_db_tables(config):
print 'Setting up a Flask app'
app = setup_flask_app(
manager_ip=config['postgresql_host'],
hash_salt=config['hash_salt'],
secret_key=config['secret_key']
)
with app.app_context():
print 'Creating tables in the DB'
upgrade(directory=config['db_migrate_dir'])
def _add_default_user_and_tenant(config, amqp_manager):
print 'Creating bootstrap admin, default tenant and security roles'
create_default_user_tenant_and_roles(
admin_username=config['admin_username'],
admin_password=config['admin_password'],
amqp_manager=amqp_manager
)
def _get_amqp_manager(config):
return AMQPManager(
host=config['amqp_host'],
username=config['amqp_username'],
password=config['amqp_password']
)
if __name__ == '__main__':
# We're expecting to receive as an argument the path to the config file
assert len(sys.argv) == 2, 'No config file path was provided'
with open(sys.argv[1], 'r') as f:
config = json.load(f)
_init_db_tables(config)
amqp_manager = _get_amqp_manager(config)
_add_default_user_and_tenant(config, amqp_manager)
print 'Finished creating bootstrap admin and default tenant'