mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 12:26:19 +02:00
add callback for saas app
This commit is contained in:
@@ -64,7 +64,7 @@ def create_app() -> FastAPI:
|
|||||||
|
|
||||||
# TODO: why those 2?
|
# TODO: why those 2?
|
||||||
g().config = settings
|
g().config = settings
|
||||||
# g().base_url = f"http://{settings.host}:{settings.port}"
|
g().base_url = f"http://{settings.host}:{settings.port}"
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||||
|
|
||||||
|
@@ -6,6 +6,9 @@ async def m001_create_admin_settings_table(db):
|
|||||||
debug TEXT,
|
debug TEXT,
|
||||||
host TEXT,
|
host TEXT,
|
||||||
port INTEGER,
|
port INTEGER,
|
||||||
|
lnbits_saas_instance_id TEXT,
|
||||||
|
lnbits_saas_callback TEXT,
|
||||||
|
lnbits_saas_secret TEXT,
|
||||||
lnbits_path TEXT,
|
lnbits_path TEXT,
|
||||||
lnbits_commit TEXT,
|
lnbits_commit TEXT,
|
||||||
lnbits_admin_users TEXT,
|
lnbits_admin_users TEXT,
|
||||||
|
@@ -53,8 +53,3 @@ async def api_delete_settings(
|
|||||||
):
|
):
|
||||||
await delete_settings()
|
await delete_settings()
|
||||||
return {"status": "Success"}
|
return {"status": "Success"}
|
||||||
|
|
||||||
|
|
||||||
@admin_ext.get("/api/v1/backup/", status_code=HTTPStatus.OK)
|
|
||||||
async def api_backup(user: User = Depends(check_admin)):
|
|
||||||
return {"status": "not implemented"}
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import importlib
|
import importlib
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import httpx
|
||||||
from os import path
|
from os import path
|
||||||
from sqlite3 import Row
|
from sqlite3 import Row
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
@@ -9,6 +10,7 @@ from loguru import logger
|
|||||||
from pydantic import BaseSettings, Field, validator
|
from pydantic import BaseSettings, Field, validator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def list_parse_fallback(v):
|
def list_parse_fallback(v):
|
||||||
try:
|
try:
|
||||||
return json.loads(v)
|
return json.loads(v)
|
||||||
@@ -34,6 +36,11 @@ class Settings(BaseSettings):
|
|||||||
lnbits_path: str = Field(default=".")
|
lnbits_path: str = Field(default=".")
|
||||||
lnbits_commit: str = Field(default="unknown")
|
lnbits_commit: str = Field(default="unknown")
|
||||||
|
|
||||||
|
# saas
|
||||||
|
lnbits_saas_callback: Optional[str] = Field(default=None)
|
||||||
|
lnbits_saas_secret: Optional[str] = Field(default=None)
|
||||||
|
lnbits_saas_instance_id: Optional[str] = Field(default=None)
|
||||||
|
|
||||||
# users
|
# users
|
||||||
lnbits_admin_users: List[str] = Field(default=[])
|
lnbits_admin_users: List[str] = Field(default=[])
|
||||||
lnbits_allowed_users: List[str] = Field(default=[])
|
lnbits_allowed_users: List[str] = Field(default=[])
|
||||||
@@ -230,11 +237,28 @@ async def check_admin_settings():
|
|||||||
|
|
||||||
http = "https" if settings.lnbits_force_https else "http"
|
http = "https" if settings.lnbits_force_https else "http"
|
||||||
user = settings.lnbits_admin_users[0]
|
user = settings.lnbits_admin_users[0]
|
||||||
logger.warning(
|
|
||||||
f" ✔️ Access admin user account at: {http}://{settings.host}:{settings.port}/wallet?usr={user}"
|
admin_url = f"{http}://{settings.host}:{settings.port}/wallet?usr={user}"
|
||||||
)
|
logger.warning(f"✔️ Access admin user account at: {admin_url}")
|
||||||
|
|
||||||
|
if settings.lnbits_saas_callback and settings.lnbits_saas_secret and settings.lnbits_saas_instance_id:
|
||||||
|
with httpx.Client() as client:
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
|
"X-API-KEY": settings.lnbits_saas_secret
|
||||||
|
}
|
||||||
|
payload = {
|
||||||
|
"instance_id": settings.lnbits_saas_instance_id,
|
||||||
|
"adminuser": user
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
r = client.post(settings.lnbits_saas_callback, headers=headers, json=payload)
|
||||||
|
logger.warning("sent admin user to saas application")
|
||||||
except:
|
except:
|
||||||
logger.warning("admin.settings tables does not exist.")
|
logger.error(f"error sending admin user to saas: {settings.lnbits_saas_callback}")
|
||||||
|
|
||||||
|
except:
|
||||||
|
logger.error("admin.settings tables does not exist.")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user