2025-12-23 11:14:24 +01:00
|
|
|
from argparse import Namespace
|
2025-12-23 11:36:20 +01:00
|
|
|
|
2025-12-23 12:21:13 +01:00
|
|
|
from .api_tokens import create_app_token_via_session
|
2025-12-23 11:14:24 +01:00
|
|
|
from .health import assert_matomo_ready
|
|
|
|
|
from .http import HttpClient
|
|
|
|
|
from .install.web_installer import ensure_installed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_bootstrap(args: Namespace) -> str:
|
2025-12-23 11:36:20 +01:00
|
|
|
# 1) Ensure Matomo is installed (NO-OP if already installed)
|
2025-12-23 11:14:24 +01:00
|
|
|
ensure_installed(
|
|
|
|
|
base_url=args.base_url,
|
|
|
|
|
admin_user=args.admin_user,
|
|
|
|
|
admin_password=args.admin_password,
|
|
|
|
|
admin_email=args.admin_email,
|
|
|
|
|
debug=args.debug,
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-23 11:36:20 +01:00
|
|
|
# 2) Now the UI/API should be reachable and "installed"
|
|
|
|
|
assert_matomo_ready(args.base_url, timeout=args.timeout)
|
|
|
|
|
|
2025-12-23 12:21:13 +01:00
|
|
|
# 3) Create app-specific token via authenticated session (cookie-based)
|
2025-12-23 11:14:24 +01:00
|
|
|
client = HttpClient(
|
|
|
|
|
base_url=args.base_url,
|
|
|
|
|
timeout=args.timeout,
|
|
|
|
|
debug=args.debug,
|
|
|
|
|
)
|
|
|
|
|
|
2025-12-23 12:21:13 +01:00
|
|
|
token = create_app_token_via_session(
|
2025-12-23 11:36:20 +01:00
|
|
|
client=client,
|
|
|
|
|
admin_user=args.admin_user,
|
|
|
|
|
admin_password=args.admin_password,
|
2025-12-23 11:14:24 +01:00
|
|
|
description=args.token_description,
|
2025-12-23 12:21:13 +01:00
|
|
|
debug=args.debug,
|
2025-12-23 11:14:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return token
|