##// END OF EJS Templates
fix(jupyter): Catching validation error in order to avoid app crash ic case of formatting issues. Fixes: RCCE-26
fix(jupyter): Catching validation error in order to avoid app crash ic case of formatting issues. Fixes: RCCE-26

File last commit:

r5096:a0018795 default
r5259:930eac40 default
Show More
setup_rc.py
123 lines | 4.1 KiB | text/x-python | PythonLexer
copyrights: updated for 2023
r5088 # Copyright (C) 2016-2023 RhodeCode GmbH
core: added two new commands rcsetup-app and rcupgrade-db that will...
r2007 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
core: ported setup-app to pyramid command....
r2341 import logging
core: added two new commands rcsetup-app and rcupgrade-db that will...
r2007
import click
core: ported setup-app to pyramid command....
r2341 import pyramid.paster
core: added two new commands rcsetup-app and rcupgrade-db that will...
r2007
core: ported setup-app to pyramid command....
r2341 from rhodecode.lib.pyramid_utils import bootstrap, get_app_config
from rhodecode.lib.db_manage import DbManage
rc-commands: python3 port
r5078 from rhodecode.lib.utils2 import get_encryption_key
core: ported setup-app to pyramid command....
r2341 from rhodecode.model.db import Session
log = logging.getLogger(__name__)
core: added two new commands rcsetup-app and rcupgrade-db that will...
r2007
@click.command()
@click.argument('ini_path', type=click.Path(exists=True))
core: ported setup-app to pyramid command....
r2341 @click.option(
'--force-yes/--force-no', default=None,
help="Force yes/no to every question")
@click.option(
'--user',
default=None,
help='Initial super-admin username')
@click.option(
'--email',
default=None,
help='Initial super-admin email address.')
@click.option(
'--password',
default=None,
help='Initial super-admin password. Minimum 6 chars.')
@click.option(
'--api-key',
help='Initial API key for the admin user')
@click.option(
'--repos',
default=None,
help='Absolute path to storage location. This is storage for all '
'existing and future repositories, and repository groups.')
@click.option(
'--public-access/--no-public-access',
default=None,
help='Enable public access on this installation. '
'Default is public access enabled.')
setup: added optional parameters to apply a default license, or skip re-creation of database at install.
r4618 @click.option(
'--skip-existing-db',
default=False,
is_flag=True,
help='Do not destroy and re-initialize the database if it already exist.')
@click.option(
'--apply-license-key',
default=False,
is_flag=True,
help='Get the license key from a license file or ENV and apply during DB creation.')
core: ported setup-app to pyramid command....
r2341 def main(ini_path, force_yes, user, email, password, api_key, repos,
setup: added optional parameters to apply a default license, or skip re-creation of database at install.
r4618 public_access, skip_existing_db, apply_license_key):
core: ported setup-app to pyramid command....
r2341 return command(ini_path, force_yes, user, email, password, api_key,
setup: added optional parameters to apply a default license, or skip re-creation of database at install.
r4618 repos, public_access, skip_existing_db, apply_license_key)
core: ported setup-app to pyramid command....
r2341
def command(ini_path, force_yes, user, email, password, api_key, repos,
setup: added optional parameters to apply a default license, or skip re-creation of database at install.
r4618 public_access, skip_existing_db, apply_license_key):
core: ported setup-app to pyramid command....
r2341 # mapping of old parameters to new CLI from click
options = dict(
username=user,
email=email,
password=password,
api_key=api_key,
repos_location=repos,
force_ask=force_yes,
public_access=public_access
)
core: added two new commands rcsetup-app and rcupgrade-db that will...
r2007 pyramid.paster.setup_logging(ini_path)
core: ported setup-app to pyramid command....
r2341 config = get_app_config(ini_path)
db_uri = config['sqlalchemy.db1.url']
rc-commands: python3 port
r5078 enc_key = get_encryption_key(config)
core: ported setup-app to pyramid command....
r2341 dbmanage = DbManage(log_sql=True, dbconf=db_uri, root='.',
rc-commands: python3 port
r5078 tests=False, cli_args=options, enc_key=enc_key)
setup: added optional parameters to apply a default license, or skip re-creation of database at install.
r4618 if skip_existing_db and dbmanage.db_exists():
return
core: ported setup-app to pyramid command....
r2341 dbmanage.create_tables(override=True)
dbmanage.set_db_version()
opts = dbmanage.config_prompt(None)
dbmanage.create_settings(opts)
dbmanage.create_default_user()
dbmanage.create_admin_and_prompt()
dbmanage.create_permissions()
dbmanage.populate_default_permissions()
setup: added optional parameters to apply a default license, or skip re-creation of database at install.
r4618 if apply_license_key:
try:
from rc_license.models import apply_trial_license_if_missing
apply_trial_license_if_missing(force=True)
except ImportError:
pass
core: ported setup-app to pyramid command....
r2341 Session().commit()
bootstrap: allow setting certain env flags for usage in CLI scripts....
r2651 with bootstrap(ini_path, env={'RC_CMD_SETUP_RC': '1'}) as env:
core: ported setup-app to pyramid command....
r2341 msg = 'Successfully initialized database, schema and default data.'
print()
print('*' * len(msg))
print(msg.upper())
print('*' * len(msg))