ports

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ports defines the shared interfaces (contracts) between Dilion domains and embedder-injectable components. Do not add domain logic here.

Index

Constants

View Source
const DefaultInstanceID = "default"

DefaultInstanceID is the sole instance of the built-in daemon and examples. Multi-instance is an embedder customization, not a default-daemon feature.

Variables

This section is empty.

Functions

func ContextWithInstance

func ContextWithInstance(ctx context.Context, instanceID string) context.Context

ContextWithInstance selects the instance for downstream Dilion calls.

func InstanceFromContext

func InstanceFromContext(ctx context.Context) string

InstanceFromContext returns the selected instance, or DefaultInstanceID.

Types

type Actor

type Actor struct {
	ID        string
	Type      string // admin | api_key | service_role | user
	ProjectID string
}

type AuditEvent

type AuditEvent struct {
	ProjectID   string
	ActorID     string
	ActorType   string // admin | api_key | service_role | user | system
	Action      string // e.g. USER_LIST_READ, PII_FULL_READ, ROLE_GRANTED
	Resource    string
	AccessLevel string // masked | full | n/a
	RequestID   string
	ResultCount int
	SubjectIDs  []string // written to dilion_audit.subjects (manifest)
	Reason      string   // operator-supplied justification (PII reveal 등); optional
	IP          string
	UserAgent   string
	OccurredAt  time.Time
}

type AuditSink

type AuditSink interface {
	Append(ctx context.Context, e AuditEvent) error
}

type Authorizer

type Authorizer interface {
	Can(ctx context.Context, actor Actor, permission string, resource string) (bool, error)
}

Authorizer decides only; audit logging and masked-by-default behavior are enforced by callers regardless of the implementation.

type Claims

type Claims struct {
	Subject   string // canonical user_id (UUID) or actor id
	Role      string // anon | authenticated | service_role
	Email     string
	Audience  string
	ExpiresAt time.Time
	Extra     map[string]any // custom claims injected via TokenClaims hook
}

type Clock

type Clock interface {
	Now() time.Time
}

type Connector

type Connector interface {
	Execute(ctx context.Context, t ConnectorTask) (ConnectorReceipt, error)
}

type ConnectorReceipt

type ConnectorReceipt struct {
	TaskID      string
	Status      string // completed | failed
	ResultCode  string
	Detail      string
	CompletedAt time.Time
}

type ConnectorTask

type ConnectorTask struct {
	TaskID        string
	RequestID     string
	UserID        string
	DestinationID string
	Action        string // DELETE | ANONYMIZE | EXPORT
	Config        map[string]any
}

type HookFunc

type HookFunc func(ctx context.Context, payload map[string]any) (map[string]any, error)

HookFunc receives a mutable payload. Validating hooks reject by returning an error; mutating hooks return a replacement payload (nil = unchanged).

type HookPoint

type HookPoint string
const (
	BeforeSignup      HookPoint = "before_signup"       // validating (may reject)
	AfterSignup       HookPoint = "after_signup"        // observing
	TokenClaims       HookPoint = "token_claims"        // mutating (adds Claims.Extra)
	BeforeUserDelete  HookPoint = "before_user_delete"  // validating
	AfterUserDelete   HookPoint = "after_user_delete"   // observing
	BeforeErasureStep HookPoint = "before_erasure_step" // validating
	AfterErasure      HookPoint = "after_erasure"       // observing
	ConsentChanged    HookPoint = "consent_changed"     // observing
	ConsentReconfirm  HookPoint = "consent_reconfirm"   // observing (확인 고지 이벤트)
	PIIReveal         HookPoint = "pii_reveal"          // validating
)

type InstanceResolver

type InstanceResolver interface {
	Pool(ctx context.Context, instanceID string) (*pgxpool.Pool, error)
	KMS(ctx context.Context, instanceID string) (KMS, error)
	// PolicyYAML returns the instance's compliance policy document
	// (project.md §2.8). nil = built-in defaults only.
	PolicyYAML(ctx context.Context, instanceID string) ([]byte, error)
	// PIIFields returns the instance's fixed PII field definitions (YAML:
	// pii-fields: {<key>: {hint: NAME|EMAIL|PHONE|ADDRESS|GENERIC}}).
	// Writes of undefined keys are rejected and the stored hint always comes
	// from the definition. nil = free-form fields (single-instance default).
	PIIFields(ctx context.Context, instanceID string) ([]byte, error)
	// List enumerates known instance ids (background worker scheduling).
	List(ctx context.Context) ([]string, error)
}

InstanceResolver provides per-instance resources dynamically. Each instance is a fully isolated database (auth.* + dilion_*), larger in scope than a tenant/project. The built-in daemon uses a single static instance; embedders inject their own resolver via dilion.WithInstanceResolver and select the instance per request with ContextWithInstance. There is NO built-in HTTP routing or token↔instance binding — how an instance is chosen for a request, and how credentials are bound to instances, is the embedder's responsibility.

Results for the same instanceID should be stable; Dilion may cache per-instance resources (engines, workers) keyed by instanceID.

type KMS

type KMS interface {
	Encrypt(ctx context.Context, subjectID string, scope KeyScope, plaintext []byte) ([]byte, error)
	Decrypt(ctx context.Context, subjectID string, scope KeyScope, ciphertext []byte) ([]byte, error)
	// DestroyDEK irreversibly destroys the subject-scoped DEK (crypto-shred).
	// Decrypt must fail afterwards. Idempotent.
	DestroyDEK(ctx context.Context, subjectID string, scope KeyScope) error
}

type KeyScope

type KeyScope string
const (
	KeyScopeDefault KeyScope = "DEFAULT" // general PII — shredded immediately on erasure
	KeyScopeConsent KeyScope = "CONSENT" // consent evidence — shredded at shred_after
)

type Mailer

type Mailer interface {
	Send(ctx context.Context, to, subject, textBody, htmlBody string) error
}

type SMSSender

type SMSSender interface {
	Send(ctx context.Context, to, body string) error
}

type SystemClock

type SystemClock struct{}

func (SystemClock) Now

func (SystemClock) Now() time.Time

type TokenSigner

type TokenSigner interface {
	Sign(ctx context.Context, c Claims) (string, error)
}

type TokenVerifier

type TokenVerifier interface {
	Verify(ctx context.Context, token string) (*Claims, error)
}

Jump to

Keyboard shortcuts

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