def _init_user_manager(self): user_manager = CLIUserManager() user, _ = user_manager.create_user(email='test@localhost', username='******', passwd='LocalUser1', role='public-archivist', name='local') return user_manager, user
def _runner_init(self): os.environ['WR_USER_CONFIG'] = 'pkg://webrecorder/config/standalone_recorder.yaml' os.environ['SECRET_KEY'] = base64.b32encode(os.urandom(75)).decode('utf-8') os.environ['RECORD_ROOT'] = os.path.join(self.root_dir, 'warcs', '') os.environ['STORAGE_ROOT'] = os.path.join(self.root_dir, 'storage', '') os.environ['REDIS_BROWSER_URL'] = 'redis://*****:*****@localhost'.format(self.default_user), username=self.default_user, passwd='LocalUser1', role='admin', name=self.default_user) print('DEFAULT_USER='******'max_size', max_size) except Exception as e: print(e) os.environ['AUTO_LOGIN_USER'] = self.default_user
def test_create_another_user(self): m = CLIUserManager() m.create_user( email='*****@*****.**', username='******', passwd='Test12345', role='archivist', name='Test User') assert self.redis.exists('u:Testauto:info') assert self.redis.hget(CLIUserManager.LC_USERNAMES_KEY, 'testauto') == 'Testauto'
def _init_user_manager(self): user_manager = CLIUserManager() user, _ = user_manager.create_user( email='test@localhost', username='******', passwd='LocalUser1', role='public-archivist', name='local') return user_manager, user
def setup_class(cls, **kwargs): os.environ['AUTO_LOGIN_USER'] = '******' super(TestAutoLogin, cls).setup_class(temp_worker=True, storage_worker=True, init_anon=False) cls.manager = CLIUserManager()
def __init__(self, old_redis_url, new_redis_url, dry_run=True, per_recording_list=False, s3_import=False, s3_root=None): self.old_redis = StrictRedis.from_url(old_redis_url, decode_responses=True) self.dry_run = dry_run self.per_recording_list = per_recording_list self.s3_import = s3_import if s3_import: assert (s3_root) import boto3 self.s3_root = s3_root self.s3 = boto3.client('s3') else: self.s3_root = None self.s3 = None if self.dry_run: import redis redis.StrictRedis = fakeredis.FakeStrictRedis self.redis = FakeStrictRedis.from_url(new_redis_url, decode_responses=True) else: self.redis = StrictRedis.from_url(new_redis_url, decode_responses=True) print('Redis Inited') self.cli = CLIUserManager(new_redis_url)
def setup_class(cls, **kwargs): super(TestLoginMigrate, cls).setup_class(extra_config_file='test_cdxj_cache_config.yaml', storage_worker=True, temp_worker=True) cls.user_manager = CLIUserManager()
def load_cache(self): if not self.serializer: logging.debug('No Serializer, indexing') return False if not self.inputs: logging.debug('Not Loading WARCs') if not self.serializer.load_db(): logging.debug('Index Not Loaded from cache, Reindexing') user_manager = CLIUserManager() try: user = user_manager.all_users['local'] except: logging.debug('Cached Index Invalid, missing user') return False collection = user.get_collection_by_name('collection') if not collection: logging.debug('Cached Index Invalid, missing collection') return False self._init_browser_redis(user, collection) logging.debug('Index Loaded from Cache, Skipping Reindex') return True
def setup_class(cls, **kwargs): os.environ['CONTENT_HOST'] = 'content-host' os.environ['APP_HOST'] = 'app-host' os.environ[ 'SESSION_SHARE_ORIGIN'] = 'http://sharedsession.example.com/' kwargs['init_anon'] = False super(TestAppContentDomain, cls).setup_class(**kwargs) cls.manager = CLIUserManager()
def setup_class(cls, **kwargs): super(TestUpload, cls).setup_class(temp_worker=False) cls.manager = CLIUserManager() cls.warc = None cls.test_upload_warc = os.path.join(cls.get_curr_dir(), 'warcs', 'test_3_15_upload.warc.gz')
def setup_class(cls): os.environ['RATE_LIMIT_MAX'] = str(cls.BASE_LIMIT) os.environ['RATE_LIMIT_HOURS'] = '2' os.environ['RATE_LIMIT_RESTRICTED_HOURS'] = '2' os.environ['RATE_LIMIT_RESTRICTED_MAX'] = str(cls.RESTRICT_LIMIT) os.environ['RATE_LIMIT_RESTRICTED_IPS'] = '255.255.255,10.0.0' super(TestRateLimits, cls).setup_class() cls.user_manager = CLIUserManager()
def setup_class(cls): os.environ['ALLOW_DAT'] = '1' super(TestDatShare, cls).setup_class(storage_worker=True) cls.manager = CLIUserManager() cls.set_uuids('Collection', count(int(cls.COLL_ID) - 1)) cls.dat_info = {'datKey': get_new_id(size=20), 'discoveryKey': get_new_id(size=20) }
def setup_class(cls): os.environ['ALLOW_EXTERNAL'] = '1' os.environ[ 'CONTENT_ERROR_REDIRECT'] = 'http://external.example.com/error' os.environ['CONTENT_HOST'] = 'content-host' os.environ['APP_HOST'] = 'app-host' cls.upload_filename = os.path.join(cls.get_curr_dir(), 'warcs', 'test_3_15_upload.warc.gz') super(TestExternalColl, cls).setup_class(init_anon=False, temp_worker=True, storage_worker=True) cls.user_manager = CLIUserManager()
def setup_class(cls): os.environ['AUTO_LOGIN_USER'] = '******' super(BaseStorageCommit, cls).setup_class(extra_config_file='test_cdxj_cache_config.yaml', storage_worker=True, init_anon=False) cls.set_uuids('Recording', count(500)) cls.set_uuids('Collection', count(100)) cls.user_manager = CLIUserManager() cls.user_manager.create_user('*****@*****.**', 'test', 'TestTest456', 'archivist', 'Test User')
def main(args=None): parser = ArgumentParser(formatter_class=RawTextHelpFormatter) parser.add_argument('-c', '--create-user', dest='create_user', nargs='*', default=None, help=('Interface to add a new user. \n\n' 'supply arguments e.g.\n' '`python admin.py -c <email> <username> <passwd> <role> \'<full name>\'`\n' '\n or simply `python admin.py -c` for interactive creation.')) parser.add_argument('-m', '--modify-user', dest='modify_user', action='store_true', help='Interface to modify a user (role, email)') parser.add_argument('-d', '--delete-user', dest='delete_user', action='store_true', help='Interface to delete a user.') parser.add_argument('-i', '--invite') parser.add_argument('-l', '--list', action='store_true') parser.add_argument('-b', '--backlog') parser.add_argument('--check', help="check if username exists") parser.add_argument('-u', '--users', action="store_true", help="list all existing users") r = parser.parse_args(args=args) m = CLIUserManager() if r.backlog: do_invite_backlog(m, r.backlog) elif r.list: list_not_invited(m, r.invite_all) elif r.invite: do_invite(m, r.invite) elif r.create_user is not None: m.create_user(*r.create_user) elif r.modify_user: m.modify_user() elif r.delete_user: m.delete_user() elif r.check: m.check_user(r.check) elif r.users: m.list_users() else: print('All systems go! See --help for usage')
def setup_class(cls, **kwargs): os.environ['CONTENT_HOST'] = 'content-host' os.environ['APP_HOST'] = 'app-host' kwargs['init_anon'] = False super(TestAppContentDomain, cls).setup_class(**kwargs) cls.manager = CLIUserManager()
def setup_class(cls): super(TestListsAPIAccess, cls).setup_class(init_anon=False) cls.user_manager = CLIUserManager()
def setup_class(cls): super(TestAdminAPI, cls).setup_class() cls.user_manager = CLIUserManager()
class WebrecorderRunner(StandaloneRunner): REDIS_PORT = 7679 def __init__(self, argres): self.root_dir = argres.root_dir self.redis_dir = os.path.join(self.root_dir, 'redis') self.user_manager = None self.browser_redis = None self.default_user = argres.default_user self.browser_id = base64.b32encode(os.urandom(15)).decode('utf-8') self.dat_share_port = argres.dat_share_port self.behaviors_tarfile = argres.behaviors_tarfile super(WebrecorderRunner, self).__init__(argres, rec_port=0) if not argres.no_browser: import webbrowser webbrowser.open_new(os.environ['APP_HOST'] + '/') def _runner_init(self): os.environ['WR_USER_CONFIG'] = 'pkg://webrecorder/config/standalone_recorder.yaml' os.environ['SECRET_KEY'] = base64.b32encode(os.urandom(75)).decode('utf-8') os.environ['RECORD_ROOT'] = os.path.join(self.root_dir, 'warcs', '') os.environ['STORAGE_ROOT'] = os.path.join(self.root_dir, 'storage', '') os.environ['REDIS_BROWSER_URL'] = 'redis://*****:*****@localhost'.format(self.default_user), username=self.default_user, passwd='LocalUser1', role='admin', name=self.default_user) # set max_size to available free space, if possible try: res = shutil.disk_usage(self.root_dir) max_size = res[2] user = self.user_manager.all_users[self.default_user] user.set_prop('max_size', max_size) except Exception as e: print(e) os.environ['AUTO_LOGIN_USER'] = self.default_user def close(self): for key in self.browser_redis.scan_iter('up:{0}:*'.format(self.browser_id)): print('Delete: ' + key) self.browser_redis.delete(key) super(WebrecorderRunner, self).close() @classmethod def add_args(cls, parser): parser.add_argument('-d', '--root-dir', default='./data/', help='Root Data Dir') parser.add_argument('-u', '--default-user', default=None, help='Create & Auto-Login as Default User') parser.add_argument('--dat-share-port', default=None, help='Dat Share API server port') parser.add_argument('--behaviors-tarfile', default=None, help='Behaviors Tarfile')