56 KiB
pgsql
import "github.com/effective-security/trustyca/internal/db/pgsql"
Package pgsql implements the database interfaces of internal/db on PostgreSQL.
Provider wraps an xdb.Provider; every method builds its SQL through the query package, measures the query and maps a missing row to xdb.ErrorNotFound. A method that writes more than one row (AcceptInvite, RegisterCertificate with an event, RegisterIssuer with an anchor, RevokeCertificate, PublishCrl) opens a transaction with BeginTx and runs every statement on the provider it returns:
tx, err := p.BeginTx(ctx, nil)
defer tx.Close() // rolls back unless committed
txProvider := tx.(*Provider)
Lists page by offset or by a keyset cursor on their sort key (listRows): id for the CA lists, (created_at, id) for the events, (name, id) for the orgs and the projects. The tests need the configured local PostgreSQL database.
Index
- Constants
- Variables
- func DbMeasureQuerySince(query string, start time.Time)
- func DbMeasureSince(start time.Time)
- func IsUniqueViolation(err error, prefix string) bool
- type Provider
- func New(p xdb.Provider) (*Provider, error)
- func (p *Provider) AcceptInvite(ctx context.Context, inviteID, userID uint64) (*model.Membership, error)
- func (p *Provider) AcceptInvites(ctx context.Context, user *model.User) (model.MembershipSlice, error)
- func (p *Provider) ActivateIssuer(ctx context.Context, m *model.Issuer) (*model.Issuer, error)
- func (p *Provider) AddMember(ctx context.Context, member *model.Membership) (*model.Membership, error)
- func (p *Provider) BeginTx(ctx context.Context, opts *sql.TxOptions) (xdb.Provider, error)
- func (p *Provider) Builder() xsql.SQLDialect
- func (p *Provider) CheckErrIDConflict(ctx context.Context, err error, id uint64)
- func (p *Provider) Close() (err error)
- func (p *Provider) Commit() error
- func (p *Provider) ConnectionString() string
- func (p *Provider) CountCertificates(ctx context.Context, req *query.CountCertificatesRequest) (*model.CertificateCounts, error)
- func (p *Provider) CountIssuers(ctx context.Context, req *query.CountIssuersRequest) (model.IssuerCounts, error)
- func (p *Provider) CreateEvent(ctx context.Context, m *model.Event) (*model.Event, error)
- func (p *Provider) CreateInvite(ctx context.Context, invite *model.Invite) (*model.Invite, error)
- func (p *Provider) DB() xdb.DB
- func (p *Provider) DeleteAPIKey(ctx context.Context, orgID, id uint64) (int64, error)
- func (p *Provider) DeleteCertificate(ctx context.Context, orgID, id uint64) (int64, error)
- func (p *Provider) DeleteCrl(ctx context.Context, orgID uint64, ikid string) (int64, error)
- func (p *Provider) DeleteExpiredCertificates(ctx context.Context, req *query.DeleteExpiredCertificatesRequest) (int64, error)
- func (p *Provider) DeleteInvite(ctx context.Context, r *query.DeleteInviteRequest) (int64, error)
- func (p *Provider) DeleteInviteByID(ctx context.Context, id uint64) (int64, error)
- func (p *Provider) DeleteIssuer(ctx context.Context, orgID, id uint64) (int64, error)
- func (p *Provider) DeleteLogin(ctx context.Context, id uint64) (int64, error)
- func (p *Provider) DeleteMember(ctx context.Context, r *query.DeleteMemberRequest) (int64, error)
- func (p *Provider) DeleteOrg(ctx context.Context, id uint64) (map[string]int64, error)
- func (p *Provider) DeleteProfile(ctx context.Context, orgID, id uint64) (int64, error)
- func (p *Provider) DeleteRoot(ctx context.Context, orgID, id uint64) (int64, error)
- func (p *Provider) DeleteUser(ctx context.Context, id uint64) (map[string]int64, error)
- func (p *Provider) DeleteUserByEmail(ctx context.Context, email string) (map[string]int64, error)
- func (p *Provider) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (p *Provider) ExpireCertificates(ctx context.Context, req *query.ExpireCertificatesRequest) (int64, error)
- func (p *Provider) FindIssuer(ctx context.Context, orgID, projectID uint64, label string) (*model.Issuer, error)
- func (p *Provider) FindOrg(ctx context.Context, alias string) (*model.Org, error)
- func (p *Provider) FindProfile(ctx context.Context, orgID, projectID uint64, label string) (*model.CertificateProfile, error)
- func (p *Provider) FindProject(ctx context.Context, orgID uint64, alias string) (*model.Project, error)
- func (p *Provider) GetAPIKey(ctx context.Context, orgID, id uint64) (*model.APIKey, error)
- func (p *Provider) GetCertificate(ctx context.Context, id uint64) (*model.Certificate, error)
- func (p *Provider) GetCertificateByIssuerSerial(ctx context.Context, ikid, serial string) (*model.Certificate, error)
- func (p *Provider) GetCertificateBySha256(ctx context.Context, sha256 string) (*model.Certificate, error)
- func (p *Provider) GetCrl(ctx context.Context, ikid string) (*model.Crl, error)
- func (p *Provider) GetCrls(ctx context.Context, ikids []string) ([]*model.Crl, error)
- func (p *Provider) GetEvent(ctx context.Context, id uint64) (*model.Event, error)
- func (p *Provider) GetInvite(ctx context.Context, id uint64) (*model.Invite, error)
- func (p *Provider) GetInviteByOrgAndEmail(ctx context.Context, orgID, projectID uint64, email string) (*model.Invite, error)
- func (p *Provider) GetIssuer(ctx context.Context, id uint64) (*model.Issuer, error)
- func (p *Provider) GetIssuerBySKID(ctx context.Context, skid string) (*model.Issuer, error)
- func (p *Provider) GetLogin(ctx context.Context, id uint64) (*model.Login, error)
- func (p *Provider) GetLoginsByEmail(ctx context.Context, email string) (model.LoginSlice, error)
- func (p *Provider) GetOrg(ctx context.Context, id uint64) (*model.Org, error)
- func (p *Provider) GetOrgInvites(ctx context.Context, orgID uint64) (model.InviteSlice, error)
- func (p *Provider) GetProfile(ctx context.Context, id uint64) (*model.CertificateProfile, error)
- func (p *Provider) GetProject(ctx context.Context, id uint64) (*model.Project, error)
- func (p *Provider) GetRevoked(ctx context.Context, req *query.GetRevokedRequest) (*model.Revoked, error)
- func (p *Provider) GetRoot(ctx context.Context, id uint64) (*model.RootCertificate, error)
- func (p *Provider) GetSummaryCounts(ctx context.Context, req *query.SummaryRequest) (*model.SummaryCounts, error)
- func (p *Provider) GetUser(ctx context.Context, id uint64) (*model.User, error)
- func (p *Provider) GetUserByEmail(ctx context.Context, email string) (*model.User, error)
- func (p *Provider) GetUserInvites(ctx context.Context, email string) (model.InviteSlice, error)
- func (p *Provider) GetUserMemberships(ctx context.Context, userID uint64) (model.MembershipInfoSlice, error)
- func (p *Provider) GetUserOrgs(ctx context.Context, userID uint64) (model.OrgSlice, error)
- func (p *Provider) IDTime(id uint64) time.Time
- func (p *Provider) ListAPIKeys(ctx context.Context, r *query.ListAPIKeysRequest) (*model.APIKeyResult, error)
- func (p *Provider) ListCertificates(ctx context.Context, req *query.ListCertificatesRequest) (*model.CertificateResult, error)
- func (p *Provider) ListCrlStates(ctx context.Context, req *query.ListCrlStatesRequest) (*model.CrlStateResult, error)
- func (p *Provider) ListCrls(ctx context.Context, req *query.ListCrlsRequest) (*model.CrlResult, error)
- func (p *Provider) ListEvents(ctx context.Context, r *query.ListEventsRequest) (*model.EventResult, error)
- func (p *Provider) ListIssuers(ctx context.Context, req *query.ListIssuersRequest) (*model.IssuerResult, error)
- func (p *Provider) ListLogins(ctx context.Context, limit, offset uint32) (model.LoginSlice, uint32, error)
- func (p *Provider) ListMemberships(ctx context.Context, req *query.ListMembershipsRequest) (model.MembershipInfoSlice, error)
- func (p *Provider) ListOrgs(ctx context.Context, req *query.ListOrgsRequest) (*model.OrgResult, error)
- func (p *Provider) ListProfiles(ctx context.Context, req *query.ListProfilesRequest) (*model.CertificateProfileResult, error)
- func (p *Provider) ListProjects(ctx context.Context, req *query.ListProjectsRequest) (*model.ProjectResult, error)
- func (p *Provider) ListRevoked(ctx context.Context, req *query.ListRevokedRequest) (*model.RevokedResult, error)
- func (p *Provider) ListRevokedCertificates(ctx context.Context, req *query.ListRevokedCertificatesRequest) (*model.RevokedCertificateResult, error)
- func (p *Provider) ListRoots(ctx context.Context, req *query.ListRootsRequest) (*model.RootCertificateResult, error)
- func (p *Provider) LoginUser(ctx context.Context, m *model.Login) (*model.Login, *model.User, error)
- func (p *Provider) Name() string
- func (p *Provider) NewNotificationsListener() notifier.Listener
- func (p *Provider) NextID() xdb.ID
- func (p *Provider) PublishCrl(ctx context.Context, m *model.Crl) (*model.Crl, error)
- func (p *Provider) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (p *Provider) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- func (p *Provider) RegisterAPIKey(ctx context.Context, m *model.APIKey) (*model.APIKey, error)
- func (p *Provider) RegisterCertificate(ctx context.Context, m *model.Certificate, evt *model.Event) (*model.Certificate, error)
- func (p *Provider) RegisterIssuer(ctx context.Context, m *model.Issuer, anchor *model.RootCertificate) (*model.Issuer, error)
- func (p *Provider) RegisterOrg(ctx context.Context, m *model.Org, ownerID uint64) (*model.Org, error)
- func (p *Provider) RegisterProfile(ctx context.Context, m *model.CertificateProfile) (*model.CertificateProfile, error)
- func (p *Provider) RegisterProject(ctx context.Context, m *model.Project) (*model.Project, error)
- func (p *Provider) RegisterRoot(ctx context.Context, m *model.RootCertificate) (*model.RootCertificate, error)
- func (p *Provider) RevokeCertificate(ctx context.Context, req *query.RevokeCertificateRequest) (*model.RevokedCertificate, error)
- func (p *Provider) Rollback() error
- func (p *Provider) TryCreateEvent(evt *model.Event)
- func (p *Provider) Tx() xdb.Tx
- func (p *Provider) UpdateCertificate(ctx context.Context, req *query.UpdateCertificateRequest) (*model.Certificate, error)
- func (p *Provider) UpdateIssuer(ctx context.Context, req *query.UpdateIssuerRequest) (*model.Issuer, error)
- func (p *Provider) UpdateMemberRole(ctx context.Context, req *query.UpdateMemberRoleRequest) (*model.Membership, error)
- func (p *Provider) UpdateOrg(ctx context.Context, req *query.UpdateOrgRequest) (*model.Org, error)
- func (p *Provider) UpdateProject(ctx context.Context, req *query.UpdateProjectRequest) (*model.Project, error)
- func (p *Provider) UpdateUser(ctx context.Context, id uint64, name string, emailVerified bool) (*model.User, error)
- func (p *Provider) UseAPIKey(ctx context.Context, orgID, id uint64) (*model.APIKey, error)
Constants
The unique constraints of the CA tables, as PostgreSQL names them in a violation (SQLSTATE 23505)
const (
// UniqueIssuerLabel is the label of an issuer in its org and project
UniqueIssuerLabel = "unique_issuer_org_project_label"
// UniqueIssuerSkid is the key identifier of an issuer, across the table
UniqueIssuerSkid = "unique_issuer_skid"
// UniqueCertificatePrefix is the prefix of the unique constraints of the
// certificate table: the thumbprint, and the issuer and serial pair
UniqueCertificatePrefix = "unique_certificate"
)
DefaultInviteExpiry is the validity of an invite when the caller does not set ExpiresAt
const DefaultInviteExpiry = 14 * 24 * time.Hour
Variables
DbSlowMethodMilliseconds defines the maximum number of Milliseconds to define a DB operation slow
var DbSlowMethodMilliseconds = 500
ErrAlreadyRevoked is returned by RevokeCertificate for a certificate whose status is Revoked
var ErrAlreadyRevoked = errors.New("certificate is already revoked")
ErrRootConflict is returned by RegisterRoot when the certificate is registered in another scope: the thumbprint is unique across the table
var ErrRootConflict = errors.New("root certificate is registered in another scope")
ErrStaleCrlNumber is returned by PublishCrl when the CRL number is not greater than the issuer's current one: another publisher won, and the caller signs a new CRL with the next number
var ErrStaleCrlNumber = errors.New("crl number is not greater than the issuer's crl number")
func DbMeasureQuerySince
func DbMeasureQuerySince(query string, start time.Time)
DbMeasureQuerySince emit DB operation perf, and logs a Warning for slow operations
func DbMeasureSince
func DbMeasureSince(start time.Time)
DbMeasureSince emit DB operation perf, and logs a Warning for slow operations
func IsUniqueViolation
func IsUniqueViolation(err error, prefix string) bool
IsUniqueViolation reports whether the error is a unique constraint violation of a constraint whose name starts with the prefix; an empty prefix matches every unique constraint. The driver's error is matched by its SQLSTATE and constraint name; an error that only carries the driver's message, as the fakes of the tests return, by the message.
type Provider
Provider represents SQL client instance
type Provider struct {
// contains filtered or unexported fields
}
func New
func New(p xdb.Provider) (*Provider, error)
New creates a Provider instance
func (*Provider) AcceptInvite
func (p *Provider) AcceptInvite(ctx context.Context, inviteID, userID uint64) (*model.Membership, error)
AcceptInvite accepts an invite for a user, adds the user as a member at the invite's scope with the invited role, and removes the invite.
func (*Provider) AcceptInvites
func (p *Provider) AcceptInvites(ctx context.Context, user *model.User) (model.MembershipSlice, error)
AcceptInvites moves the pending invites for a user's email to grants at the invites' scopes, and returns the grants it created. Each invite is accepted in a transaction of its own: an invite whose grant fails is logged, stays pending and is not returned, and one withdrawn since the list is not found and grants nothing.
func (*Provider) ActivateIssuer
func (p *Provider) ActivateIssuer(ctx context.Context, m *model.Issuer) (*model.Issuer, error)
ActivateIssuer sets the certificate columns of a Pending issuer from the model, clears its CSR and makes it Active. The issuer is reported as not found when it does not exist, is not Pending or is not of the model's org.
func (*Provider) AddMember
func (p *Provider) AddMember(ctx context.Context, member *model.Membership) (*model.Membership, error)
AddMember grants a role org-wide (empty ProjectID) or in a project. An existing grant at the same scope gets the new role.
func (*Provider) BeginTx
func (p *Provider) BeginTx(ctx context.Context, opts *sql.TxOptions) (xdb.Provider, error)
BeginTx starts a transaction.
The provided context is used until the transaction is committed or rolled back. If the context is cancelled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginTx is cancelled.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*Provider) Builder
func (p *Provider) Builder() xsql.SQLDialect
Builder returns SQL dialect
func (*Provider) CheckErrIDConflict
func (p *Provider) CheckErrIDConflict(ctx context.Context, err error, id uint64)
CheckErrIDConflict prints decomposed ID if error is ID conflict
func (*Provider) Close
func (p *Provider) Close() (err error)
Close connection and release resources
func (*Provider) Commit
func (p *Provider) Commit() error
func (*Provider) ConnectionString
func (p *Provider) ConnectionString() string
func (*Provider) CountCertificates
func (p *Provider) CountCertificates(ctx context.Context, req *query.CountCertificatesRequest) (*model.CertificateCounts, error)
CountCertificates counts the certificates of the org of the request by status, and the Active ones whose validity ends within each period of the request: one statement per period, a range of the expiring entries
func (*Provider) CountIssuers
func (p *Provider) CountIssuers(ctx context.Context, req *query.CountIssuersRequest) (model.IssuerCounts, error)
CountIssuers counts the issuers of the org of the request by lifecycle status; a status without issuers has no entry
func (*Provider) CreateEvent
func (p *Provider) CreateEvent(ctx context.Context, m *model.Event) (*model.Event, error)
CreateEvent returns new Event
func (*Provider) CreateInvite
func (p *Provider) CreateInvite(ctx context.Context, invite *model.Invite) (*model.Invite, error)
CreateInvite creates or updates an invite for a user to join an org (empty ProjectID) or a project
func (*Provider) DB
func (p *Provider) DB() xdb.DB
DB returns underlying DB connection
func (*Provider) DeleteAPIKey
func (p *Provider) DeleteAPIKey(ctx context.Context, orgID, id uint64) (int64, error)
DeleteAPIKey deletes an API key of the org and returns the number of deleted rows
func (*Provider) DeleteCertificate
func (p *Provider) DeleteCertificate(ctx context.Context, orgID, id uint64) (int64, error)
DeleteCertificate deletes a certificate of the exact org scope (a zero orgID is the platform) and its revocation, and returns the number of deleted certificates. Certificates are audit records: the retention task and operators delete them, the tenant lifecycle does not.
func (*Provider) DeleteCrl
func (p *Provider) DeleteCrl(ctx context.Context, orgID uint64, ikid string) (int64, error)
DeleteCrl deletes the current CRL of the issuer with the key identifier in the exact org scope (a zero orgID is the platform) and returns the number of deleted rows
func (*Provider) DeleteExpiredCertificates
func (p *Provider) DeleteExpiredCertificates(ctx context.Context, req *query.DeleteExpiredCertificatesRequest) (int64, error)
DeleteExpiredCertificates deletes a batch of certificates of any status whose validity ended before the time, with their revocations, lowest IDs first, and returns the number of deleted certificates. The caller repeats the call until a batch is smaller than the limit. Retention is the only deletion of certificates the service performs itself.
func (*Provider) DeleteInvite
func (p *Provider) DeleteInvite(ctx context.Context, r *query.DeleteInviteRequest) (int64, error)
DeleteInvite deletes invites at the requested scope
func (*Provider) DeleteInviteByID
func (p *Provider) DeleteInviteByID(ctx context.Context, id uint64) (int64, error)
DeleteInviteByID deletes an invite by ID
func (*Provider) DeleteIssuer
func (p *Provider) DeleteIssuer(ctx context.Context, orgID, id uint64) (int64, error)
DeleteIssuer deletes an issuer of the exact org scope (a zero orgID is the platform) and its current CRL, and returns the number of deleted issuers. The certificates it issued are kept: the lifecycle of an issuer ends with the Destroyed status, deletion is for operators.
func (*Provider) DeleteLogin
func (p *Provider) DeleteLogin(ctx context.Context, id uint64) (int64, error)
DeleteLogin deletes a single login by ID
func (*Provider) DeleteMember
func (p *Provider) DeleteMember(ctx context.Context, r *query.DeleteMemberRequest) (int64, error)
DeleteMember deletes grants at the requested scope
func (*Provider) DeleteOrg
func (p *Provider) DeleteOrg(ctx context.Context, id uint64) (map[string]int64, error)
DeleteOrg deletes an org and all its members
func (*Provider) DeleteProfile
func (p *Provider) DeleteProfile(ctx context.Context, orgID, id uint64) (int64, error)
DeleteProfile deletes a certificate profile of the exact org scope (a zero orgID is the platform) and returns the number of deleted rows
func (*Provider) DeleteRoot
func (p *Provider) DeleteRoot(ctx context.Context, orgID, id uint64) (int64, error)
DeleteRoot deletes a trust anchor of the exact org scope (a zero orgID is the platform) and returns the number of deleted rows
func (*Provider) DeleteUser
func (p *Provider) DeleteUser(ctx context.Context, id uint64) (map[string]int64, error)
DeleteUser deletes user and logins by user ID
func (*Provider) DeleteUserByEmail
func (p *Provider) DeleteUserByEmail(ctx context.Context, email string) (map[string]int64, error)
DeleteUserByEmail deletes user and logins
func (*Provider) ExecContext
func (p *Provider) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Provider) ExpireCertificates
func (p *Provider) ExpireCertificates(ctx context.Context, req *query.ExpireCertificatesRequest) (int64, error)
ExpireCertificates sets the status of a batch of Active certificates whose validity ended before the time to Expired, lowest IDs first, and returns the number of certificates it changed. The caller repeats the call until a batch is smaller than the limit: a changed row leaves the set, so no offset is needed.
func (*Provider) FindIssuer
func (p *Provider) FindIssuer(ctx context.Context, orgID, projectID uint64, label string) (*model.Issuer, error)
FindIssuer returns the issuer of the exact scope and label: a zero orgID is the platform scope and a zero projectID the org scope. The resolution of a label through the scopes is the caller's.
func (*Provider) FindOrg
func (p *Provider) FindOrg(ctx context.Context, alias string) (*model.Org, error)
FindOrg returns Org by alias
func (*Provider) FindProfile
func (p *Provider) FindProfile(ctx context.Context, orgID, projectID uint64, label string) (*model.CertificateProfile, error)
FindProfile returns the profile of the exact scope and label: a zero orgID is the platform scope and a zero projectID the org scope. The resolution of a label through the scopes is the caller's.
func (*Provider) FindProject
func (p *Provider) FindProject(ctx context.Context, orgID uint64, alias string) (*model.Project, error)
FindProject returns Project by org and alias
func (*Provider) GetAPIKey
func (p *Provider) GetAPIKey(ctx context.Context, orgID, id uint64) (*model.APIKey, error)
GetAPIKey returns an API key of the org by ID
func (*Provider) GetCertificate
func (p *Provider) GetCertificate(ctx context.Context, id uint64) (*model.Certificate, error)
GetCertificate returns a certificate by ID
func (*Provider) GetCertificateByIssuerSerial
func (p *Provider) GetCertificateByIssuerSerial(ctx context.Context, ikid, serial string) (*model.Certificate, error)
GetCertificateByIssuerSerial returns a certificate by the key identifier of its issuer and its serial number
func (*Provider) GetCertificateBySha256
func (p *Provider) GetCertificateBySha256(ctx context.Context, sha256 string) (*model.Certificate, error)
GetCertificateBySha256 returns a certificate by its hex encoded SHA-256 thumbprint
func (*Provider) GetCrl
func (p *Provider) GetCrl(ctx context.Context, ikid string) (*model.Crl, error)
GetCrl returns the current CRL of the issuer with the key identifier
func (*Provider) GetCrls
func (p *Provider) GetCrls(ctx context.Context, ikids []string) ([]*model.Crl, error)
GetCrls returns the current CRLs of the issuers with the key identifiers, in any order; an issuer without a CRL has none in the result. The CRL publisher reads the CRLs of a page of issuers in one query, so the list is bounded by the caller's page; no key identifiers read nothing.
func (*Provider) GetEvent
func (p *Provider) GetEvent(ctx context.Context, id uint64) (*model.Event, error)
GetEvent returns Event
func (*Provider) GetInvite
func (p *Provider) GetInvite(ctx context.Context, id uint64) (*model.Invite, error)
GetInvite returns an invite by ID
func (*Provider) GetInviteByOrgAndEmail
func (p *Provider) GetInviteByOrgAndEmail(ctx context.Context, orgID, projectID uint64, email string) (*model.Invite, error)
GetInviteByOrgAndEmail returns an invite by org, scope and email. projectID 0 returns the Org scope invite.
func (*Provider) GetIssuer
func (p *Provider) GetIssuer(ctx context.Context, id uint64) (*model.Issuer, error)
GetIssuer returns an issuer by ID
func (*Provider) GetIssuerBySKID
func (p *Provider) GetIssuerBySKID(ctx context.Context, skid string) (*model.Issuer, error)
GetIssuerBySKID returns the issuer by its Subject Key Identifier, which is the IKID of the certificates and CRLs it issued
func (*Provider) GetLogin
func (p *Provider) GetLogin(ctx context.Context, id uint64) (*model.Login, error)
GetLogin returns a login by ID
func (*Provider) GetLoginsByEmail
func (p *Provider) GetLoginsByEmail(ctx context.Context, email string) (model.LoginSlice, error)
GetLoginsByEmail returns Logins
func (*Provider) GetOrg
func (p *Provider) GetOrg(ctx context.Context, id uint64) (*model.Org, error)
GetOrg returns Org by ID
func (*Provider) GetOrgInvites
func (p *Provider) GetOrgInvites(ctx context.Context, orgID uint64) (model.InviteSlice, error)
GetOrgInvites returns invites of all scopes for an org
func (*Provider) GetProfile
func (p *Provider) GetProfile(ctx context.Context, id uint64) (*model.CertificateProfile, error)
GetProfile returns a certificate profile by ID
func (*Provider) GetProject
func (p *Provider) GetProject(ctx context.Context, id uint64) (*model.Project, error)
GetProject returns Project by ID
func (*Provider) GetRevoked
func (p *Provider) GetRevoked(ctx context.Context, req *query.GetRevokedRequest) (*model.Revoked, error)
GetRevoked returns the revocation of a certificate by its ID, or by the key identifier of its issuer and its serial number
func (*Provider) GetRoot
func (p *Provider) GetRoot(ctx context.Context, id uint64) (*model.RootCertificate, error)
GetRoot returns a trust anchor by ID
func (*Provider) GetSummaryCounts
func (p *Provider) GetSummaryCounts(ctx context.Context, req *query.SummaryRequest) (*model.SummaryCounts, error)
GetSummaryCounts reads the counts of the tenant summary at one snapshot: a read-only REPEATABLE READ transaction runs the issuer counts, the certificate counts and every page of the CRL states, so the counts agree with each other and with the states, as the dashboard reports them at one time. The transaction holds no lock and is rolled back when the reads are done.
func (*Provider) GetUser
func (p *Provider) GetUser(ctx context.Context, id uint64) (*model.User, error)
GetUser returns user
func (*Provider) GetUserByEmail
func (p *Provider) GetUserByEmail(ctx context.Context, email string) (*model.User, error)
GetUserByEmail returns User
func (*Provider) GetUserInvites
func (p *Provider) GetUserInvites(ctx context.Context, email string) (model.InviteSlice, error)
GetUserInvites returns invites for a user's email
func (*Provider) GetUserMemberships
func (p *Provider) GetUserMemberships(ctx context.Context, userID uint64) (model.MembershipInfoSlice, error)
GetUserMemberships returns all grants of a user in active orgs
func (*Provider) GetUserOrgs
func (p *Provider) GetUserOrgs(ctx context.Context, userID uint64) (model.OrgSlice, error)
GetUserOrgs gets the orgs for a user
func (*Provider) IDTime
func (p *Provider) IDTime(id uint64) time.Time
IDTime returns time when ID was generated
func (*Provider) ListAPIKeys
func (p *Provider) ListAPIKeys(ctx context.Context, r *query.ListAPIKeysRequest) (*model.APIKeyResult, error)
ListAPIKeys lists API keys of an org
func (*Provider) ListCertificates
func (p *Provider) ListCertificates(ctx context.Context, req *query.ListCertificatesRequest) (*model.CertificateResult, error)
ListCertificates lists certificates, newest first; the request names its org scope
func (*Provider) ListCrlStates
func (p *Provider) ListCrlStates(ctx context.Context, req *query.ListCrlStatesRequest) (*model.CrlStateResult, error)
ListCrlStates lists the issuers of the org of the request with the lifecycle statuses of the request, newest first, with the state of their current CRL: the columns the tenant summary classifies, never a PEM
func (*Provider) ListCrls
func (p *Provider) ListCrls(ctx context.Context, req *query.ListCrlsRequest) (*model.CrlResult, error)
ListCrls lists the current CRLs, newest first; the request names its org scope
func (*Provider) ListEvents
func (p *Provider) ListEvents(ctx context.Context, r *query.ListEventsRequest) (*model.EventResult, error)
ListEvents lists events, newest first
func (*Provider) ListIssuers
func (p *Provider) ListIssuers(ctx context.Context, req *query.ListIssuersRequest) (*model.IssuerResult, error)
ListIssuers lists issuers, newest first; the request names its org scope
func (*Provider) ListLogins
func (p *Provider) ListLogins(ctx context.Context, limit, offset uint32) (model.LoginSlice, uint32, error)
ListLogins returns Logins
func (*Provider) ListMemberships
func (p *Provider) ListMemberships(ctx context.Context, req *query.ListMembershipsRequest) (model.MembershipInfoSlice, error)
ListMemberships lists memberships
func (*Provider) ListOrgs
func (p *Provider) ListOrgs(ctx context.Context, req *query.ListOrgsRequest) (*model.OrgResult, error)
ListOrgs lists orgs by name
func (*Provider) ListProfiles
func (p *Provider) ListProfiles(ctx context.Context, req *query.ListProfilesRequest) (*model.CertificateProfileResult, error)
ListProfiles lists certificate profiles, newest first; the request names its org scope
func (*Provider) ListProjects
func (p *Provider) ListProjects(ctx context.Context, req *query.ListProjectsRequest) (*model.ProjectResult, error)
ListProjects lists projects of an org by name
func (*Provider) ListRevoked
func (p *Provider) ListRevoked(ctx context.Context, req *query.ListRevokedRequest) (*model.RevokedResult, error)
ListRevoked lists revocations, newest first; the request names its org scope. A CRL is built from the revocations of an issuer that are still valid.
func (*Provider) ListRevokedCertificates
func (p *Provider) ListRevokedCertificates(ctx context.Context, req *query.ListRevokedCertificatesRequest) (*model.RevokedCertificateResult, error)
ListRevokedCertificates lists revoked certificates with their certificate columns, newest revocation first; the request names its org scope
func (*Provider) ListRoots
func (p *Provider) ListRoots(ctx context.Context, req *query.ListRootsRequest) (*model.RootCertificateResult, error)
ListRoots lists trust anchors, newest first; the request names its org scope
func (*Provider) LoginUser
func (p *Provider) LoginUser(ctx context.Context, m *model.Login) (*model.Login, *model.User, error)
LoginUser registers the login and its user and returns both. A new login and a new user are inserted under one new ID; on a conflict each row keeps its ID, so only the first login of a new user returns both with the same ID.
func (*Provider) Name
func (p *Provider) Name() string
func (*Provider) NewNotificationsListener
func (p *Provider) NewNotificationsListener() notifier.Listener
func (*Provider) NextID
func (p *Provider) NextID() xdb.ID
NextID returns unique ID
func (*Provider) PublishCrl
func (p *Provider) PublishCrl(ctx context.Context, m *model.Crl) (*model.Crl, error)
PublishCrl stores the current CRL of an issuer and records its number on the issuer in one transaction. The CRL's IKID must be the issuer's SKID and the number greater than the issuer's current CRL number, so the number of an IKID only grows: otherwise nothing is stored and ErrStaleCrlNumber is returned. The tenancy and issuer name of the CRL are copied from the issuer row.
func (*Provider) QueryContext
func (p *Provider) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Provider) QueryRowContext
func (p *Provider) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*Provider) RegisterAPIKey
func (p *Provider) RegisterAPIKey(ctx context.Context, m *model.APIKey) (*model.APIKey, error)
RegisterAPIKey inserts a new API key; the key and the protected secret are prepared by the caller
func (*Provider) RegisterCertificate
func (p *Provider) RegisterCertificate(ctx context.Context, m *model.Certificate, evt *model.Event) (*model.Certificate, error)
RegisterCertificate inserts the issuance record of a certificate; the status defaults to Active. The thumbprint and the issuer and serial number pair are unique. With an event, the insert and the event are one transaction, and the event references the certificate when it has no reference of its own.
func (*Provider) RegisterIssuer
func (p *Provider) RegisterIssuer(ctx context.Context, m *model.Issuer, anchor *model.RootCertificate) (*model.Issuer, error)
RegisterIssuer inserts an issuer. A Pending issuer carries its CSR, any other status its certificate; the label is unique in its scope and the SKID across the table. A root issuer requires its anchor, its own certificate as a trust anchor of its org, which is registered as RegisterRoot does in the transaction of the insert, so a root issuer is never stored without it; any other issuer takes none. An anchor registered in another scope fails both with ErrRootConflict.
func (*Provider) RegisterOrg
func (p *Provider) RegisterOrg(ctx context.Context, m *model.Org, ownerID uint64) (*model.Org, error)
RegisterOrg registers a new org and, when ownerID is set, its Owner in one transaction: an org is never left without its Owner
func (*Provider) RegisterProfile
func (p *Provider) RegisterProfile(ctx context.Context, m *model.CertificateProfile) (*model.CertificateProfile, error)
RegisterProfile creates a certificate profile, or replaces the issuer label, status and config of the profile with the same label in the same scope; the row ID and creation time of a replaced profile are kept
func (*Provider) RegisterProject
func (p *Provider) RegisterProject(ctx context.Context, m *model.Project) (*model.Project, error)
RegisterProject creates a project in an org
func (*Provider) RegisterRoot
func (p *Provider) RegisterRoot(ctx context.Context, m *model.RootCertificate) (*model.RootCertificate, error)
RegisterRoot registers a trust anchor. Registering the same certificate again in the same scope updates its trust and returns the existing row; the same certificate in another scope fails with ErrRootConflict.
func (*Provider) RevokeCertificate
func (p *Provider) RevokeCertificate(ctx context.Context, req *query.RevokeCertificateRequest) (*model.RevokedCertificate, error)
RevokeCertificate records the revocation of a certificate of the exact org scope and sets its status to Revoked in one transaction. The revocation copies the issuer, serial number, expiry and tenancy of the certificate row.
func (*Provider) Rollback
func (p *Provider) Rollback() error
func (*Provider) TryCreateEvent
func (p *Provider) TryCreateEvent(evt *model.Event)
TryCreateEvent creates the event on its own goroutine with a background context, so the caller's cancellation does not drop it, and logs a failure instead of returning it
func (*Provider) Tx
func (p *Provider) Tx() xdb.Tx
Tx returns underlying DB transaction
func (*Provider) UpdateCertificate
func (p *Provider) UpdateCertificate(ctx context.Context, req *query.UpdateCertificateRequest) (*model.Certificate, error)
UpdateCertificate replaces the label, the client metadata or the published locations of a certificate of the exact org scope
func (*Provider) UpdateIssuer
func (p *Provider) UpdateIssuer(ctx context.Context, req *query.UpdateIssuerRequest) (*model.Issuer, error)
UpdateIssuer changes the lifecycle status or the runtime settings of an issuer of the exact org scope; the Destroyed status also clears the protected key material. The config must be a pb.IssuerConfig document.
func (*Provider) UpdateMemberRole
func (p *Provider) UpdateMemberRole(ctx context.Context, req *query.UpdateMemberRoleRequest) (*model.Membership, error)
UpdateMemberRole updates the role of a grant at the given scope
func (*Provider) UpdateOrg
func (p *Provider) UpdateOrg(ctx context.Context, req *query.UpdateOrgRequest) (*model.Org, error)
UpdateOrg updates an org's name and description
func (*Provider) UpdateProject
func (p *Provider) UpdateProject(ctx context.Context, req *query.UpdateProjectRequest) (*model.Project, error)
UpdateProject updates a project's name, description or status
func (*Provider) UpdateUser
func (p *Provider) UpdateUser(ctx context.Context, id uint64, name string, emailVerified bool) (*model.User, error)
UpdateUser updates a user's profile
func (*Provider) UseAPIKey
func (p *Provider) UseAPIKey(ctx context.Context, orgID, id uint64) (*model.APIKey, error)
UseAPIKey increments the used count and sets the used at time
Generated by gomarkdoc