def wrapper(*args, **kwargs): get_claims() if len(settings.LEEK_API_WHITELISTED_ORGS ) and g.org_name not in settings.LEEK_API_WHITELISTED_ORGS: raise JWTError( f'Only {settings.LEEK_API_WHITELISTED_ORGS} are whitelisted to use this app' ) if allowed_org_names: if g.org_name not in allowed_org_names: raise JWTError( f'Only {allowed_org_names} org can access this endpoint' ) if only_app_owner: try: app_name = request.headers["x-leek-app-name"] except KeyError as e: return responses.missing_headers try: app = get_app(f"{g.org_name}-{app_name}") if g.email != app.get("owner"): return responses.insufficient_permission except es_exceptions.NotFoundError: return responses.application_not_found except es_exceptions.ConnectionError: return responses.cache_backend_unavailable return route(*args, **kwargs)
def wrapper(*args, **kwargs): g.app_name = request.headers.get("x-leek-app-name") g.app_env = request.headers.get("x-leek-app-env") if settings.LEEK_API_ENABLE_AUTH: get_claims() if len( settings.LEEK_API_WHITELISTED_ORGS ) and g.org_name not in settings.LEEK_API_WHITELISTED_ORGS: raise JWTError( f'Only {settings.LEEK_API_WHITELISTED_ORGS} are whitelisted to use this app' ) if allowed_org_names: if g.org_name not in allowed_org_names: raise JWTError( f'Only {allowed_org_names} org can access this endpoint' ) if only_app_owner: if not g.app_name: return responses.missing_headers try: app = get_app(f"{g.org_name}-{g.app_name}") if g.email != app.get("owner"): return responses.insufficient_permission except es_exceptions.NotFoundError: return responses.application_not_found except es_exceptions.ConnectionError: return responses.search_backend_unavailable else: g.org_name = "mono" g.index_alias = f"{g.org_name}-{g.app_name}" return route(*args, **kwargs)
def get(self): """ Check if application is ready to receive events """ try: org_name = request.headers["x-leek-org-name"] app_name = request.headers["x-leek-app-name"] app_key = request.headers["x-leek-app-key"] except KeyError as e: return responses.missing_headers try: # Get application app = get_app(f"{org_name}-{app_name}") # Authenticate if app_key not in [app["app_key"], settings.LEEK_AGENT_API_SECRET]: return responses.wrong_application_app_key except es_exceptions.NotFoundError: return responses.application_not_found except es_exceptions.ConnectionError: return responses.search_backend_unavailable return "Ready!", 200
def wrapper(*args, **kwargs): # Get headers try: org_name = request.headers["x-leek-org-name"] app_name = request.headers["x-leek-app-name"] app_env = request.headers["x-leek-app-env"] app_key = request.headers["x-leek-app-key"] except KeyError as e: return responses.missing_headers # Get app try: # Get/Build application app = get_app(f"{org_name}-{app_name}") fo_triggers = app.pop("fo_triggers") triggers = [FanoutTrigger(**t) for t in fo_triggers] application = Application(**app, fo_triggers=triggers) # Authenticate if app_key not in [ application.app_key, settings.LEEK_AGENT_API_SECRET ]: return responses.wrong_application_app_key except es_exceptions.NotFoundError: return responses.application_not_found except es_exceptions.ConnectionError: return responses.cache_backend_unavailable # Build context g.context = { "index_alias": f"{org_name}-{app_name}", "app": application, "org_name": org_name, "app_name": app_name, "app_env": app_env, "app_key": app_key, } return route(*args, **kwargs)