PlaidEx.Config.TenantRegistry (plaid_ex v1.0.0)

Copy Markdown View Source

ETS-backed registry for multi-tenant Plaid configurations.

Stores per-tenant PlaidEx.Config structs for runtime lookup. Supports secret rotation without application restart.

Usage

# Register a tenant at runtime (e.g., when a user connects Plaid)
PlaidEx.Config.TenantRegistry.register("acme_corp",
  PlaidEx.Config.new!(
    client_id: vault.get("acme/plaid/client_id"),
    secret: vault.get("acme/plaid/secret"),
    environment: :production,
    tenant_id: "acme_corp"
  )
)

# Retrieve tenant config for an API call
{:ok, config} = PlaidEx.Config.TenantRegistry.get("acme_corp")

# Rotate a secret without full re-registration
PlaidEx.Config.TenantRegistry.update_secret("acme_corp", new_secret)

# Remove a tenant (e.g., when they unsubscribe)
PlaidEx.Config.TenantRegistry.deregister("acme_corp")

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the number of registered tenants.

Removes a tenant from the registry.

Retrieves a tenant's configuration.

Retrieves a tenant config or raises if not found. Useful in pipelines where a missing tenant is a programming error.

Lists all registered tenant IDs.

Registers or updates a tenant configuration.

Rotates the secret for a tenant without full re-registration.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count()

@spec count() :: non_neg_integer()

Returns the number of registered tenants.

deregister(tenant_id)

@spec deregister(String.t()) :: :ok

Removes a tenant from the registry.

get(tenant_id)

@spec get(String.t()) :: {:ok, PlaidEx.Config.t()} | :not_found

Retrieves a tenant's configuration.

get!(tenant_id)

@spec get!(String.t()) :: PlaidEx.Config.t()

Retrieves a tenant config or raises if not found. Useful in pipelines where a missing tenant is a programming error.

list_tenants()

@spec list_tenants() :: [String.t()]

Lists all registered tenant IDs.

register(tenant_id, config)

@spec register(String.t(), PlaidEx.Config.t()) :: :ok

Registers or updates a tenant configuration.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

update_secret(tenant_id, new_secret)

@spec update_secret(String.t(), String.t()) :: :ok | :not_found

Rotates the secret for a tenant without full re-registration.