Draft — this article documents identity-service MRs !349, !354 and !360, dawiso-data-ingestion MRs !665 and !679, dawiso-backend MRs !6494 and !6536, and platform-dev-test MRs !776 and !794. Check structure, tone, and placement before publication.

With the PostgreSQL-based Dawiso Ingestion, a Dawiso instance receives ingestion events over a NATS broker instead of an HTTP webhook. The instance logs in to the broker with the same broker login it uses for user synchronization.

Requirements

  • The instance runs in the identity-service login mode. In any other login mode, the API answers 400 with the error INGESTION_REQUIRES_IDENTITY_SERVICE_MODE. The ingestion self-test reports a mismatch in modeConflict.
  • The instance can reach the broker at be.module.identity_service.settings.nats_url, and logs in with nats_credentials and nats_inbox_prefix from the same settings. These are the user-sync broker settings; there is no separate ingestion NATS address.
  • The broker user has rights on the instance’s own durable consumer dawiso-ingestion-{slug} on the stream INGESTION. Operations set these rights.

The instance reads ingestion events only when it is in the identity-service login mode or is connected to legacy ingestion. Otherwise the consumer stays idle.

The dawiso:ingest scope

The scope is not needed for the NATS connection. It covers ingestion REST and gRPC calls only.

When a super admin approves a Dawiso instance in identity-service, the instance’s client gets dawiso:ingest automatically. There is no separate grant step. Instances approved before this change received the scope from a one-time database migration.

The scope stays reserved. Tenant admins, join requests, and anonymous registration cannot request it, and no other client gets it. A refused request returns the code reserved_scope (This scope can only be granted by a super admin.).

A super admin can edit the scopes of the instance’s client. The edit replaces the whole list, so leaving dawiso:ingest out removes it. Add it back in the same edit. The ingestGranted check of the switch endpoint shows whether the scope is present.

The scope needs a tenant-bound client. The access token then carries tenant_id, tenant_slug, and dawiso-ingestion in aud. The aud claim is an array, so check that it contains dawiso-ingestion; do not compare it to a string.

Switch a tenant to NATS

An administrator switches one tenant at a time with these endpoints of the ingestion API. All three require an admin account. {tenantName} is the tenant name in Data Ingestion.

Method and pathPurpose
GET /api/admin/tenant/{tenantName}/switchRead the switch state and the readiness checks.
POST /api/admin/tenant/{tenantName}/switchSwitch the instance from the HTTP webhook to NATS.
POST /api/admin/tenant/{tenantName}/switch/revertSwitch the instance back to the HTTP webhook.

Pass identityTenantSlug as a query parameter when the identity-service tenant slug differs from the tenant’s default.

The response holds state (legacy, switching or switched), ready, and the checks identityTenant, ingestGranted, durableExists and migratedFromLegacyAt.

StatusMeaning
409 with the checksA readiness check fails. Fix the failing check and call again.
409 not_revertible_identity_bornThe tenant never used the legacy connection, so it cannot revert.
409 switch_not_configuredA required switch option is not configured. option names it.
503 ingestion_stream_missingThe ingestion stream does not exist on the broker.
400 invalid_slugThe identity tenant slug is not valid.

A revert is refused with 409 while migratedFromLegacyAt is false. For a tenant migrated earlier, run the migration tool with --backfill-migrated-at first.

Migration tool flags

The data migration tool of Data Ingestion has these flags for the switch.

FlagPurpose
--switchWith --flag: after the flip, write Migrated_From_Legacy_At and switch the instance to NATS. The tenant counts as done only when its state is switched.
--pg-admin-url <https url>Base URL of the PostgreSQL ingestion API. Required with --switch.
--identity-tenant-slug <slug>Identity-service tenant slug, when it differs from the default.
--identity-tenants-file <file>With --batch --switch: JSON such as {"ident":"identity-slug"} for tenants whose slug is not the default.
--switch-timeout-seconds <n>Bound for each switch call, 5 to 900 seconds. The default is 180. Keep it above the API’s Switch:AckWaitSeconds.
--backfill-migrated-atWrite the legacy Migrated_At into the tenant’s Migrated_From_Legacy_At. For tenants migrated before the switch existed. It never overwrites a different value.

Pass the administrator token in the DI_PG_ADMIN_TOKEN environment variable, never as an argument.

If a switch does not complete, the tenant stays frozen. Fix the cause that the checks list, then run --flag --resume --switch --pg-admin-url <url>. Resuming without --switch keeps the freeze and refuses.