db

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: BSD-2-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDocuments = errors.New("no documents in result")

ErrNoDocuments is returned when no documents are found

Functions

This section is empty.

Types

type AddIdentityQuery added in v0.5.7

type AddIdentityQuery struct {
	AuthenticSource    string   `json:"authentic_source" bson:"authentic_source"`
	Scope              string   `json:"scope" bson:"scope"`
	DocumentID         string   `json:"document_id" bson:"document_id"`
	IdentityMappingIDs []string `json:"identity_mapping_ids" bson:"identity_mapping_ids"`
}

AddIdentityQuery is the query to add document identity

type CredentialOfferColl added in v0.5.7

type CredentialOfferColl struct {
	Service *Service
	Coll    *mongo.Collection
	// contains filtered or unexported fields
}

func NewCredentialOfferColl

func NewCredentialOfferColl(ctx context.Context, collName string, service *Service, log *logger.Log) (*CredentialOfferColl, error)

func (*CredentialOfferColl) Delete added in v0.5.7

func (c *CredentialOfferColl) Delete(ctx context.Context, uuid string) error

Delete deletes one code_challenge

func (*CredentialOfferColl) Get added in v0.5.7

func (*CredentialOfferColl) Save added in v0.5.7

type CredentialOfferDocument

type CredentialOfferDocument struct {
	UUID                      string                               `bson:"uuid"`
	CredentialOfferParameters openid4vci.CredentialOfferParameters `bson:"credential_offer_parameters"`
}

type CredentialOfferStore

type CredentialOfferStore interface {
	Save(ctx context.Context, doc *CredentialOfferDocument) error
	Get(ctx context.Context, uuid string) (*CredentialOfferDocument, error)
	Delete(ctx context.Context, uuid string) error
}

CredentialOfferStore defines the interface for credential offer operations

type DatastoreColl added in v0.5.7

type DatastoreColl struct {
	Service *Service
	Coll    *mongo.Collection
	// contains filtered or unexported fields
}

DatastoreColl is the generic collection

func (*DatastoreColl) AddIdentity added in v0.5.7

func (c *DatastoreColl) AddIdentity(ctx context.Context, query *AddIdentityQuery) error

AddIdentity adds document identity

func (*DatastoreColl) Count added in v0.7.1

func (c *DatastoreColl) Count(ctx context.Context) (int64, error)

Count returns the (possibly approximate) number of documents in the datastore.

func (*DatastoreColl) Delete added in v0.5.7

func (c *DatastoreColl) Delete(ctx context.Context, doc *model.MetaData) error

Delete deletes a document

func (*DatastoreColl) DeleteByKey added in v0.5.7

func (c *DatastoreColl) DeleteByKey(ctx context.Context, authenticSource, scope, documentID string) error

DeleteByKey deletes a document by its natural key (authentic_source, scope, document_id)

func (*DatastoreColl) DeleteIdentity added in v0.5.7

func (c *DatastoreColl) DeleteIdentity(ctx context.Context, query *DeleteIdentityQuery) error

DeleteIdentity deletes identity in document

func (*DatastoreColl) Get added in v0.5.7

func (c *DatastoreColl) Get(ctx context.Context, meta *model.MetaData) (*model.Document, error)

Get return matching document if any, or error

func (*DatastoreColl) GetByIdentity added in v0.5.7

func (c *DatastoreColl) GetByIdentity(ctx context.Context, scope, identityMappingID string) (map[string]*model.CompleteDocument, error)

GetByIdentity returns matching documents for a scope where any of the document's identity_mapping_ids match the provided identifier.

func (*DatastoreColl) GetByKey added in v0.5.7

func (c *DatastoreColl) GetByKey(ctx context.Context, authenticSource, scope, documentID string) (*model.CompleteDocument, error)

GetByKey retrieves a document by its natural key (authentic_source, scope, document_id)

func (*DatastoreColl) List added in v0.5.7

func (c *DatastoreColl) List(ctx context.Context, query *ListQuery) ([]*model.DocumentList, error)

List return matching documents if any, or error

func (*DatastoreColl) ListAuthenticSources added in v0.5.7

func (c *DatastoreColl) ListAuthenticSources(ctx context.Context) ([]string, error)

ListAuthenticSources returns all unique authentic_source values in the datastore

func (*DatastoreColl) Replace added in v0.5.7

func (c *DatastoreColl) Replace(ctx context.Context, doc *model.CompleteDocument) error

Replace replaces one document

func (*DatastoreColl) Save added in v0.5.7

Save saves one document to the generic collection

func (*DatastoreColl) SaveMany added in v0.5.7

func (c *DatastoreColl) SaveMany(ctx context.Context, docs []*model.CompleteDocument) error

SaveMany saves multiple documents to the generic collection using bulk insert

func (*DatastoreColl) Search added in v0.5.7

Search returns documents matching a text search or filters, with a limit

type DatastoreStore

type DatastoreStore interface {
	// Count returns the (possibly approximate) number of documents in the datastore.
	Count(ctx context.Context) (int64, error)
	Save(ctx context.Context, doc *model.CompleteDocument) error
	SaveMany(ctx context.Context, docs []*model.CompleteDocument) error
	AddIdentity(ctx context.Context, query *AddIdentityQuery) error
	DeleteIdentity(ctx context.Context, query *DeleteIdentityQuery) error
	Delete(ctx context.Context, doc *model.MetaData) error
	Get(ctx context.Context, meta *model.MetaData) (*model.Document, error)
	GetByIdentity(ctx context.Context, scope, identityMappingID string) (map[string]*model.CompleteDocument, error)
	List(ctx context.Context, query *ListQuery) ([]*model.DocumentList, error)
	Replace(ctx context.Context, doc *model.CompleteDocument) error
	GetByKey(ctx context.Context, authenticSource, scope, documentID string) (*model.CompleteDocument, error)
	DeleteByKey(ctx context.Context, authenticSource, scope, documentID string) error
	Search(ctx context.Context, query *SearchDocumentsQuery) ([]*model.CompleteDocument, error)
	ListAuthenticSources(ctx context.Context) ([]string, error)
}

DatastoreStore defines the interface for datastore operations

type DeleteIdentityQuery added in v0.5.7

type DeleteIdentityQuery struct {
	AuthenticSource         string `json:"authentic_source" bson:"authentic_source"`
	Scope                   string `json:"scope" bson:"scope"`
	DocumentID              string `json:"document_id" bson:"document_id"`
	AuthenticSourcePersonID string `json:"authentic_source_person_id" bson:"authentic_source_person_id"`
}

DeleteIdentityQuery is the query to delete identity in document

type DeleteMappingQuery added in v0.5.7

type DeleteMappingQuery struct {
	AuthenticSource         string `json:"authentic_source"`
	AuthenticSourcePersonID string `json:"authentic_source_person_id"`
}

DeleteMappingQuery is the query for deleting an identity mapping

type DynamicRegistrationColl added in v0.5.7

type DynamicRegistrationColl struct {
	Service *Service
	Coll    *mongo.Collection
	// contains filtered or unexported fields
}

DynamicRegistrationColl handles persistence of dynamic client registration credentials.

func NewDynamicRegistrationColl

func NewDynamicRegistrationColl(ctx context.Context, collName string, service *Service, log *logger.Log) (*DynamicRegistrationColl, error)

NewDynamicRegistrationColl creates a new collection for dynamic registration credentials.

func (*DynamicRegistrationColl) Get added in v0.5.7

Get returns the stored credentials, or nil if none exist.

func (*DynamicRegistrationColl) Save added in v0.5.7

Save stores or replaces dynamic registration credentials.

type DynamicRegistrationCredentials

type DynamicRegistrationCredentials struct {
	ClientID                string    `bson:"client_id"`
	ClientSecret            string    `bson:"client_secret"`
	RegistrationAccessToken string    `bson:"registration_access_token,omitempty"`
	RegistrationClientURI   string    `bson:"registration_client_uri,omitempty"`
	ClientSecretExpiresAt   int64     `bson:"client_secret_expires_at,omitempty"`
	RegisteredAt            time.Time `bson:"registered_at"`
}

DynamicRegistrationCredentials holds OIDC dynamic client registration credentials.

type DynamicRegistrationStore added in v0.7.1

type DynamicRegistrationStore interface {
	Save(ctx context.Context, creds *DynamicRegistrationCredentials) error
	Get(ctx context.Context) (*DynamicRegistrationCredentials, error)
}

DynamicRegistrationStore defines the interface for OIDC dynamic client registration operations

type IdentityMappingStore added in v0.5.7

type IdentityMappingStore interface {
	// Count returns the (possibly approximate) number of identity mappings.
	Count(ctx context.Context) (int64, error)
	CreateMapping(ctx context.Context, mapping *model.IdentityMapping) error
	CreateMappings(ctx context.Context, mappings []*model.IdentityMapping) error
	EnsureMapping(ctx context.Context, mapping *model.IdentityMapping) error
	ResolveMapping(ctx context.Context, query *ResolveMappingQuery) (string, error)
	UpdateMapping(ctx context.Context, mapping *model.IdentityMapping) error
	DeleteMapping(ctx context.Context, query *DeleteMappingQuery) error
	SearchMappings(ctx context.Context, query *SearchMappingsQuery) ([]*model.IdentityMapping, error)
}

IdentityMappingStore defines the interface for identity mapping operations

type IdentityMappingsColl added in v0.5.7

type IdentityMappingsColl struct {
	Service *Service
	Coll    *mongo.Collection
	// contains filtered or unexported fields
}

IdentityMappingsColl is the collection for identity mappings

func (*IdentityMappingsColl) Count added in v0.7.1

func (c *IdentityMappingsColl) Count(ctx context.Context) (int64, error)

Count returns the (possibly approximate) number of identity mappings.

func (*IdentityMappingsColl) CreateMapping added in v0.5.7

func (c *IdentityMappingsColl) CreateMapping(ctx context.Context, mapping *model.IdentityMapping) error

CreateMapping creates a new identity mapping

func (*IdentityMappingsColl) CreateMappings added in v0.5.7

func (c *IdentityMappingsColl) CreateMappings(ctx context.Context, mappings []*model.IdentityMapping) error

CreateMappings creates multiple identity mappings using bulk insert

func (*IdentityMappingsColl) DeleteMapping added in v0.5.7

func (c *IdentityMappingsColl) DeleteMapping(ctx context.Context, query *DeleteMappingQuery) error

DeleteMapping deletes an identity mapping

func (*IdentityMappingsColl) EnsureMapping added in v0.5.7

func (c *IdentityMappingsColl) EnsureMapping(ctx context.Context, mapping *model.IdentityMapping) error

EnsureMapping creates an identity mapping only if it does not already exist. If a record with the same (authentic_source, authentic_source_person_id) already exists, it is left unchanged.

func (*IdentityMappingsColl) ResolveMapping added in v0.5.7

func (c *IdentityMappingsColl) ResolveMapping(ctx context.Context, query *ResolveMappingQuery) (string, error)

ResolveMapping resolves identity attributes to an authentic_source_person_id.

func (*IdentityMappingsColl) SearchMappings added in v0.5.7

func (c *IdentityMappingsColl) SearchMappings(ctx context.Context, query *SearchMappingsQuery) ([]*model.IdentityMapping, error)

SearchMappings returns identity mappings matching a text search or filters, with a limit

func (*IdentityMappingsColl) UpdateMapping added in v0.5.7

func (c *IdentityMappingsColl) UpdateMapping(ctx context.Context, mapping *model.IdentityMapping) error

UpdateMapping updates the attributes of an existing identity mapping

type ListQuery added in v0.5.7

type ListQuery struct {
	AuthenticSource   string `json:"authentic_source" bson:"authentic_source"`
	IdentityMappingID string `json:"identity_mapping_id" bson:"identity_mapping_id" validate:"required"`
	Scope             string `json:"scope" bson:"scope"`
	ValidFrom         int64  `json:"valid_from" bson:"valid_from"`
	ValidTo           int64  `json:"valid_to" bson:"valid_to"`
}

ListQuery is the query to get document list

type ResolveMappingQuery added in v0.5.7

type ResolveMappingQuery struct {
	AuthenticSource string            `json:"authentic_source"`
	Attributes      map[string]string `json:"attributes"`
}

ResolveMappingQuery is the query for resolving attributes to an authentic_source_person_id

type SQLCredentialOfferColl added in v0.7.1

type SQLCredentialOfferColl struct {
	Service *Service
	// contains filtered or unexported fields
}

SQLCredentialOfferColl is a SQL-backed implementation of CredentialOfferStore.

func NewSQLCredentialOfferColl added in v0.7.1

func NewSQLCredentialOfferColl(service *Service, db *sqlx.DB, dialect sqlstore.Dialect) *SQLCredentialOfferColl

NewSQLCredentialOfferColl creates a SQL-backed CredentialOfferStore.

func (*SQLCredentialOfferColl) Delete added in v0.7.1

func (c *SQLCredentialOfferColl) Delete(ctx context.Context, uuid string) error

Delete deletes one credential offer by uuid.

func (*SQLCredentialOfferColl) Get added in v0.7.1

Get returns the credential offer document for the given uuid.

func (*SQLCredentialOfferColl) Save added in v0.7.1

Save saves one credential offer document.

type SQLDatastoreColl added in v0.7.1

type SQLDatastoreColl struct {
	Service *Service
	// contains filtered or unexported fields
}

SQLDatastoreColl is a SQL-backed implementation of DatastoreStore.

func NewSQLDatastoreColl added in v0.7.1

func NewSQLDatastoreColl(service *Service, db *sqlx.DB, dialect sqlstore.Dialect) *SQLDatastoreColl

NewSQLDatastoreColl creates a SQL-backed DatastoreStore.

func (*SQLDatastoreColl) AddIdentity added in v0.7.1

func (c *SQLDatastoreColl) AddIdentity(ctx context.Context, query *AddIdentityQuery) error

AddIdentity adds document identity.

func (*SQLDatastoreColl) Count added in v0.7.1

func (c *SQLDatastoreColl) Count(ctx context.Context) (int64, error)

Count returns the (possibly approximate) number of documents in the datastore.

func (*SQLDatastoreColl) Delete added in v0.7.1

func (c *SQLDatastoreColl) Delete(ctx context.Context, doc *model.MetaData) error

Delete deletes a document. Mirrors Mongo's Delete: silently succeeds even if nothing matched.

func (*SQLDatastoreColl) DeleteByKey added in v0.7.1

func (c *SQLDatastoreColl) DeleteByKey(ctx context.Context, authenticSource, scope, documentID string) error

DeleteByKey deletes a document by its natural key (authentic_source, scope, document_id).

func (*SQLDatastoreColl) DeleteIdentity added in v0.7.1

func (c *SQLDatastoreColl) DeleteIdentity(ctx context.Context, query *DeleteIdentityQuery) error

DeleteIdentity deletes identity in document.

func (*SQLDatastoreColl) Get added in v0.7.1

Get returns the matching document, or an error if none exists.

func (*SQLDatastoreColl) GetByIdentity added in v0.7.1

func (c *SQLDatastoreColl) GetByIdentity(ctx context.Context, scope, identityMappingID string) (map[string]*model.CompleteDocument, error)

GetByIdentity returns matching documents for a scope where any of the document's identity mappings match the provided identifier.

func (*SQLDatastoreColl) GetByKey added in v0.7.1

func (c *SQLDatastoreColl) GetByKey(ctx context.Context, authenticSource, scope, documentID string) (*model.CompleteDocument, error)

GetByKey retrieves a document by its natural key (authentic_source, scope, document_id).

func (*SQLDatastoreColl) List added in v0.7.1

func (c *SQLDatastoreColl) List(ctx context.Context, query *ListQuery) ([]*model.DocumentList, error)

List returns matching document metadata, filtered by identity mapping and optionally authentic_source/scope.

func (*SQLDatastoreColl) ListAuthenticSources added in v0.7.1

func (c *SQLDatastoreColl) ListAuthenticSources(ctx context.Context) ([]string, error)

ListAuthenticSources returns all unique authentic_source values in the datastore.

func (*SQLDatastoreColl) Replace added in v0.7.1

Replace replaces one document, including its full set of identity mappings, matching by natural key. Mirrors Mongo's ReplaceOne: silently does nothing if no document matches.

func (*SQLDatastoreColl) Save added in v0.7.1

Save saves one document to the generic collection.

func (*SQLDatastoreColl) SaveMany added in v0.7.1

func (c *SQLDatastoreColl) SaveMany(ctx context.Context, docs []*model.CompleteDocument) error

SaveMany saves multiple documents to the generic collection.

func (*SQLDatastoreColl) Search added in v0.7.1

Search returns documents matching a text search or filters, with a limit. The document_data.* text search is a known perf tradeoff vs Mongo's regex-across-BSON: neither Postgres nor MariaDB can cheaply full-text index arbitrary, unschema'd JSON keys without knowing them in advance.

type SQLDynamicRegistrationColl added in v0.7.1

type SQLDynamicRegistrationColl struct {
	Service *Service
	// contains filtered or unexported fields
}

SQLDynamicRegistrationColl is a SQL-backed implementation of DynamicRegistrationStore.

func NewSQLDynamicRegistrationColl added in v0.7.1

func NewSQLDynamicRegistrationColl(service *Service, db *sqlx.DB, dialect sqlstore.Dialect) *SQLDynamicRegistrationColl

NewSQLDynamicRegistrationColl creates a SQL-backed DynamicRegistrationStore.

func (*SQLDynamicRegistrationColl) Get added in v0.7.1

Get returns the stored credentials, or nil if none exist or the client secret has expired.

func (*SQLDynamicRegistrationColl) Save added in v0.7.1

Save stores or replaces dynamic registration credentials, upserting by client_id.

type SQLIdentityMappingsColl added in v0.7.1

type SQLIdentityMappingsColl struct {
	Service *Service
	// contains filtered or unexported fields
}

SQLIdentityMappingsColl is a SQL-backed implementation of IdentityMappingStore.

func NewSQLIdentityMappingsColl added in v0.7.1

func NewSQLIdentityMappingsColl(service *Service, db *sqlx.DB, dialect sqlstore.Dialect) *SQLIdentityMappingsColl

NewSQLIdentityMappingsColl creates a SQL-backed IdentityMappingStore.

func (*SQLIdentityMappingsColl) Count added in v0.7.1

Count returns the (possibly approximate) number of identity mappings.

func (*SQLIdentityMappingsColl) CreateMapping added in v0.7.1

func (c *SQLIdentityMappingsColl) CreateMapping(ctx context.Context, mapping *model.IdentityMapping) error

CreateMapping creates a new identity mapping.

func (*SQLIdentityMappingsColl) CreateMappings added in v0.7.1

func (c *SQLIdentityMappingsColl) CreateMappings(ctx context.Context, mappings []*model.IdentityMapping) error

CreateMappings creates multiple identity mappings in a single statement.

func (*SQLIdentityMappingsColl) DeleteMapping added in v0.7.1

func (c *SQLIdentityMappingsColl) DeleteMapping(ctx context.Context, query *DeleteMappingQuery) error

DeleteMapping deletes an identity mapping.

func (*SQLIdentityMappingsColl) EnsureMapping added in v0.7.1

func (c *SQLIdentityMappingsColl) EnsureMapping(ctx context.Context, mapping *model.IdentityMapping) error

EnsureMapping creates an identity mapping only if it does not already exist. If a record with the same (authentic_source, authentic_source_person_id) already exists, it is left unchanged.

func (*SQLIdentityMappingsColl) ResolveMapping added in v0.7.1

func (c *SQLIdentityMappingsColl) ResolveMapping(ctx context.Context, query *ResolveMappingQuery) (string, error)

ResolveMapping resolves identity attributes to an authentic_source_person_id.

func (*SQLIdentityMappingsColl) SearchMappings added in v0.7.1

SearchMappings returns identity mappings matching a text search or filters, with a limit.

func (*SQLIdentityMappingsColl) UpdateMapping added in v0.7.1

func (c *SQLIdentityMappingsColl) UpdateMapping(ctx context.Context, mapping *model.IdentityMapping) error

UpdateMapping updates the attributes of an existing identity mapping.

type SearchDocumentsQuery

type SearchDocumentsQuery struct {
	Search                  string   `json:"search"`
	AuthenticSource         string   `json:"authentic_source"`
	Scope                   string   `json:"scope"`
	Limit                   int64    `json:"limit"`
	AllowedAuthenticSources []string `json:"-"`
	AllowedScopes           []string `json:"-"`
}

SearchDocumentsQuery is the query for searching documents

type SearchMappingsQuery added in v0.5.7

type SearchMappingsQuery struct {
	Search                  string   `json:"search"`
	AuthenticSource         string   `json:"authentic_source"`
	Limit                   int64    `json:"limit"`
	AllowedAuthenticSources []string `json:"-"`
}

SearchMappingsQuery is the query for searching identity mappings

type Service

type Service struct {
	MongoClient *mongo.Client
	SQLDB       *sqlx.DB

	DatastoreColl           DatastoreStore
	IdentityMappingsColl    IdentityMappingStore
	CredentialOfferColl     CredentialOfferStore
	DynamicRegistrationColl DynamicRegistrationStore
	// contains filtered or unexported fields
}

Service is the database service

func New

func New(ctx context.Context, cfg *model.Cfg, tracer *trace.Tracer, log *logger.Log) (*Service, error)

New creates a new database service. The storage backend is selected by cfg.Common.SQL.Backend: "postgres" or "mariadb" connect to the corresponding relational database (via pkg/sqlstore, running schema migrations at startup); anything else (including unset, the default) keeps the existing MongoDB-backed behavior unchanged.

func (*Service) Close

func (s *Service) Close(ctx context.Context) error

Close closes the database connection

func (*Service) HealthProbe added in v0.7.4

func (s *Service) HealthProbe(ctx context.Context) error

HealthProbe implements the status.Prober contract: returns nil when the active backend (SQL or MongoDB) is reachable, otherwise the underlying error.

Jump to

Keyboard shortcuts

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