Beispiel #1
0
    def post(self):
        """ Creates the initial super user, updates the underlying configuration and
        sets the current session to have that super user. """

        _reload_config()

        # Special security check: This method is only accessible when:
        #   - There is a valid config YAML file.
        #   - There are currently no users in the database (clean install)
        #
        # We do this special security check because at the point this method is called, the database
        # is clean but does not (yet) have any super users for our permissions code to check against.
        if config_provider.config_exists() and not database_has_users():
            data = request.get_json()
            username = data['username']
            password = data['password']
            email = data['email']

            # Create the user in the database.
            superuser_uuid = model.create_superuser(username, password, email)

            # Add the user to the config.
            config_object = config_provider.get_config()
            config_object['SUPER_USERS'] = [username]
            config_provider.save_config(config_object)

            # Update the in-memory config for the new superuser.
            superusers.register_superuser(username)

            return {'status': True}

        abort(403)
Beispiel #2
0
    def get(self):
        """ Returns the status of the registry. """
        # If there is no config file, we need to setup the database.
        if not config_provider.config_exists():
            return {"status": "config-db"}

        # If the database isn't yet valid, then we need to set it up.
        if not database_is_valid():
            return {"status": "setup-db"}

        config = config_provider.get_config()
        if config and config.get("SETUP_COMPLETE"):
            return {"status": "config"}

        return {"status": "create-superuser" if not database_has_users() else "config"}
Beispiel #3
0
    def put(self):
        """ Loads tarball config into the config provider """
        # Generate a new empty dir to load the config into
        config_provider.new_config_dir()
        input_stream = request.stream
        with tarfile.open(mode="r|gz", fileobj=input_stream) as tar_stream:
            tar_stream.extractall(config_provider.get_config_dir_path())

        config_provider.create_copy_of_config_dir()

        # now try to connect to the db provided in their config to validate it works
        combined = dict(**app.config)
        combined.update(config_provider.get_config())
        configure(combined)

        return make_response('OK')
Beispiel #4
0
    def post(self):
        # Get a clean transient directory to write the config into
        config_provider.new_config_dir()

        kube_accessor = KubernetesAccessorSingleton.get_instance()
        kube_accessor.save_secret_to_directory(config_provider.get_config_dir_path())
        config_provider.create_copy_of_config_dir()

        # We update the db configuration to connect to their specified one
        # (Note, even if this DB isn't valid, it won't affect much in the config app, since we'll report an error,
        # and all of the options create a new clean dir, so we'll never pollute configs)
        combined = dict(**app.config)
        combined.update(config_provider.get_config())
        configure(combined)

        return 200
Beispiel #5
0
    def get(self):
        """ Returns the status of the registry. """
        # If there is no config file, we need to setup the database.
        if not config_provider.config_exists():
            return {'status': 'config-db'}

        # If the database isn't yet valid, then we need to set it up.
        if not database_is_valid():
            return {'status': 'setup-db'}

        config = config_provider.get_config()
        if config and config.get('SETUP_COMPLETE'):
            return {'status': 'config'}

        return {
            'status':
            'create-superuser' if not database_has_users() else 'config'
        }
Beispiel #6
0
    def put(self):
        """ Updates the config override file. """
        # Note: This method is called to set the database configuration before super users exists,
        # so we also allow it to be called if there is no valid registry configuration setup.
        config_object = request.get_json()['config']

        # Add any enterprise defaults missing from the config.
        add_enterprise_config_defaults(config_object, app.config['SECRET_KEY'])

        # Write the configuration changes to the config override file.
        config_provider.save_config(config_object)

        # now try to connect to the db provided in their config to validate it works
        combined = dict(**app.config)
        combined.update(config_provider.get_config())
        configure(combined, testing=app.config['TESTING'])

        return {'exists': True, 'config': config_object}
Beispiel #7
0
 def get(self):
     """ Returns the currently defined configuration, if any. """
     config_object = config_provider.get_config()
     return {'config': config_object}
Beispiel #8
0
def _reload_config():
    combined = dict(**app.config)
    combined.update(config_provider.get_config())
    configure(combined)
    return combined