"""CLI helper: pull current SF jobs + users into identity_persons. Credentials come from the ``successfactors`` platform_config row, same as the webapp. Configure them once in the admin UI (or directly in the DB) and this script will pick them up — no CLI args for secrets, no env vars. """ from __future__ import annotations import argparse import asyncio import app.auth.models # noqa: F401 from app.core.database import async_session_factory from app.identity.successfactors_client import SuccessFactorsClient from app.identity.successfactors_sync import SuccessFactorsSyncService async def _main() -> None: parser = argparse.ArgumentParser( description="Sync SuccessFactors users and primary departments into Helix.", ) parser.add_argument( "--limit", type=int, default=None, help="Maximum number of current EmpJob rows to import. Omit for full sync.", ) args = parser.parse_args() async with async_session_factory() as session: client = await SuccessFactorsClient.from_config(session=session) service = SuccessFactorsSyncService(session, sf_client=client) summary = await service.sync_users(limit=args.limit) await session.commit() print(f"fetched_jobs={summary.fetched_jobs}") print(f"fetched_users={summary.fetched_users}") print(f"upserted_org_nodes={summary.upserted_org_nodes}") print(f"upserted_people={summary.upserted_people}") print(f"upserted_memberships={summary.upserted_memberships}") if __name__ == "__main__": asyncio.run(_main())