Show More
@@ -1,81 +1,81 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2018 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | import sys |
|
23 | 23 | import logging |
|
24 | 24 | |
|
25 | 25 | import click |
|
26 | 26 | |
|
27 | 27 | from pyramid.paster import setup_logging |
|
28 | 28 | |
|
29 | 29 | from rhodecode.lib.pyramid_utils import bootstrap |
|
30 | 30 | from .backends import SshWrapper |
|
31 | 31 | |
|
32 | 32 | log = logging.getLogger(__name__) |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | def setup_custom_logging(ini_path, debug): |
|
36 | 36 | if debug: |
|
37 | 37 | # enabled rhodecode.ini controlled logging setup |
|
38 | 38 | setup_logging(ini_path) |
|
39 | 39 | else: |
|
40 | 40 | # configure logging in a mode that doesn't print anything. |
|
41 | 41 | # in case of regularly configured logging it gets printed out back |
|
42 | 42 | # to the client doing an SSH command. |
|
43 | 43 | logger = logging.getLogger('') |
|
44 | 44 | null = logging.NullHandler() |
|
45 | 45 | # add the handler to the root logger |
|
46 | 46 | logger.handlers = [null] |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | @click.command() |
|
50 | 50 | @click.argument('ini_path', type=click.Path(exists=True)) |
|
51 | 51 | @click.option( |
|
52 | 52 | '--mode', '-m', required=False, default='auto', |
|
53 | 53 | type=click.Choice(['auto', 'vcs', 'git', 'hg', 'svn', 'test']), |
|
54 | 54 | help='mode of operation') |
|
55 | 55 | @click.option('--user', help='Username for which the command will be executed') |
|
56 | 56 | @click.option('--user-id', help='User ID for which the command will be executed') |
|
57 | 57 | @click.option('--key-id', help='ID of the key from the database') |
|
58 | 58 | @click.option('--shell', '-s', is_flag=True, help='Allow Shell') |
|
59 | 59 | @click.option('--debug', is_flag=True, help='Enabled detailed output logging') |
|
60 | 60 | def main(ini_path, mode, user, user_id, key_id, shell, debug): |
|
61 | 61 | setup_custom_logging(ini_path, debug) |
|
62 | 62 | |
|
63 | 63 | command = os.environ.get('SSH_ORIGINAL_COMMAND', '') |
|
64 | 64 | if not command and mode not in ['test']: |
|
65 | 65 | raise ValueError( |
|
66 | 66 | 'Unable to fetch SSH_ORIGINAL_COMMAND from environment.' |
|
67 | 67 | 'Please make sure this is set and available during execution ' |
|
68 | 68 | 'of this script.') |
|
69 | 69 | connection_info = os.environ.get('SSH_CONNECTION', '') |
|
70 | 70 | |
|
71 | with bootstrap(ini_path) as env: | |
|
71 | with bootstrap(ini_path, env={'RC_CMD_SSH_WRAPPER': '1'}) as env: | |
|
72 | 72 | try: |
|
73 | 73 | ssh_wrapper = SshWrapper( |
|
74 | 74 | command, connection_info, mode, |
|
75 | 75 | user, user_id, key_id, shell, ini_path, env) |
|
76 | 76 | except Exception: |
|
77 | 77 | log.exception('Failed to execute SshWrapper') |
|
78 | 78 | sys.exit(-5) |
|
79 | 79 | |
|
80 | 80 | return_code = ssh_wrapper.wrap() |
|
81 | 81 | sys.exit(return_code) |
@@ -1,56 +1,58 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2018 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | from pyramid.compat import configparser |
|
23 | 23 | from pyramid.paster import bootstrap as pyramid_bootstrap, setup_logging # noqa |
|
24 | 24 | from pyramid.request import Request |
|
25 | 25 | from pyramid.scripting import prepare |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | def get_config(ini_path, **kwargs): |
|
29 | 29 | parser = configparser.ConfigParser(**kwargs) |
|
30 | 30 | parser.read(ini_path) |
|
31 | 31 | return parser |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | def get_app_config(ini_path): |
|
35 | 35 | from paste.deploy.loadwsgi import appconfig |
|
36 | 36 | return appconfig('config:{}'.format(ini_path), relative_to=os.getcwd()) |
|
37 | 37 | |
|
38 | 38 | |
|
39 | def bootstrap(config_uri, request=None, options=None): | |
|
39 | def bootstrap(config_uri, request=None, options=None, env=None): | |
|
40 | if env: | |
|
41 | os.environ.update(env) | |
|
40 | 42 | |
|
41 | 43 | config = get_config(config_uri) |
|
42 | 44 | base_url = 'http://rhodecode.local' |
|
43 | 45 | try: |
|
44 | 46 | base_url = config.get('app:main', 'app.base_url') |
|
45 | 47 | except (configparser.NoSectionError, configparser.NoOptionError): |
|
46 | 48 | pass |
|
47 | 49 | |
|
48 | 50 | request = request or Request.blank('/', base_url=base_url) |
|
49 | 51 | |
|
50 | 52 | return pyramid_bootstrap(config_uri, request=request, options=options) |
|
51 | 53 | |
|
52 | 54 | |
|
53 | 55 | def prepare_request(environ): |
|
54 | 56 | request = Request.blank('/', environ=environ) |
|
55 | 57 | prepare(request) # set pyramid threadlocal request |
|
56 | 58 | return request |
@@ -1,103 +1,103 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2018 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | import logging |
|
21 | 21 | |
|
22 | 22 | import click |
|
23 | 23 | import pyramid.paster |
|
24 | 24 | |
|
25 | 25 | from rhodecode.lib.pyramid_utils import bootstrap, get_app_config |
|
26 | 26 | from rhodecode.lib.db_manage import DbManage |
|
27 | 27 | from rhodecode.model.db import Session |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | log = logging.getLogger(__name__) |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | @click.command() |
|
34 | 34 | @click.argument('ini_path', type=click.Path(exists=True)) |
|
35 | 35 | @click.option( |
|
36 | 36 | '--force-yes/--force-no', default=None, |
|
37 | 37 | help="Force yes/no to every question") |
|
38 | 38 | @click.option( |
|
39 | 39 | '--user', |
|
40 | 40 | default=None, |
|
41 | 41 | help='Initial super-admin username') |
|
42 | 42 | @click.option( |
|
43 | 43 | '--email', |
|
44 | 44 | default=None, |
|
45 | 45 | help='Initial super-admin email address.') |
|
46 | 46 | @click.option( |
|
47 | 47 | '--password', |
|
48 | 48 | default=None, |
|
49 | 49 | help='Initial super-admin password. Minimum 6 chars.') |
|
50 | 50 | @click.option( |
|
51 | 51 | '--api-key', |
|
52 | 52 | help='Initial API key for the admin user') |
|
53 | 53 | @click.option( |
|
54 | 54 | '--repos', |
|
55 | 55 | default=None, |
|
56 | 56 | help='Absolute path to storage location. This is storage for all ' |
|
57 | 57 | 'existing and future repositories, and repository groups.') |
|
58 | 58 | @click.option( |
|
59 | 59 | '--public-access/--no-public-access', |
|
60 | 60 | default=None, |
|
61 | 61 | help='Enable public access on this installation. ' |
|
62 | 62 | 'Default is public access enabled.') |
|
63 | 63 | def main(ini_path, force_yes, user, email, password, api_key, repos, |
|
64 | 64 | public_access): |
|
65 | 65 | return command(ini_path, force_yes, user, email, password, api_key, |
|
66 | 66 | repos, public_access) |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | def command(ini_path, force_yes, user, email, password, api_key, repos, |
|
70 | 70 | public_access): |
|
71 | 71 | # mapping of old parameters to new CLI from click |
|
72 | 72 | options = dict( |
|
73 | 73 | username=user, |
|
74 | 74 | email=email, |
|
75 | 75 | password=password, |
|
76 | 76 | api_key=api_key, |
|
77 | 77 | repos_location=repos, |
|
78 | 78 | force_ask=force_yes, |
|
79 | 79 | public_access=public_access |
|
80 | 80 | ) |
|
81 | 81 | pyramid.paster.setup_logging(ini_path) |
|
82 | 82 | |
|
83 | 83 | config = get_app_config(ini_path) |
|
84 | 84 | |
|
85 | 85 | db_uri = config['sqlalchemy.db1.url'] |
|
86 | 86 | dbmanage = DbManage(log_sql=True, dbconf=db_uri, root='.', |
|
87 | 87 | tests=False, cli_args=options) |
|
88 | 88 | dbmanage.create_tables(override=True) |
|
89 | 89 | dbmanage.set_db_version() |
|
90 | 90 | opts = dbmanage.config_prompt(None) |
|
91 | 91 | dbmanage.create_settings(opts) |
|
92 | 92 | dbmanage.create_default_user() |
|
93 | 93 | dbmanage.create_admin_and_prompt() |
|
94 | 94 | dbmanage.create_permissions() |
|
95 | 95 | dbmanage.populate_default_permissions() |
|
96 | 96 | Session().commit() |
|
97 | 97 | |
|
98 | with bootstrap(ini_path) as env: | |
|
98 | with bootstrap(ini_path, env={'RC_CMD_SETUP_RC': '1'}) as env: | |
|
99 | 99 | msg = 'Successfully initialized database, schema and default data.' |
|
100 | 100 | print() |
|
101 | 101 | print('*' * len(msg)) |
|
102 | 102 | print(msg.upper()) |
|
103 | 103 | print('*' * len(msg)) |
@@ -1,52 +1,52 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2018 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 | 22 | |
|
23 | 23 | import click |
|
24 | 24 | import pyramid.paster |
|
25 | 25 | |
|
26 | 26 | from rhodecode.lib.pyramid_utils import bootstrap |
|
27 | 27 | from rhodecode.lib.db_manage import DbManage |
|
28 | 28 | |
|
29 | 29 | log = logging.getLogger(__name__) |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | @click.command() |
|
33 | 33 | @click.argument('ini_path', type=click.Path(exists=True)) |
|
34 | 34 | @click.option('--force-yes/--force-no', default=None, |
|
35 | 35 | help="Force yes/no to every question") |
|
36 | 36 | def main(ini_path, force_yes): |
|
37 | 37 | return command(ini_path, force_yes) |
|
38 | 38 | |
|
39 | 39 | |
|
40 | 40 | def command(ini_path, force_yes): |
|
41 | 41 | pyramid.paster.setup_logging(ini_path) |
|
42 | 42 | |
|
43 | with bootstrap(ini_path) as env: | |
|
43 | with bootstrap(ini_path, env={'RC_CMD_UPGRADE_DB': '1'}) as env: | |
|
44 | 44 | config = env['registry'].settings |
|
45 | 45 | db_uri = config['sqlalchemy.db1.url'] |
|
46 | 46 | options = {} |
|
47 | 47 | if force_yes is not None: |
|
48 | 48 | options['force_ask'] = force_yes |
|
49 | 49 | dbmanage = DbManage( |
|
50 | 50 | log_sql=True, dbconf=db_uri, root='.', tests=False, |
|
51 | 51 | cli_args=options) |
|
52 | 52 | dbmanage.upgrade() |
General Comments 0
You need to be logged in to leave comments.
Login now