identityimport

package
v4.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package identityimport copies Control's legacy identity data (v2_user identity columns and v2_user_mfa) into the identity module with IdentityService.ImportAccounts. The kernel drives it: batches are checkpointed in v4_kernel_identity_authority so an interrupted import resumes, and a delta import re-sends what changed since the previous one: users or their MFA row updated since, and deletions (linked users whose v2_user row is gone), which every import finishes with. Identity never reads v2_user.password itself. Invite codes stay with Control: registration consumes them through KernelIdentity.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRunning        = errors.New("an identity import is already running")
	ErrNotImportable  = errors.New("identity is authoritative: importing would overwrite its accounts")
	ErrNoFullImport   = errors.New("a delta import needs a completed full import")
	ErrNotInitialized = errors.New("the identity importer is not configured")
)

Errors of Run.

Functions

func AccountUUID

func AccountUUID(userID uint) string

AccountUUID is the account UUID of a legacy user without a link yet.

func SetDefault

func SetDefault(runner *Runner, db *gorm.DB)

SetDefault installs the server's runner and database for the admin API.

Types

type Checkpoint

type Checkpoint struct {
	ImportID string `json:"import_id"`
	Delta    bool   `json:"delta"`
	// UserCursor is the last user id sent.
	UserCursor uint `json:"user_cursor"`
	UsersDone  bool `json:"users_done"`
	// DeletionsDone is set once identity deleted every account whose
	// subscriber is gone.
	DeletionsDone bool `json:"deletions_done"`
	// Since is the lower bound of a delta import: the start of the
	// previous completed import.
	Since       int64  `json:"since"`
	StartedAt   int64  `json:"started_at"`
	CompletedAt int64  `json:"completed_at"`
	Accounts    uint64 `json:"accounts"`
	Deleted     uint64 `json:"deleted"`
	LastError   string `json:"last_error,omitempty"`
}

Checkpoint is the import progress stored in the authority row.

func Status

func Status(ctx context.Context, db *gorm.DB) (string, Checkpoint, error)

Status returns the authority state and the import progress.

type Importer

type Importer struct {
	DB      *gorm.DB
	Connect func() (grpc.ClientConnInterface, error)
	// BatchSize defaults to 500.
	BatchSize int
	// Now defaults to time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Importer runs imports, one at a time.

func (*Importer) Run

func (i *Importer) Run(ctx context.Context, delta bool) (Checkpoint, error)

Run imports everything (delta false) or what changed since the previous completed import (delta true). An unfinished import of the same kind resumes from its checkpoint. The authority state becomes importing; the cutover, not the import, hands authority to identity.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner runs imports in the background for the server's lifetime.

func Default

func Default() (*Runner, *gorm.DB)

Default returns the installed runner (nil without package hosts) and database.

func NewRunner

func NewRunner(importer *Importer, logf func(string, ...any)) *Runner

NewRunner returns a runner; call Serve.

func (*Runner) Serve

func (r *Runner) Serve(ctx context.Context)

Serve runs requested imports until ctx ends.

func (*Runner) Start

func (r *Runner) Start(delta bool) error

Start requests an import; it fails with ErrRunning while one runs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL