def main(host, port): "starts betanin" _print_meta_info() _ensure_config() _ensure_secret_key() signal.signal(signal.SIGINT, _stop) signal.signal(signal.SIGTERM, _stop) gevent.hub.Hub.NOT_ERROR = (OSError, SystemExit) app = application.create() with app.app_context(): _migrate_database() _retry_old_imports() _register_notifications() conf = conf_betanin.read() num_imports = conf_betanin.find_num_parallel_jobs(conf) gevent.joinall( ( *(_start_job(app, import_torrents) for _ in range(num_imports)), _start_job(app, serve_web, host, port), ) )
def register_all(): config = conf_betanin.read() APPRISE.clear() APPRISE.add([ f'{service["protocol"]}://{service["not_protocol"]}' for service in config["notifications"]["services"].values() if all(service[key] for key in ("enabled", "protocol", "not_protocol")) ])
def wrapper(*args, **kwargs): api_key = request.headers.get("X-API-Key") if not api_key: verify_jwt_in_request() return func(*args, **kwargs) conf = conf_betanin.read() if conf_betanin.find_api_key_correct(conf, api_key): return func(*args, **kwargs) return abort(422, "no valid auth provided")
def post(): "generates a json web token for the given username / password" args = req_models.CREDENTIALS.parse_args() conf = conf_betanin.read() if not conf_betanin.find_creds_correct( conf, args["username"], args["password"] ): return abort(422, "invalid username / password") return {"token": create_access_token(args["username"])}
def _ensure_config(): logger.info(f"using config `{paths.CONFIG_PATH}`") if os.path.exists(paths.CONFIG_PATH): conf = conf_betanin.read() if ( not conf["frontend"] or not conf["frontend"]["username"] or not conf["frontend"]["password"] ): logger.error("please provide a frontend username and password") sys.exit(1) if not conf["clients"] or not conf["clients"]["api_key"]: logger.error("please provide an api key") sys.exit(1) return logger.error(f"`{paths.CONFIG_PATH}`: doesn't exist. creating and exiting") conf = conf_betanin.DEFAULT_CONFIG conf["clients"]["api_key"] = conf_betanin.gen_api_key() conf_betanin.write(conf) sys.exit(1)
def send(torrent): config = conf_betanin.read() templates = _make_templates(config) variables = { "name": torrent.name, "id": torrent.id, "time": torrent.updated, "console_path": f"#/torrents/console/{torrent.id}", "status": STATUS_LONG.get( torrent.status, # custom f"has status {torrent.status.name.lower()}", # default ), } APPRISE.notify( title=templates["title"].safe_substitute(variables), body=templates["body"].safe_substitute(variables), )
def get(): "fetches the clients api key" conf = conf_betanin.read() return {"api_key": conf_betanin.find_api_key(conf)}
def get_strings(): config = conf_betanin.read() return config["notifications"]["strings"]