Documentation
¶
Overview ¶
Package api implements the Dilion management-plane HTTP surface (/privacy/v1 and /iam/v1) with huma v2, following docs/api-conventions.md.
Every operation is guarded by the same pipeline: Bearer authentication (service_role JWT, scoped API key, or a user access token) → permission check → handler → audit event. Route registration itself never dereferences Deps, so the spec can be generated without a database (see cmd/openapi).
Index ¶
- Constants
- func ActorFrom(ctx context.Context) (ports.Actor, bool)
- func NewConfig() huma.Config
- func RegisterIAMAPI(api huma.API, d Deps)
- func RegisterPrivacyAPI(api huma.API, svcs ServiceProvider, d Deps)
- type APIKey
- type APIKeyPage
- type APIKeyWithToken
- type Actor
- type AudienceMember
- type AudiencePage
- type AuditEvent
- type AuditEventPage
- type ConsentState
- type ConsentStatePage
- type CreateAPIKeyBody
- type CreateDestinationBody
- type CreateLegalHoldBody
- type CreateMeRequestBody
- type CreatePermissionBody
- type CreatePrivacyRequestBody
- type CreateRoleAssignmentBody
- type CreateRoleBody
- type Deps
- type Destination
- type DestinationPage
- type ExportConsentAudienceBody
- type LegalHold
- type LegalHoldPage
- type Permission
- type PermissionHolder
- type PermissionHolderPage
- type PermissionPage
- type PoolFunc
- type PrivacyRequest
- type PrivacyRequestPage
- type Problem
- type Profile
- type ProfileBatch
- type ProfileField
- type ProfileFieldWrite
- type RevealUserProfileBody
- type Role
- type RoleAssignment
- type RoleAssignmentPage
- type RolePage
- type ServiceProvider
- type SubjectConsent
- type SubjectConsentPage
- type UpdateConsentBody
- type UpdateDestinationBody
- type UpdateMeConsentBody
- type UpdateRoleBody
- type UpdateUserProfileBody
- type UserMatch
- type UserMatchPage
Constants ¶
const ( APITitle = "Dilion Platform API" APIVersion = "0.1.0" DefaultURL = "http://localhost:8787" )
API metadata (docs/api-conventions.md consumers generate clients from this).
Variables ¶
This section is empty.
Functions ¶
func ActorFrom ¶
ActorFrom returns the authenticated actor for the current request. It is exported so embedders' custom handlers can reuse the same identity.
func NewConfig ¶
NewConfig returns the huma configuration for the Dilion platform API. Use it both for the running server and for `cmd/openapi` so the generated spec and the served API cannot drift.
func RegisterIAMAPI ¶
RegisterIAMAPI mounts /iam/v1 on the given huma API. Reads require `audit.read`; defining roles and permissions and granting roles require `roles.manage`; issuing and revoking API keys require `keys.manage`. Every grant is further capped at what the caller holds itself (grantCeiling).
func RegisterPrivacyAPI ¶
func RegisterPrivacyAPI(api huma.API, svcs ServiceProvider, d Deps)
RegisterPrivacyAPI mounts /privacy/v1 on the given huma API. svcs resolves the compliance service per request (see ServiceProvider), which is what makes one mounted API serve several instances. Registration performs no I/O and never dereferences Deps or svcs, so it is safe to call with a zero Deps and a nil provider to generate the OpenAPI document.
Types ¶
type APIKey ¶
type APIKey struct {
ID string `json:"id" example:"key_1f0c0b6a7d5e4a2b9c8d7e6f5a4b3c2d"`
Name *string `json:"name" nullable:"true"`
Scopes []string `json:"scopes" nullable:"false"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at" nullable:"true"`
RevokedAt *time.Time `json:"revoked_at" nullable:"true"`
LastUsedAt *time.Time `json:"last_used_at" nullable:"true"`
}
APIKey is a scoped machine credential. The plaintext token is never returned after creation.
type APIKeyPage ¶
type APIKeyWithToken ¶
type APIKeyWithToken struct {
APIKey
Token string `json:"token" example:"dk_..." doc:"Plaintext API key. Shown once — store it now."`
}
APIKeyWithToken is the creation response: the only time the plaintext token is available.
type Actor ¶ added in v0.0.5
type Actor struct {
ActorType string `` /* 189-byte string literal not displayed */
Active bool `json:"active" doc:"Whether the actor can still exercise the grant: not banned, deleted or revoked."`
CreatedAt *time.Time `json:"created_at" nullable:"true"`
LastSignInAt *time.Time `json:"last_sign_in_at" nullable:"true" doc:"Users only."`
BannedUntil *time.Time `json:"banned_until" nullable:"true" doc:"Users only."`
DeletedAt *time.Time `json:"deleted_at" nullable:"true" doc:"Users only."`
RevokedAt *time.Time `json:"revoked_at" nullable:"true" doc:"API keys only."`
}
Actor is the non-PII operational view of the actor a grant names, returned with `expand=actor`. It answers "can this actor still use the grant?" without a request per actor.
It deliberately carries NO personal data: no email, no name. The management plane does not inline personal data into unrelated reports, so a caller that needs to show who an operator is reads the masked profile surface, which is separately permissioned and separately audited.
type AudienceMember ¶
type AudienceMember struct {
UserID string `json:"user_id" format:"uuid"`
Email *string `json:"email" nullable:"true" doc:"Auth email, empty string if the account has none, null when not requested."`
Phone *string `json:"phone" nullable:"true" doc:"Auth phone, empty string if the account has none, null when not requested."`
}
AudienceMember is one export row. Fields that were not requested are null — data minimization applies to exports too.
type AudiencePage ¶
type AudiencePage struct {
Items []AudienceMember `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true"`
}
AudiencePage is the export envelope.
type AuditEvent ¶
type AuditEvent struct {
ID string `json:"id" example:"evt_1f0c0b6a7d5e4a2b9c8d7e6f5a4b3c2d"`
ActorID *string `json:"actor_id" nullable:"true" doc:"Operator or API key id, or null for system events."`
ActorType *string `json:"actor_type" nullable:"true" doc:"admin | api_key | service_role | user | system."`
Action string `json:"action" example:"PII_FULL_READ" doc:"Recorded action, UPPER_SNAKE_CASE."`
Resource *string `json:"resource" nullable:"true" doc:"Resource or route the action targeted."`
AccessLevel *string `json:"access_level" nullable:"true" doc:"masked | full | n/a."`
RequestID *string `json:"request_id" nullable:"true"`
ResultCount *int `json:"result_count" nullable:"true" doc:"Number of records the action touched."`
Reason *string `json:"reason" nullable:"true" doc:"Operator-supplied justification (PII reveal 사유), or null."`
IP *string `json:"ip" nullable:"true"`
UserAgent *string `json:"user_agent" nullable:"true"`
CreatedAt time.Time `json:"created_at"`
SubjectIDs []string `` /* 126-byte string literal not displayed */
}
AuditEvent is one recorded access event (§5.1: who, when, from where, with which access level, over which scope, doing what — never the personal data values themselves).
type AuditEventPage ¶
type AuditEventPage struct {
Items []AuditEvent `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true" doc:"Opaque cursor for the next page, or null."`
}
AuditEventPage is the cursor-paginated list envelope.
type ConsentState ¶
type ConsentState struct {
Purpose string `json:"purpose" doc:"Consent purpose key."`
Granted bool `json:"granted" doc:"Whether consent is currently granted."`
PolicyVersion string `json:"policy_version" doc:"Policy version the consent was recorded against."`
UpdatedAt time.Time `json:"updated_at"`
ReconfirmDue *time.Time `json:"reconfirm_due" nullable:"true" doc:"When re-confirmation notice is due, or null."`
}
ConsentState is the current projection of the consent ledger for one purpose.
type ConsentStatePage ¶
type ConsentStatePage struct {
Items []ConsentState `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true" doc:"Always null: consent state is returned in full."`
}
ConsentStatePage is the consent list envelope. Consents are not paginated today; next_cursor is always null.
type CreateAPIKeyBody ¶
type CreateAPIKeyBody struct {
Name *string `json:"name,omitempty" doc:"Human-readable label."`
Scopes []string `json:"scopes" nullable:"false" minItems:"1" doc:"Permissions this key may exercise (least privilege)."`
ExpiresAt *time.Time `json:"expires_at,omitempty" doc:"RFC 3339 expiry. Omit for a non-expiring key."`
}
type CreateDestinationBody ¶
type CreateDestinationBody struct {
Type string `json:"type" enum:"WEBHOOK,CONNECTOR"`
Name string `json:"name" minLength:"1"`
Config map[string]any `json:"config" doc:"Webhook: {url, identity_field}."`
Secret *string `json:"secret,omitempty" doc:"Webhook HMAC secret. Write-only, never returned."`
}
type CreateLegalHoldBody ¶
type CreateMeRequestBody ¶
type CreateMeRequestBody struct {
Type string `json:"type" enum:"DELETION,EXPORT,CONSENT_WITHDRAWAL" doc:"Request type."`
Immediate *bool `json:"immediate,omitempty" doc:"Skip the grace period (즉시 파기 요청, §2.9)."`
}
CreateMeRequestBody is the self-service DSR payload: the subject comes from the token, never from the body.
type CreatePermissionBody ¶
type CreatePermissionBody struct {
Name string `` /* 141-byte string literal not displayed */
}
type CreatePrivacyRequestBody ¶
type CreatePrivacyRequestBody struct {
UserID string `json:"user_id" format:"uuid" doc:"Canonical user id of the data subject."`
Type string `json:"type" enum:"DELETION,EXPORT,CONSENT_WITHDRAWAL" doc:"Request type."`
Immediate *bool `json:"immediate,omitempty" doc:"Skip the grace period and schedule erasure immediately."`
}
CreatePrivacyRequestBody is the POST /privacy/v1/requests payload.
type CreateRoleAssignmentBody ¶
type CreateRoleAssignmentBody struct {
ActorID string `json:"actor_id" minLength:"1" doc:"Operator or API key id receiving the role."`
}
type CreateRoleBody ¶
type Deps ¶
type Deps struct {
// Pool is the fixed database of a single-instance deployment. Registration
// never dereferences it, so a zero Deps describes every route.
Pool *pgxpool.Pool
// Pools resolves the database per request and takes precedence over Pool.
// Multi-instance deployments set it to instances.Registry.Pool.
Pools PoolFunc
Verifier ports.TokenVerifier
Authz ports.Authorizer
Audit ports.AuditSink
// DeletionReauthWindow is how recent a user's sign-in must be for them to
// request their own deletion through /privacy/v1/me/requests; 0 turns the
// recency check off (the session and MFA checks remain). The server fills
// it from auth's Security.DeletionReauthWindow.
DeletionReauthWindow time.Duration
// TrustedProxies are the proxies whose X-Forwarded-For is believed when
// recording a caller's address (netguard.ClientIP).
TrustedProxies netguard.Networks
// SessionLookup reads the assurance of a user token's session. nil means
// auth.LookupSessionAssurance on the request's database.
SessionLookup func(ctx context.Context, userID, sessionID string) (auth.SessionAssurance, error)
// AdminMFADisabled lets a user token act on the management plane without
// an aal2 session (dilion.WithoutAdminMFA). Development only.
AdminMFADisabled bool
}
Deps are the platform dependencies injected by dilion.go.
type Destination ¶
type Destination struct {
ID string `json:"id" example:"dst_1f0c0b6a7d5e4a2b9c8d7e6f5a4b3c2d"`
Type string `json:"type" enum:"WEBHOOK,CONNECTOR"`
Name string `json:"name"`
Config map[string]any `json:"config" doc:"Type specific configuration. Secrets are never returned."`
Enabled bool `json:"enabled"`
}
Destination is a downstream system that receives erasure instructions.
type DestinationPage ¶
type DestinationPage struct {
Items []Destination `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true"`
}
type ExportConsentAudienceBody ¶
type ExportConsentAudienceBody struct {
Purpose string `json:"purpose" minLength:"1" doc:"Consent purpose whose granted subjects form the audience."`
Fields []string `` /* 140-byte string literal not displayed */
Reason string `json:"reason" minLength:"1" maxLength:"500" doc:"Why the audience is being exported. Required and recorded in the audit log."`
Limit int `json:"limit,omitempty" minimum:"1" maximum:"1000" doc:"Page size (default 100)."`
Cursor *string `json:"cursor,omitempty" doc:"Opaque cursor from a previous response."`
}
ExportConsentAudienceBody selects the audience and carries the mandatory justification. Pagination lives in the body because the operation is a POST.
type LegalHold ¶
type LegalHold struct {
ID string `json:"id" example:"hold_1f0c0b6a7d5e4a2b9c8d7e6f5a4b3c2d"`
UserID string `json:"user_id" format:"uuid"`
Domain *string `json:"domain" nullable:"true" doc:"Data domain held, or null for the whole subject."`
Reason string `json:"reason"`
Basis string `json:"basis" doc:"Legal basis for the hold."`
CreatedAt time.Time `json:"created_at"`
ReleasedAt *time.Time `json:"released_at" nullable:"true"`
}
LegalHold blocks erasure for a subject (or one domain of a subject).
type LegalHoldPage ¶
type Permission ¶
type Permission struct {
Name string `json:"name" example:"myapp.orders.refund"`
Builtin bool `json:"builtin"`
CreatedAt time.Time `json:"created_at"`
}
Permission is a flat permission string registered in the project.
type PermissionHolder ¶
type PermissionHolder struct {
ActorID string `json:"actor_id"`
RoleID string `json:"role_id"`
RoleName string `json:"role_name"`
GrantedBy *string `json:"granted_by" nullable:"true"`
GrantedAt time.Time `json:"granted_at"`
Actor *Actor `json:"actor,omitempty" doc:"Operational view of the actor; present only with expand=actor."`
}
PermissionHolder is one row of the CC6.3 recertification report.
type PermissionHolderPage ¶
type PermissionHolderPage struct {
Items []PermissionHolder `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true" doc:"Always null: recertification returns the full set."`
}
type PermissionPage ¶
type PermissionPage struct {
Items []Permission `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true"`
}
type PoolFunc ¶
PoolFunc resolves the database pool for a request: in a multi-instance deployment the database of the instance selected on the context (ports.ContextWithInstance, internal/instances), otherwise the one configured pool. Structurally identical to instances.PoolFunc.
type PrivacyRequest ¶
type PrivacyRequest struct {
ID string `json:"id" example:"pr_1f0c0b6a7d5e4a2b9c8d7e6f5a4b3c2d" doc:"Request identifier."`
UserID string `json:"user_id" format:"uuid" doc:"Canonical user id of the data subject."`
Type string `json:"type" enum:"DELETION,EXPORT,CONSENT_WITHDRAWAL" doc:"Request type."`
Status string `json:"status" enum:"REQUESTED,PROCESSING,DONE,MANUAL_REVIEW,CANCELED" doc:"Lifecycle status."`
PolicyID string `json:"policy_id" doc:"Compliance policy snapshot applied to this request."`
ScheduledAt time.Time `json:"scheduled_at" doc:"When the erasure pipeline is due to run (grace deadline)."`
RequestedAt time.Time `json:"requested_at" doc:"When the request was accepted."`
CompletedAt *time.Time `json:"completed_at" nullable:"true" doc:"When processing finished, or null."`
}
PrivacyRequest is a data subject request (DSR).
type PrivacyRequestPage ¶
type PrivacyRequestPage struct {
Items []PrivacyRequest `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true" doc:"Opaque cursor for the next page, or null."`
}
PrivacyRequestPage is the cursor-paginated list envelope.
type Problem ¶
type Problem struct {
Type string `json:"type,omitempty" format:"uri" doc:"URI reference to documentation for this error type."`
Title string `json:"title,omitempty" doc:"Short, human-readable summary of the problem type."`
Status int `json:"status,omitempty" doc:"HTTP status code."`
Detail string `json:"detail,omitempty" doc:"Human-readable explanation specific to this occurrence."`
Instance string `json:"instance,omitempty" format:"uri" doc:"URI reference identifying this specific occurrence."`
Code string `` /* 243-byte string literal not displayed */
Errors []*huma.ErrorDetail `json:"errors,omitempty" nullable:"false" doc:"Optional list of individual error details."`
}
Problem is the RFC 9457 problem details body returned by every /privacy/v1 and /iam/v1 endpoint. It is huma's ErrorModel plus the `code` extension that frontends branch on.
func NewProblem ¶
NewProblem builds a problem with an explicit machine-readable code.
func (*Problem) ContentType ¶
ContentType satisfies huma.ContentTypeFilter so errors are served as application/problem+json.
type Profile ¶
type Profile struct {
UserID string `json:"user_id" format:"uuid" doc:"Canonical user id of the data subject."`
Fields map[string]ProfileField `json:"fields" nullable:"false" doc:"PII fields keyed by field name."`
View string `json:"view" enum:"MASKED,FULL" doc:"MASKED = hint-based projection, FULL = original values."`
UpdatedAt *time.Time `json:"updated_at" nullable:"true" doc:"When the profile was last written, or null."`
}
Profile is a data subject's PII profile. Custom field keys are supported, so `fields` is an open key→field map.
type ProfileBatch ¶ added in v0.0.5
type ProfileBatch struct {
Items []Profile `json:"items" nullable:"false" doc:"Masked profiles, in the order the ids were given."`
Missing []string `json:"missing" nullable:"false" doc:"Requested ids with no stored profile."`
}
ProfileBatch is the batch response. Subjects with no stored profile are named in Missing rather than omitted silently, so a caller can tell "no profile" apart from "id you did not ask about".
type ProfileField ¶
type ProfileField struct {
Value string `json:"value" doc:"Field value: masked projection or original, depending on the profile view."`
Hint string `json:"hint" enum:"EMAIL,NAME,PHONE,ADDRESS,GENERIC" doc:"Masking hint that decides how the value is projected when masked."`
}
ProfileField is one PII field of a subject's profile. In a MASKED profile the value is the hint-based projection (§2.6); in a FULL profile it is the original.
type ProfileFieldWrite ¶
type ProfileFieldWrite struct {
Value string `json:"value" doc:"Field value (the original, never a masked projection)."`
Hint *string `` /* 203-byte string literal not displayed */
}
ProfileFieldWrite is one field of a profile write. Unlike the response ProfileField the masking hint is optional: an instance may pin its PII field definitions (ports.InstanceResolver.PIIFields), in which case the hint is taken from the definition and may be omitted — supplying a different one is rejected. Instances without definitions keep free-form fields, where the hint is required.
type RevealUserProfileBody ¶
type RevealUserProfileBody struct {
Reason string `` /* 131-byte string literal not displayed */
}
RevealUserProfileBody carries the mandatory justification for an unmasked read. The reason is stored on the PII_FULL_READ audit event (§5.2).
type Role ¶
type Role struct {
ID string `json:"id" example:"role_1f0c0b6a7d5e4a2b9c8d7e6f5a4b3c2d"`
Name string `json:"name"`
Permissions []string `json:"permissions" nullable:"false"`
Builtin bool `json:"builtin" doc:"Builtin roles are seeded by Dilion and cannot be redefined."`
CreatedAt time.Time `json:"created_at"`
}
Role is a bundle of permissions (§2.11).
type RoleAssignment ¶
type RoleAssignment struct {
ID int64 `json:"id"`
ActorID string `json:"actor_id"`
RoleID string `json:"role_id"`
GrantedBy *string `json:"granted_by" nullable:"true"`
GrantedAt time.Time `json:"granted_at"`
RevokedBy *string `json:"revoked_by" nullable:"true"`
RevokedAt *time.Time `json:"revoked_at" nullable:"true"`
Actor *Actor `json:"actor,omitempty" doc:"Operational view of the actor; present only with expand=actor."`
}
RoleAssignment is one grant in the history-preserving assignment ledger.
type RoleAssignmentPage ¶
type RoleAssignmentPage struct {
Items []RoleAssignment `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true"`
}
type ServiceProvider ¶
ServiceProvider resolves the compliance service for a request. In a multi-instance deployment it returns the engine of the instance selected on the context (instances.Registry.PrivacyService); single-instance deployments use StaticService. A nil provider (spec generation) yields a 500 at call time and never at registration time.
func StaticService ¶
func StaticService(svc privacy.Service) ServiceProvider
StaticService is the single-instance ServiceProvider over one fixed engine.
type SubjectConsent ¶
type SubjectConsent struct {
UserID string `json:"user_id" format:"uuid" doc:"Canonical user id of the data subject."`
Purpose string `json:"purpose" doc:"Consent purpose key."`
Granted bool `json:"granted" doc:"Whether consent is currently granted."`
PolicyVersion string `json:"policy_version" doc:"Policy version the consent was recorded against."`
UpdatedAt time.Time `json:"updated_at"`
ReconfirmDue *time.Time `json:"reconfirm_due" nullable:"true" doc:"When re-confirmation notice is due, or null."`
}
SubjectConsent is the current consent state of one purpose for one subject (the cross-user counterpart of ConsentState).
type SubjectConsentPage ¶
type SubjectConsentPage struct {
Items []SubjectConsent `json:"items" nullable:"false"`
NextCursor *string `` /* 146-byte string literal not displayed */
}
SubjectConsentPage is the cursor-paginated segment envelope.
type UpdateConsentBody ¶
type UpdateConsentBody struct {
Purpose string `` /* 126-byte string literal not displayed */
Granted bool `json:"granted" doc:"true = grant, false = withdraw."`
PolicyVersion string `json:"policy_version" minLength:"1" maxLength:"64" doc:"Policy version presented to the subject."`
Source string `json:"source" enum:"UI,API,IMPORT" default:"API" doc:"Where the change originated."`
}
UpdateConsentBody appends one entry to the consent ledger.
type UpdateDestinationBody ¶
type UpdateMeConsentBody ¶
type UpdateMeConsentBody struct {
Purpose string `` /* 126-byte string literal not displayed */
Granted bool `json:"granted" doc:"true = grant, false = withdraw."`
PolicyVersion string `json:"policy_version" minLength:"1" maxLength:"64" doc:"Policy version presented to the subject."`
}
UpdateMeConsentBody appends one ledger entry for the token's subject. Source is fixed to UI: a self-service change is by definition the subject acting.
type UpdateRoleBody ¶ added in v0.0.5
type UpdateRoleBody struct {
Permissions []string `` /* 178-byte string literal not displayed */
}
type UpdateUserProfileBody ¶
type UpdateUserProfileBody struct {
Set map[string]ProfileFieldWrite `json:"set,omitempty" doc:"Fields to upsert, keyed by field name."`
Remove []string `json:"remove,omitempty" doc:"Field names to delete."`
}
UpdateUserProfileBody is a partial write: `set` upserts fields, `remove` deletes them. At least one of the two must be present.
type UserMatch ¶
type UserMatch struct {
UserID string `json:"user_id" format:"uuid" doc:"Canonical user id of the matched subject."`
Source string `json:"source" enum:"AUTH_EMAIL,AUTH_PHONE,PROFILE_FIELD" doc:"Which identifier matched."`
FieldKey *string `json:"field_key" nullable:"true" doc:"The vault field that matched, or null for auth identifiers."`
}
UserMatch is one search hit: which subject matched and through which identifier. Field values are never returned — follow up with the masked profile, or a privileged reveal, as a separate audited read.
type UserMatchPage ¶
type UserMatchPage struct {
Items []UserMatch `json:"items" nullable:"false"`
NextCursor *string `json:"next_cursor" nullable:"true" doc:"Opaque cursor for the next page, or null."`
}
UserMatchPage is the cursor-paginated search envelope.