Exemplo n.º 1
0
 def _prepare(self, args):
     os.chdir(args.path)
     base_dir = os.path.join(self.original_dir, args.path)
     config = json.loads(open(os.path.join(base_dir, './config/repo/web-admin.conf')).read())
     config['config_dir'] = os.path.abspath(args.path)
     update_globals(config, base_dir)
     os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
Exemplo n.º 2
0
def main():
    store_pidfile(os.path.abspath('.'))
    repo_dir = os.path.join('.', 'config', 'repo')

    # Update Django settings
    config = json.loads(open(os.path.join(repo_dir, 'web-admin.conf')).read())
    config['config_dir'] = os.path.abspath('.')
    update_globals(config)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
    django.setup()
    call_command('loaddata', os.path.join(repo_dir, 'initial-data.json'))

    RepoManager(repo_dir).ensure_repo_consistency()
    execute_from_command_line(['zato-web-admin', 'runserver', '--noreload', '--nothreading', '{host}:{port}'.format(**config)])
Exemplo n.º 3
0
def main():
    store_pidfile(os.path.abspath('.'))
    repo_dir = os.path.join('.', 'config', 'repo')

    # Update Django settings
    config = json.loads(open(os.path.join(repo_dir, 'web-admin.conf')).read())
    config['config_dir'] = os.path.abspath('.')
    update_globals(config)

    # Store the PID so that the server can be later stopped by its PID.
    open('./.web-admin.pid', 'w').write(str(os.getpid()))
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'zato.admin.settings')
    call_command('loaddata', os.path.join(repo_dir, 'initial-data.json'))

    RepoManager(repo_dir).ensure_repo_consistency()

    # Cannot be imported before update_globals does its job of updating settings' configuration
    execute_from_command_line(['zato-web-admin', 'runserver', '--noreload', '{host}:{port}'.format(**config)])
Exemplo n.º 4
0
def main():
    
    repo_dir = os.path.join('.', 'config', 'repo')
    
    # Update Django settings
    config = json.loads(open(os.path.join(repo_dir, 'web-admin.conf')).read())
    config['config_dir'] = os.path.abspath('.')
    update_globals(config)
    
    # Store the PID so that the server can be later stopped by its PID.
    open('./.web-admin.pid', 'w').write(str(os.getpid()))
        
    os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
    call_command('loaddata', os.path.join(repo_dir, 'initial-data.json'))
    
    RepoManager(repo_dir).ensure_repo_consistency()

    app = WSGIHandler()
    make_server(config['host'], config['port'], app).serve_forever()
Exemplo n.º 5
0
def main():

    repo_dir = os.path.join(".", "config", "repo")

    # Update Django settings
    config = json.loads(open(os.path.join(repo_dir, "web-admin.conf")).read())
    config["config_dir"] = os.path.abspath(".")
    update_globals(config)

    # Store the PID so that the server can be later stopped by its PID.
    open("./.web-admin.pid", "w").write(str(os.getpid()))

    os.environ["DJANGO_SETTINGS_MODULE"] = "zato.admin.settings"
    call_command("loaddata", os.path.join(repo_dir, "initial-data.json"))

    RepoManager(repo_dir).ensure_repo_consistency()

    app = WSGIHandler()
    make_server(config["host"], config["port"], app).serve_forever()
Exemplo n.º 6
0
    def _prepare(self, args):

        # stdlib
        import os

        # Zato
        from zato.admin.zato_settings import update_globals
        from zato.common.json_internal import loads

        os.chdir(os.path.abspath(args.path))
        base_dir = os.path.join(self.original_dir, args.path)
        config = loads(
            open(os.path.join(base_dir, '.',
                              'config/repo/web-admin.conf')).read())
        config['config_dir'] = os.path.abspath(args.path)
        update_globals(config, base_dir)

        os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
        import django
        django.setup()
Exemplo n.º 7
0
def main():
    store_pidfile(os.path.abspath("."))
    repo_dir = os.path.join(".", "config", "repo")

    # Update Django settings
    config = json.loads(open(os.path.join(repo_dir, "web-admin.conf")).read())
    config["config_dir"] = os.path.abspath(".")
    update_globals(config)

    # Store the PID so that the server can be later stopped by its PID.
    open("./.web-admin.pid", "w").write(str(os.getpid()))

    os.environ["DJANGO_SETTINGS_MODULE"] = "zato.admin.settings"
    call_command("loaddata", os.path.join(repo_dir, "initial-data.json"))

    RepoManager(repo_dir).ensure_repo_consistency()

    # Cannot be imported before update_globals does its job of updating settings' configuration
    from zato.admin import settings

    execute_manager(settings, ["zato-web-admin", "runserver", "--noreload", "{host}:{port}".format(**config)])
Exemplo n.º 8
0
def main():
    store_pidfile(os.path.abspath('.'))
    repo_dir = os.path.join('.', 'config', 'repo')

    # Update Django settings
    config = json.loads(open(os.path.join(repo_dir, 'web-admin.conf')).read())
    config['config_dir'] = os.path.abspath('.')
    update_globals(config)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
    call_command('loaddata', os.path.join(repo_dir, 'initial-data.json'))

    RepoManager(repo_dir).ensure_repo_consistency()

    # Cannot be imported before update_globals does its job of updating settings' configuration
    from zato.admin import settings

    execute_manager(settings, [
        'zato-web-admin', 'runserver', '--noreload',
        '{host}:{port}'.format(**config)
    ])
Exemplo n.º 9
0
def main():
    store_pidfile(os.path.abspath('.'))
    repo_dir = os.path.join('.', 'config', 'repo')

    # Update Django settings
    config = json.loads(open(os.path.join(repo_dir, 'web-admin.conf')).read())
    config['config_dir'] = os.path.abspath('.')
    update_globals(config)

    # Store the PID so that the server can be later stopped by its PID.
    open('./.web-admin.pid', 'w').write(str(os.getpid()))
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'zato.admin.settings')
    call_command('loaddata', os.path.join(repo_dir, 'initial-data.json'))

    RepoManager(repo_dir).ensure_repo_consistency()

    # Cannot be imported before update_globals does its job of updating settings' configuration
    execute_from_command_line([
        'zato-web-admin', 'runserver', '--noreload',
        '{host}:{port}'.format(**config)
    ])
Exemplo n.º 10
0
    def execute(self,
                args,
                show_output=True,
                password=None,
                needs_admin_created_flag=False):
        os.chdir(self.target_dir)

        repo_dir = os.path.join(self.target_dir, 'config', 'repo')
        web_admin_conf_path = os.path.join(repo_dir, 'web-admin.conf')
        initial_data_json_path = os.path.join(repo_dir, 'initial-data.json')

        os.mkdir(os.path.join(self.target_dir, 'logs'))
        os.mkdir(os.path.join(self.target_dir, 'config'))
        os.mkdir(repo_dir)

        user_name = 'admin'
        password = password if password else generate_password()

        self.copy_web_admin_crypto(repo_dir, args)
        priv_key = open(os.path.join(repo_dir,
                                     'web-admin-priv-key.pem')).read()

        config = {
            'host':
            web_admin_host,
            'port':
            web_admin_port,
            'db_type':
            args.odb_type,
            'log_config':
            'logging.conf',
            'DATABASE_NAME':
            args.odb_db_name or args.sqlite_path,
            'DATABASE_USER':
            args.odb_user or '',
            'DATABASE_PASSWORD':
            encrypt(args.odb_password, priv_key) if args.odb_password else '',
            'DATABASE_HOST':
            args.odb_host or '',
            'DATABASE_PORT':
            args.odb_port or '',
            'SITE_ID':
            getrandbits(20),
            'SECRET_KEY':
            encrypt(uuid.uuid4().hex, priv_key),
            'ADMIN_INVOKE_NAME':
            'admin.invoke',
            'ADMIN_INVOKE_PASSWORD':
            encrypt(
                getattr(args, 'admin_invoke_password', None)
                or getattr(args, 'tech_account_password'), priv_key),
        }

        open(os.path.join(repo_dir, 'logging.conf'), 'w').write(
            common_logging_conf_contents.format(
                log_path='./logs/web-admin.log'))
        open(web_admin_conf_path, 'w').write(config_template.format(**config))
        open(initial_data_json_path,
             'w').write(initial_data_json.format(**config))

        # Initial info
        self.store_initial_info(self.target_dir,
                                self.COMPONENTS.WEB_ADMIN.code)

        config = json.loads(
            open(os.path.join(repo_dir, 'web-admin.conf')).read())
        config['config_dir'] = self.target_dir
        update_globals(config, self.target_dir)

        os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'

        import django
        django.setup()
        self.reset_logger(args, True)

        # Can't import these without DJANGO_SETTINGS_MODULE being set
        from django.contrib.auth.models import User
        from django.db import connection
        from django.db.utils import IntegrityError

        call_command('migrate',
                     run_syncdb=True,
                     interactive=False,
                     verbosity=0)
        call_command('loaddata', initial_data_json_path, verbosity=0)

        try:
            call_command('createsuperuser',
                         interactive=False,
                         username=user_name,
                         first_name='admin-first-name',
                         last_name='admin-last-name',
                         email='*****@*****.**')
            admin_created = True

            user = User.objects.get(username=user_name)
            user.set_password(password)
            user.save()

        except IntegrityError, e:
            admin_created = False
            connection._rollback()
            self.logger.info('Ignoring IntegrityError e:[%s]',
                             format_exc(e).decode('utf-8'))
Exemplo n.º 11
0
    def execute(self, args, show_output=True, admin_password=None, needs_admin_created_flag=False):
        os.chdir(self.target_dir)

        repo_dir = os.path.join(self.target_dir, 'config', 'repo')
        web_admin_conf_path = os.path.join(repo_dir, 'web-admin.conf')
        initial_data_json_path = os.path.join(repo_dir, 'initial-data.json')

        os.mkdir(os.path.join(self.target_dir, 'logs'))
        os.mkdir(os.path.join(self.target_dir, 'config'))
        os.mkdir(repo_dir)

        user_name = 'admin'
        admin_password = admin_password if admin_password else WebAdminCryptoManager.generate_password()

        self.copy_web_admin_crypto(repo_dir, args)

        zato_secret_key = WebAdminCryptoManager.generate_key()
        cm = WebAdminCryptoManager.from_secret_key(zato_secret_key)

        django_secret_key = uuid4().hex.encode('utf8')
        django_site_id = getrandbits(20)

        admin_invoke_password = getattr(args, 'admin_invoke_password', None) or getattr(args, 'tech_account_password')
        admin_invoke_password = admin_invoke_password.encode('utf8')

        odb_password = args.odb_password or ''
        odb_password = odb_password.encode('utf8')

        config = {
            'host': web_admin_host,
            'port': web_admin_port,
            'db_type': args.odb_type,
            'log_config': 'logging.conf',
            'zato_secret_key':zato_secret_key,
            'well_known_data': cm.encrypt(well_known_data.encode('utf8')),
            'DATABASE_NAME': args.odb_db_name or args.sqlite_path,
            'DATABASE_USER': args.odb_user or '',
            'DATABASE_PASSWORD': cm.encrypt(odb_password),
            'DATABASE_HOST': args.odb_host or '',
            'DATABASE_PORT': args.odb_port or '',
            'SITE_ID': django_site_id,
            'SECRET_KEY': cm.encrypt(django_secret_key),
            'ADMIN_INVOKE_NAME':'admin.invoke',
            'ADMIN_INVOKE_PASSWORD':cm.encrypt(admin_invoke_password),
        }

        for name in 'zato_secret_key', 'well_known_data', 'DATABASE_PASSWORD', 'SECRET_KEY', 'ADMIN_INVOKE_PASSWORD':
            config[name] = config[name].decode('utf8')

        open(os.path.join(repo_dir, 'logging.conf'), 'w').write(
            common_logging_conf_contents.format(log_path='./logs/web-admin.log'))
        open(web_admin_conf_path, 'w').write(config_template.format(**config))
        open(initial_data_json_path, 'w').write(initial_data_json.format(**config))

        # Initial info
        self.store_initial_info(self.target_dir, self.COMPONENTS.WEB_ADMIN.code)

        config = json.loads(open(os.path.join(repo_dir, 'web-admin.conf')).read())
        config['config_dir'] = self.target_dir
        update_globals(config, self.target_dir)

        os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'

        import django
        django.setup()
        self.reset_logger(args, True)

        # Can't import these without DJANGO_SETTINGS_MODULE being set
        from django.contrib.auth.models import User
        from django.db import connection
        from django.db.utils import IntegrityError

        call_command('migrate', run_syncdb=True, interactive=False, verbosity=0)
        call_command('loaddata', initial_data_json_path, verbosity=0)

        try:
            call_command(
                'createsuperuser', interactive=False, username=user_name, first_name='admin-first-name',
                last_name='admin-last-name', email='*****@*****.**')
            admin_created = True

            user = User.objects.get(username=user_name)
            user.set_password(admin_password)
            user.save()

        except IntegrityError:
            # This will happen if user 'admin' already exists, e.g. if this is not the first cluster in this database
            admin_created = False
            connection._rollback()

        # Needed because Django took over our logging config
        self.reset_logger(args, True)

        if show_output:
            if self.verbose:
                msg = """Successfully created a web admin instance.
    You can start it with the 'zato start {path}' command.""".format(path=os.path.abspath(os.path.join(os.getcwd(), self.target_dir)))
                self.logger.debug(msg)
            else:
                self.logger.info('OK')

        # We return it only when told to explicitly so when the command runs from CLI
        # it doesn't return a non-zero exit code.
        if needs_admin_created_flag:
            return admin_created
Exemplo n.º 12
0
    def execute(self, args, show_output=True, password=None):
        os.chdir(self.target_dir)

        repo_dir = os.path.join(self.target_dir, 'config', 'repo')
        zato_admin_conf_path = os.path.join(repo_dir, 'zato-admin.conf')
        initial_data_json_path = os.path.join(repo_dir, 'initial-data.json')

        os.mkdir(os.path.join(self.target_dir, 'logs'))
        os.mkdir(os.path.join(self.target_dir, 'config'))
        os.mkdir(os.path.join(self.target_dir, 'config', 'zdaemon'))
        os.mkdir(repo_dir)
        
        user_name = 'admin'
        password = password if password else generate_password()
        
        self.copy_zato_admin_crypto(repo_dir, args)
        pub_key = open(os.path.join(repo_dir, 'zato-admin-pub-key.pem')).read()
        
        config = {
            'host': zato_admin_host,
            'port': zato_admin_port,
            'db_type': args.odb_type,
            'log_config': 'logging.conf',
            'DATABASE_NAME': args.odb_db_name,
            'DATABASE_USER': args.odb_user,
            'DATABASE_PASSWORD': encrypt(args.odb_password, pub_key),
            'DATABASE_HOST': args.odb_host,
            'DATABASE_PORT': args.odb_port,
            'SITE_ID': getrandbits(20),
            'SECRET_KEY': encrypt(uuid.uuid4().hex, pub_key),
            'TECH_ACCOUNT_NAME':args.tech_account_name,
            'TECH_ACCOUNT_PASSWORD':encrypt(args.tech_account_password, pub_key),
        }
        
        open(os.path.join(repo_dir, 'logging.conf'), 'w').write(common_logging_conf_contents.format(log_path='./logs/zato-admin.log'))
        open(zato_admin_conf_path, 'w').write(config_template.format(**config))
        open(initial_data_json_path, 'w').write(initial_data_json.format(**config))
        
        # Initial info
        self.store_initial_info(self.target_dir, self.COMPONENTS.ZATO_ADMIN.code)
        
        config = json.loads(open(os.path.join(repo_dir, 'zato-admin.conf')).read())
        config['config_dir'] = self.target_dir
        update_globals(config, self.target_dir)
        
        os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'
        
        # Can't import these without DJANGO_SETTINGS_MODULE being set
        from django.contrib.auth.models import User
        from django.db import connection
        from django.db.utils import IntegrityError
        
        call_command('syncdb', interactive=False, verbosity=0)
        call_command('loaddata', initial_data_json_path, verbosity=0)
        
        try:
            call_command('createsuperuser', interactive=False, username=user_name, first_name='admin-first-name',
                                     last_name='admin-last-name', email='*****@*****.**')
            admin_created = True
        except IntegrityError, e:
            admin_created = False
            connection._rollback()
            msg = 'Ignoring IntegrityError e:[{}]'.format(format_exc(e))
            self.logger.info(msg)
Exemplo n.º 13
0
    def execute(self, args, show_output=True, password=None, needs_admin_created_flag=False):
        os.chdir(self.target_dir)

        repo_dir = os.path.join(self.target_dir, 'config', 'repo')
        web_admin_conf_path = os.path.join(repo_dir, 'web-admin.conf')
        initial_data_json_path = os.path.join(repo_dir, 'initial-data.json')

        os.mkdir(os.path.join(self.target_dir, 'logs'))
        os.mkdir(os.path.join(self.target_dir, 'config'))
        os.mkdir(repo_dir)

        user_name = 'admin'
        password = password if password else generate_password()

        self.copy_web_admin_crypto(repo_dir, args)
        priv_key = open(os.path.join(repo_dir, 'web-admin-priv-key.pem')).read()

        config = {
            'host': web_admin_host,
            'port': web_admin_port,
            'db_type': args.odb_type,
            'log_config': 'logging.conf',
            'DATABASE_NAME': args.odb_db_name or args.sqlite_path,
            'DATABASE_USER': args.odb_user or '',
            'DATABASE_PASSWORD': encrypt(args.odb_password, priv_key) if args.odb_password else '',
            'DATABASE_HOST': args.odb_host or '',
            'DATABASE_PORT': args.odb_port or '',
            'SITE_ID': getrandbits(20),
            'SECRET_KEY': encrypt(uuid.uuid4().hex, priv_key),
            'ADMIN_INVOKE_NAME':'admin.invoke',
            'ADMIN_INVOKE_PASSWORD':encrypt(getattr(args, 'admin_invoke_password', None) or getattr(args, 'tech_account_password'), priv_key),
        }

        open(os.path.join(repo_dir, 'logging.conf'), 'w').write(common_logging_conf_contents.format(log_path='./logs/web-admin.log'))
        open(web_admin_conf_path, 'w').write(config_template.format(**config))
        open(initial_data_json_path, 'w').write(initial_data_json.format(**config))

        # Initial info
        self.store_initial_info(self.target_dir, self.COMPONENTS.WEB_ADMIN.code)

        config = json.loads(open(os.path.join(repo_dir, 'web-admin.conf')).read())
        config['config_dir'] = self.target_dir
        update_globals(config, self.target_dir)

        os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'

        # Can't import these without DJANGO_SETTINGS_MODULE being set
        from django.contrib.auth.models import User
        from django.db import connection
        from django.db.utils import IntegrityError

        call_command('syncdb', interactive=False, verbosity=0)
        call_command('loaddata', initial_data_json_path, verbosity=0)

        try:
            call_command(
                'createsuperuser', interactive=False, username=user_name, first_name='admin-first-name',
                last_name='admin-last-name', email='*****@*****.**')
            admin_created = True

            user = User.objects.get(username=user_name)
            user.set_password(password)
            user.save()

        except IntegrityError, e:
            admin_created = False
            connection._rollback()
            self.logger.info('Ignoring IntegrityError e:[%s]', format_exc(e).decode('utf-8'))
Exemplo n.º 14
0
    def execute(self,
                args,
                show_output=True,
                admin_password=None,
                needs_admin_created_flag=False):

        try:
            import pymysql
            pymysql.install_as_MySQLdb()
        except ImportError:
            pass

        # stdlib
        import os, json
        from random import getrandbits
        from uuid import uuid4

        # Django
        from django.core.management import call_command

        # Python 2/3 compatibility
        from past.builtins import unicode

        # Zato
        # TODO: There really shouldn't be any direct dependency between zato-cli and zato-web-admin
        from zato.admin.zato_settings import update_globals

        from zato.cli import common_logging_conf_contents, is_arg_given
        from zato.common.crypto.api import WebAdminCryptoManager
        from zato.common.crypto.const import well_known_data
        from zato.common.defaults import web_admin_host, web_admin_port

        os.chdir(self.target_dir)

        repo_dir = os.path.join(self.target_dir, 'config', 'repo')
        web_admin_conf_path = os.path.join(repo_dir, 'web-admin.conf')
        initial_data_json_path = os.path.join(repo_dir, 'initial-data.json')

        os.mkdir(os.path.join(self.target_dir, 'logs'))
        os.mkdir(os.path.join(self.target_dir, 'config'))
        os.mkdir(repo_dir)

        user_name = 'admin'
        admin_password = admin_password if admin_password else WebAdminCryptoManager.generate_password(
        )

        # If we have a CA's certificate then it implicitly means that there is some CA
        # which tells us that we are to trust both the CA and the certificates that it issues,
        # and the only certificate we are interested in is the one to the load-balancer.
        # This is why, if we get ca_certs_path, it must be because we are to use TLS
        # in communication with the load-balancer's agent which in turn means that we have crypto material on input.
        has_crypto = is_arg_given(args, 'ca_certs_path')

        if has_crypto:
            self.copy_web_admin_crypto(repo_dir, args)

        zato_secret_key = WebAdminCryptoManager.generate_key()
        cm = WebAdminCryptoManager.from_secret_key(zato_secret_key)

        django_secret_key = uuid4().hex.encode('utf8')
        django_site_id = getrandbits(20)

        admin_invoke_password = getattr(args, 'admin_invoke_password', None)

        if not admin_invoke_password:
            admin_invoke_password = '******' + uuid4().hex

        if isinstance(admin_invoke_password, unicode):
            admin_invoke_password = admin_invoke_password.encode('utf8')

        odb_password = args.odb_password or ''
        odb_password = odb_password.encode('utf8')

        config = {
            'host': web_admin_host,
            'port': web_admin_port,
            'db_type': args.odb_type,
            'log_config': 'logging.conf',
            'lb_agent_use_tls': 'true' if has_crypto else 'false',
            'zato_secret_key': zato_secret_key,
            'well_known_data': cm.encrypt(well_known_data.encode('utf8')),
            'DATABASE_NAME': args.odb_db_name or args.sqlite_path,
            'DATABASE_USER': args.odb_user or '',
            'DATABASE_PASSWORD': cm.encrypt(odb_password),
            'DATABASE_HOST': args.odb_host or '',
            'DATABASE_PORT': args.odb_port or '',
            'SITE_ID': django_site_id,
            'SECRET_KEY': cm.encrypt(django_secret_key),
            'ADMIN_INVOKE_NAME': 'admin.invoke',
            'ADMIN_INVOKE_PASSWORD': cm.encrypt(admin_invoke_password),
        }

        for name in 'zato_secret_key', 'well_known_data', 'DATABASE_PASSWORD', 'SECRET_KEY', 'ADMIN_INVOKE_PASSWORD':
            config[name] = config[name].decode('utf8')

        open(os.path.join(repo_dir, 'logging.conf'), 'w').write(
            common_logging_conf_contents.format(
                log_path='./logs/web-admin.log'))
        open(web_admin_conf_path, 'w').write(config_template.format(**config))
        open(initial_data_json_path,
             'w').write(initial_data_json.format(**config))

        # Initial info
        self.store_initial_info(self.target_dir,
                                self.COMPONENTS.WEB_ADMIN.code)

        config = json.loads(
            open(os.path.join(repo_dir, 'web-admin.conf')).read())
        config['config_dir'] = self.target_dir
        update_globals(config, self.target_dir)

        os.environ['DJANGO_SETTINGS_MODULE'] = 'zato.admin.settings'

        import django
        django.setup()
        self.reset_logger(args, True)

        # Can't import these without DJANGO_SETTINGS_MODULE being set
        from django.contrib.auth.models import User
        from django.db import connection
        from django.db.utils import IntegrityError

        call_command('migrate',
                     run_syncdb=True,
                     interactive=False,
                     verbosity=0)
        call_command('loaddata', initial_data_json_path, verbosity=0)

        try:
            call_command('createsuperuser',
                         interactive=False,
                         username=user_name,
                         first_name='admin-first-name',
                         last_name='admin-last-name',
                         email='*****@*****.**')
            admin_created = True

            user = User.objects.get(username=user_name)
            user.set_password(admin_password)
            user.save()

        except IntegrityError:
            # This will happen if user 'admin' already exists, e.g. if this is not the first cluster in this database
            admin_created = False
            connection._rollback()

        # Needed because Django took over our logging config
        self.reset_logger(args, True)

        if show_output:
            if self.verbose:
                msg = """Successfully created a web admin instance.
    You can start it with the 'zato start {path}' command.""".format(
                    path=os.path.abspath(
                        os.path.join(os.getcwd(), self.target_dir)))
                self.logger.debug(msg)
            else:
                self.logger.info('OK')

        # We return it only when told to explicitly so when the command runs from CLI
        # it doesn't return a non-zero exit code.
        if needs_admin_created_flag:
            return admin_created