Example #1
0
    def test_get_user_manager(self):
        # Get absolute path to development ini file.
        script_dir = os.path.dirname(os.path.realpath(__file__))
        ini_file_path = os.path.join(script_dir,
                                     "assets",
                                     "test.conf")

        # Create temporary files and dirs the server will use.
        server_paths = helpers.server_utils.create_server_paths()

        config = configparser.ConfigParser()
        config.read(ini_file_path)

        # Use custom files and dirs in settings. Should be SqliteUserManager
        config['sync_app'].update(server_paths)
        self.assertTrue(type(get_user_manager(config['sync_app']) == SqliteUserManager))

        # No value defaults to SimpleUserManager
        config.remove_option("sync_app", "auth_db_path")
        self.assertTrue(type(get_user_manager(config['sync_app'])) == SimpleUserManager)

        # A conf-specified UserManager is loaded
        config.set("sync_app", "user_manager", 'test_users.FakeUserManager')
        self.assertTrue(type(get_user_manager(config['sync_app'])) == FakeUserManager)

        # Should fail at load time if the class doesn't inherit from  SimpleUserManager
        config.set("sync_app", "user_manager", 'test_users.BadUserManager')
        with self.assertRaises(TypeError):
            um = get_user_manager(config['sync_app'])

        # Add the auth_db_path back, it should take precedence over BadUserManager
        config['sync_app'].update(server_paths)
        self.assertTrue(type(get_user_manager(config['sync_app']) == SqliteUserManager))
def deluser(username):
    user_manager = get_user_manager(config)
    try:
        user_manager.del_user(username)
    except ValueError as error:
        print("Could not delete user {}: {}".format(username, error),
              file=sys.stderr)
Example #3
0
def create_app(config=None,
               sync_app=None,
               user_manager=None,
               collection_manager=None):

    from flask import Flask

    logging.basicConfig(
        level=logging.DEBUG,
        format="[%(asctime)s]:%(levelname)s:%(name)s:%(message)s")

    if config is None:
        config = load()

    app = Flask("ankisyncd")
    app.logger.setLevel(logging.DEBUG)

    if user_manager is None:
        user_manager = get_user_manager(config)

    if collection_manager is None:
        collection_manager = get_collection_manager(config)

    if sync_app is None:
        sync_app = SyncApp(config,
                           user_manager=user_manager,
                           collection_manager=collection_manager)

    app.register_blueprint(sync.create_blueprint(sync_app=sync_app))
    app.register_blueprint(
        api.create_blueprint(config, user_manager, collection_manager),
        url_prefix="/api",
    )

    return app
Example #4
0
    def __init__(self, config, user_manager=None, collection_manager=None):
        from ankisyncd.thread import get_collection_manager

        self.data_root = os.path.abspath(config["data_root"])
        self.base_url = config["base_url"]
        self.base_media_url = config["base_media_url"]
        self.setup_new_collection = None

        self.prehooks = {}
        self.posthooks = {}

        if not user_manager:
            self.user_manager = get_user_manager(config)
        else:
            self.user_manager = user_manager

        if not collection_manager:
            self.collection_manager = get_collection_manager(config)
        else:
            self.collection_manager = collection_manager

        self.session_manager = get_session_manager(config)
        self.full_sync_manager = get_full_sync_manager(config)

        # make sure the base_url has a trailing slash
        if not self.base_url.endswith("/"):
            self.base_url += "/"
        if not self.base_media_url.endswith("/"):
            self.base_media_url += "/"
def lsuser():
    user_manager = get_user_manager(config)
    try:
        users = user_manager.user_list()
        for username in users:
            print(username)
    except ValueError as error:
        print("Could not list users: {}".format(error), file=sys.stderr)
Example #6
0
def lsuser():
    user_manager = get_user_manager(config)
    try:
        users = user_manager.user_list()
        for username in users:
            print(username)
    except ValueError as error:
        print("Could not list users: {}".format(error), file=sys.stderr)
def passwd(username):
    user_manager = get_user_manager(config)

    if username not in user_manager.user_list():
        print("User {} doesn't exist".format(username))
        return

    password = getpass.getpass("Enter password for {}: ".format(username))
    try:
        user_manager.set_password_for_user(username, password)
    except ValueError as error:
        print("Could not set password for user {}: {}".format(username, error), file=sys.stderr)
Example #8
0
    def __init__(self, config):
        from ankisyncd.thread import get_collection_manager

        self.data_root = os.path.abspath(config['data_root'])
        self.base_url  = config['base_url']
        self.base_media_url  = config['base_media_url']
        self.setup_new_collection = None

        self.user_manager = get_user_manager(config)
        self.session_manager = get_session_manager(config)
        self.full_sync_manager = get_full_sync_manager(config)
        self.collection_manager = get_collection_manager(config)

        # make sure the base_url has a trailing slash
        if not self.base_url.endswith('/'):
            self.base_url += '/'
        if not self.base_media_url.endswith('/'):
            self.base_media_url += '/'
Example #9
0
    def __init__(self, config):
        from ankisyncd.thread import get_collection_manager

        self.data_root = os.path.abspath(config['data_root'])
        self.base_url  = config['base_url']
        self.base_media_url  = config['base_media_url']
        self.setup_new_collection = None

        self.prehooks = {}
        self.posthooks = {}

        self.user_manager = get_user_manager(config)
        self.session_manager = get_session_manager(config)
        self.full_sync_manager = get_full_sync_manager(config)
        self.collection_manager = get_collection_manager(config)

        # make sure the base_url has a trailing slash
        if not self.base_url.endswith('/'):
            self.base_url += '/'
        if not self.base_media_url.endswith('/'):
            self.base_media_url += '/'
def adduser(username):
    password = getpass.getpass("Enter password for {}: ".format(username))

    user_manager = get_user_manager(config)
    user_manager.add_user(username, password)
def inituser(username, password):
    # one line create user for dockerfile, username equal password.
    user_manager = get_user_manager(config)
    user_manager.add_user(username, password)
    print('Done.')
Example #12
0
def deluser(username):
    user_manager = get_user_manager(config)
    try:
        user_manager.del_user(username)
    except ValueError as error:
        print("Could not delete user {}: {}".format(username, error), file=sys.stderr)
Example #13
0
def adduser(username):
    password = getpass.getpass("Enter password for {}: ".format(username))

    user_manager = get_user_manager(config)
    user_manager.add_user(username, password)