Documentation
¶
Index ¶
- Constants
- Variables
- type ConsentEngineOperation
- type ConsentErrorCode
- type ConsentField
- type ConsentPortalAction
- type ConsentPortalActionRequest
- type ConsentRecord
- type ConsentRequirement
- type ConsentResponseInternalView
- type ConsentResponsePortalView
- type ConsentStatus
- type ConsentSummaryView
- type ConsentType
- type CreateConsentRequest
- type GrantDuration
- type ListConsentsResponse
- type OwnerType
- type UpdateByMessage
Constants ¶
const ( DefaultPendingTimeoutRealtimeDuration = "PT1H" // 1 hour for realtime consent DefaultPendingTimeoutOfflineDuration = "P1D" // 1 day for offline consent )
DefaultPendingTimeoutDuration represents the default duration for pending status expiry based on consent type. Pending consents will expire after this duration if not approved or rejected Format: ISO 8601 duration (e.g., "P1D" for 1 day, "PT24H" for 24 hours)
const ( DefaultConsentListLimit = 20 MaxConsentListLimit = 100 )
Pagination bounds for listing an owner's consents in the portal
Variables ¶
var ( ErrConsentNotFound = errors.New("consent record not found") ErrConsentCreateFailed = errors.New("failed to create consent record") ErrConsentUpdateFailed = errors.New("failed to update consent record") ErrConsentGetFailed = errors.New("failed to get consent records") ErrConsentExpiryFailed = errors.New("failed to check consent expiry") ErrPortalRequestFailed = errors.New("failed to process consent portal request") ErrConsentNotPending = errors.New("consent is not pending") ErrConsentNotRevocable = errors.New("consent is not approved and cannot be revoked") ErrConsentAccessDenied = errors.New("consent belongs to a different owner") )
Sentinel errors for consent operations These errors can be checked using errors.Is()
Functions ¶
This section is empty.
Types ¶
type ConsentEngineOperation ¶
type ConsentEngineOperation string
ConsentEngineOperation represents the operation
const ( OpCreateConsent ConsentEngineOperation = "create consent" OpUpdateConsent ConsentEngineOperation = "update consent" OpRevokeConsent ConsentEngineOperation = "revoke consent" OpGetConsentStatus ConsentEngineOperation = "get consent status" OpGetConsentsByOwner ConsentEngineOperation = "get consents by data owner" OpGetConsentsByConsumer ConsentEngineOperation = "get consents by consumer" OpCheckConsentExpiry ConsentEngineOperation = "check consent expiry" OpProcessPortalRequest ConsentEngineOperation = "process consent portal" )
ConsentEngineOperation constants
type ConsentErrorCode ¶
type ConsentErrorCode string
ConsentErrorCode represents an error code
const ( ErrorCodeConsentNotFound ConsentErrorCode = "CONSENT_NOT_FOUND" ErrorCodeInternalError ConsentErrorCode = "INTERNAL_ERROR" ErrorCodeBadRequest ConsentErrorCode = "BAD_REQUEST" ErrorCodeForbidden ConsentErrorCode = "FORBIDDEN" ErrorCodeMethodNotAllowed ConsentErrorCode = "METHOD_NOT_ALLOWED" ErrorCodeConsentNotPending ConsentErrorCode = "CONSENT_NOT_PENDING" ErrorCodeConsentNotRevocable ConsentErrorCode = "CONSENT_NOT_REVOCABLE" )
ConsentErrorCode constants
type ConsentField ¶
type ConsentField struct {
FieldName string `json:"fieldName"`
SchemaID string `json:"schemaId"`
DisplayName *string `json:"displayName,omitempty"`
Description *string `json:"description,omitempty"`
Owner OwnerType `json:"owner"`
}
ConsentField represents a field that requires consent Matches PolicyDecisionResponseFieldRecord DTO structure from PolicyDecisionPoint
func (ConsentField) Equals ¶
func (a ConsentField) Equals(b ConsentField) bool
Equals checks if two ConsentField instances are equal
type ConsentPortalAction ¶
type ConsentPortalAction string
ConsentPortalAction represents the action taken in the consent portal
const ( ActionApprove ConsentPortalAction = "approve" ActionReject ConsentPortalAction = "reject" ActionRevoke ConsentPortalAction = "revoke" )
ConsentPortalAction constants
type ConsentPortalActionRequest ¶
type ConsentPortalActionRequest struct {
ConsentID string `json:"consentId"`
OwnerID string `json:"ownerId"` // Subject of the caller; must match the consent's owner
Action ConsentPortalAction `json:"action"` // "approve", "reject" or "revoke"
UpdatedBy string `json:"updatedBy"`
}
ConsentPortalActionRequest defines the structure for consent portal interactions
type ConsentRecord ¶
type ConsentRecord struct {
// ConsentID is the unique identifier for the consent record
ConsentID uuid.UUID `gorm:"column:consent_id;type:uuid;primaryKey;default:gen_random_uuid()" json:"consent_id"`
// OwnerID is the single canonical identifier (UID) for the data owner.
// The whole system relies on this UID to identify a user; a token claim
// (configurable) is matched against it during portal authorization.
// Part of conditional unique constraint for active consents (pending/approved)
OwnerID string `` /* 222-byte string literal not displayed */
// AppID is the unique identifier for the consumer application
// Part of conditional unique constraint for active consents (pending/approved)
AppID string `` /* 216-byte string literal not displayed */
// AppName is the name of the consumer application
AppName *string `gorm:"column:app_name;type:varchar(255);" json:"app_name,omitempty"`
// Status is the status of the consent record: pending, approved, rejected, expired, revoked
// Filters the conditional unique constraint (via its WHERE clause) but is
// deliberately NOT part of the index key, so a single (owner_id, app_id) can
// have at most one active (pending OR approved) consent.
Status string `gorm:"column:status;type:varchar(50);not null;index:idx_consent_records_status" json:"status"`
// Type is the type of consent mechanism "realtime" or "offline"
Type string `gorm:"column:type;type:varchar(50);not null" json:"type"`
// CreatedAt is the timestamp when the consent record was created
// Used to determine the most recent active consent
CreatedAt time.Time `` /* 144-byte string literal not displayed */
// UpdatedAt is the timestamp when the consent record was last updated
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
// PendingExpiresAt is the timestamp when a pending consent expires (timeout waiting for approval/denial)
// Set when status is pending, cleared when status changes to approved/rejected
PendingExpiresAt *time.Time `` /* 143-byte string literal not displayed */
// GrantExpiresAt is the timestamp when an approved consent grant expires
// Calculated by adding GrantDuration to the current time when consent is approved
// Only set when status is approved
GrantExpiresAt *time.Time `` /* 137-byte string literal not displayed */
// GrantDuration is the duration to add to current time when approving consent (e.g., "P30D", "1h")
// Used to calculate GrantExpiresAt: GrantExpiresAt = current_time + GrantDuration
GrantDuration string `gorm:"column:grant_duration;type:varchar(50);not null" json:"grant_duration"`
// Fields is the list of data fields that require consent (stored as array of field names)
Fields []ConsentField `gorm:"column:fields;type:jsonb;serializer:json;not null" json:"fields"`
// SessionID is the session identifier for tracking the consent flow
SessionID *string `gorm:"column:session_id;type:varchar(255);" json:"session_id,omitempty"`
// ConsentPortalURL is the URL to redirect to for consent portal
ConsentPortalURL string `gorm:"column:consent_portal_url;type:text;not null" json:"consent_portal_url"`
// UpdatedBy identifies who last updated the consent (audit field)
UpdatedBy *string `gorm:"column:updated_by;type:varchar(255)" json:"updated_by,omitempty"`
}
ConsentRecord represents a consent record in the system Business Rules: - Only one record can exist with status 'pending' or 'approved' for a given (OwnerID, AppID) tuple - Multiple records can exist with status 'revoked', 'expired', or 'rejected' for the same tuple - The most recently created record should have status 'pending' or 'approved' (if active)
func (*ConsentRecord) TableName ¶
func (*ConsentRecord) TableName() string
TableName specifies the table name for GORM
func (*ConsentRecord) ToConsentResponseInternalView ¶
func (cr *ConsentRecord) ToConsentResponseInternalView() ConsentResponseInternalView
ToConsentResponseInternalView converts a ConsentRecord to a simplified ConsentResponseInternalView. Only includes consent_portal_url when status is pending and the URL is not empty Includes fields only when status is pending or approved to support internal operations
func (*ConsentRecord) ToConsentResponsePortalView ¶
func (cr *ConsentRecord) ToConsentResponsePortalView() ConsentResponsePortalView
ToConsentResponsePortalView converts an internal ConsentRecord to a user-facing view. Returns rich field information including display names and descriptions for better UX
func (*ConsentRecord) ToConsentSummaryView ¶ added in v0.5.0
func (cr *ConsentRecord) ToConsentSummaryView() ConsentSummaryView
ToConsentSummaryView converts a ConsentRecord to the compact row used when listing an owner's consents
type ConsentRequirement ¶
type ConsentRequirement struct {
Owner OwnerType `json:"owner"`
OwnerID string `json:"ownerId"`
Fields []ConsentField `json:"fields"`
}
ConsentRequirement represents a consent requirement for a specific owner
type ConsentResponseInternalView ¶
type ConsentResponseInternalView struct {
ConsentID string `json:"consentId"`
Status string `json:"status"`
ConsentPortalURL *string `json:"consentPortalUrl,omitempty"` // Only present when status is pending
Fields *[]ConsentField `json:"fields,omitempty"` // Included for internal use if needed
}
ConsentResponseInternalView represents a simplified consent response structure for Internal API Responses
type ConsentResponsePortalView ¶
type ConsentResponsePortalView struct {
ConsentID string `json:"consentId"`
AppID string `json:"appId"`
AppName *string `json:"appName"`
OwnerID string `json:"ownerId"`
Status ConsentStatus `json:"status"`
Type ConsentType `json:"type"`
GrantDuration string `json:"grantDuration"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
PendingExpiresAt *time.Time `json:"pendingExpiresAt,omitempty"` // Only set while pending
GrantExpiresAt *time.Time `json:"grantExpiresAt,omitempty"` // Only set once approved
Fields []ConsentField `json:"fields"` // Rich field information with display names and descriptions
}
ConsentResponsePortalView represents the user-facing consent object for the UI. Uses rich field information for better UX in the consent portal
type ConsentStatus ¶
type ConsentStatus string
ConsentStatus represents the status of a consent record
const ( StatusPending ConsentStatus = "pending" StatusApproved ConsentStatus = "approved" StatusRejected ConsentStatus = "rejected" StatusExpired ConsentStatus = "expired" StatusRevoked ConsentStatus = "revoked" )
ConsentStatus constants
type ConsentSummaryView ¶ added in v0.5.0
type ConsentSummaryView struct {
ConsentID string `json:"consentId"`
AppID string `json:"appId"`
AppName *string `json:"appName"`
Status ConsentStatus `json:"status"`
CreatedAt time.Time `json:"createdAt"`
PendingExpiresAt *time.Time `json:"pendingExpiresAt,omitempty"` // Only set while pending
GrantExpiresAt *time.Time `json:"grantExpiresAt,omitempty"` // Only set once approved
}
ConsentSummaryView is the compact row shown in the consent portal's list of an owner's consents. The full request (fields, grant duration, ...) is fetched by ID via ConsentResponsePortalView.
type ConsentType ¶
type ConsentType string
ConsentType represents the type of consent mechanism
const ( TypeRealtime ConsentType = "realtime" TypeOffline ConsentType = "offline" )
ConsentType constants
type CreateConsentRequest ¶
type CreateConsentRequest struct {
AppID string `json:"appId"`
AppName *string `json:"appName,omitempty"`
ConsentRequirement ConsentRequirement `json:"consentRequirement"`
GrantDuration *string `json:"grantDuration,omitempty"`
ConsentType *ConsentType `json:"consentType,omitempty"`
}
CreateConsentRequest defines the structure for creating a consent record GrantDuration is optional - nil means not provided and will use default value
type GrantDuration ¶
type GrantDuration string
GrantDuration represents the duration for which consent is granted
const ( DurationOneHour GrantDuration = "PT1H" // 1 hour DurationSixHours GrantDuration = "PT6H" // 6 hours DurationTwelveHours GrantDuration = "PT12H" // 12 hours DurationOneDay GrantDuration = "P1D" // 1 day DurationSevenDays GrantDuration = "P7D" // 7 days DurationThirtyDays GrantDuration = "P30D" // 30 days DurationDefault GrantDuration = DurationOneHour // default duration )
GrantDuration constants
type ListConsentsResponse ¶ added in v0.5.0
type ListConsentsResponse struct {
Consents []ConsentSummaryView `json:"consents"`
Total int64 `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
ListConsentsResponse is the paginated list of the authenticated owner's consents
type OwnerType ¶
type OwnerType string
OwnerType represents the owner enum (matches PolicyDecisionPoint Owner type)
const (
OwnerCitizen OwnerType = "citizen"
)
type UpdateByMessage ¶
type UpdateByMessage string
UpdateByMessage represents who updated the consent with specific message
const (
RevokedByNewConsentWithDifferentFields UpdateByMessage = "System: revoked due to new consent with different fields"
)
UpdateByMessage constants