def main(argv=sys.argv): if len(argv) < 2: usage(argv) config_uri = argv[1] options = parse_vars(argv[2:]) setup_logging(config_uri) # configure connections for Postgres, ElasticSearch and Redis settings = get_appsettings(config_uri, options=options) engine = engine_from_config(settings, 'sqlalchemy.') Session = sessionmaker() # noqa Session.configure(bind=engine) configure_es_from_config(settings) queue_config = get_queue_config(settings) batch_size = int(settings.get('elasticsearch.batch_size.syncer', 1000)) with queue_config.connection: try: worker = SyncWorker( queue_config.connection, queue_config.queue, batch_size, session_factory=Session) log.info('Syncer started, running initial sync') worker.sync() log.info('Waiting on messages') worker.run() except KeyboardInterrupt: log.info('Syncer stopped')
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ # Configure SQLAlchemy engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) Base.metadata.bind = engine # Configure ElasticSearch configure_es_from_config(settings) config = Configurator(settings=settings) config.include('cornice') config.registry.queue_config = get_queue_config(settings) bypass_auth = False if 'noauthorization' in settings: bypass_auth = asbool(settings['noauthorization']) if not bypass_auth: config.include("pyramid_jwtauth") # Intercept request handling to validate token against the database config.add_tween('c2corg_api.jwt_database_validation_tween_factory') # Inject ACLs config.set_root_factory(RootFactory) else: log.warning('Bypassing authorization') configure_caches(settings) # Scan MUST be the last call otherwise ACLs will not be set # and the permissions would be bypassed config.scan(ignore='c2corg_api.tests') return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ # Configure SQLAlchemy engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) Base.metadata.bind = engine # Configure ElasticSearch configure_es_from_config(settings) config = Configurator(settings=settings) config.include('cornice') config.registry.queue_config = get_queue_config(settings) bypass_auth = False if 'noauthorization' in settings: bypass_auth = asbool(settings['noauthorization']) if not bypass_auth: config.include("pyramid_jwtauth") # Intercept request handling to validate token against the database config.add_tween('c2corg_api.jwt_database_validation_tween_factory') # Inject ACLs config.set_root_factory(RootFactory) else: log.warning('Bypassing authorization') # Scan MUST be the last call otherwise ACLs will not be set # and the permissions would be bypassed config.scan(ignore='c2corg_api.tests') return config.make_wsgi_app()
def main(argv=sys.argv): parser = argparse.ArgumentParser() parser.add_argument("src_id", help="Source user identifier", type=int) parser.add_argument("tgt_id", help="Target user identifier", type=int) parser.add_argument( "-f", "--force", action="store_true", help="Merge user without confirmation" ) args = parser.parse_args() source_user_id = args.src_id target_user_id = args.tgt_id if source_user_id == target_user_id: exit('ERROR: source and target user accounts cannot be the same') settings_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../../production.ini') settings = get_appsettings(settings_file) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) queue_config = get_queue_config(settings) logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.WARN) source_user = DBSession.query(User).get(source_user_id) if not source_user: exit('ERROR: source user account (id {}) does not exist'.format( source_user_id)) target_user = DBSession.query(User).get(target_user_id) if not target_user: exit('ERROR: target user account (id {}) does not exist'.format( target_user_id)) if not args.force: sys.stdout.write( '\n' 'Are you sure you want to merge the following accounts? [y/N]\n' 'source: id {}: {}/{}\n' 'target: id {}: {}/{}\n'.format( source_user.id, source_user.name, source_user.forum_username, target_user.id, target_user.name, target_user.forum_username)) if input().lower()[:1] != 'y': exit('ABORTED: User accounts merging has been aborted') print('Merging user account {} to user account {} in progress.\n' 'Please wait...'.format(source_user_id, target_user_id)) with transaction.manager: merge_user_accounts(source_user_id, target_user_id, queue_config) print('SUCCESS: User account {} has been merged to user account {}'.format( source_user_id, target_user_id))
def main(argv=sys.argv): if len(argv) < 3: usage(argv) source_user_id = int(argv[1]) target_user_id = int(argv[2]) if source_user_id == target_user_id: exit('ERROR: source and target user accounts cannot be the same') settings_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../../production.ini') settings = get_appsettings(settings_file) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) queue_config = get_queue_config(settings) logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.WARN) source_user = DBSession.query(User).get(source_user_id) if not source_user: exit('ERROR: source user account (id {}) does not exist'.format( source_user_id)) target_user = DBSession.query(User).get(target_user_id) if not target_user: exit('ERROR: target user account (id {}) does not exist'.format( target_user_id)) sys.stdout.write( '\n' 'Are you sure you want to merge the following user accounts? [y/N]\n' 'source: id {}: {}/{}\n' 'target: id {}: {}/{}\n'.format( source_user.id, source_user.name, source_user.forum_username, target_user.id, target_user.name, target_user.forum_username)) if input().lower()[:1] != 'y': exit('ABORTED: User accounts merging has been aborted') print('Merging user account {} to user account {} in progress.\n' 'Please wait...'.format(source_user_id, target_user_id)) with transaction.manager: merge_user_accounts(source_user_id, target_user_id, queue_config) print('SUCCESS: User account {} has been merged to user account {}'.format( source_user_id, target_user_id))