repository

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashSubscriptionToken

func HashSubscriptionToken(token string) string

HashSubscriptionToken computes a SHA-256 hash of the token for secure storage. The same token always produces the same hash for deterministic lookups. Exported for use when propagating to gateways (events, internal API).

func IsUniqueViolation added in v0.11.2

func IsUniqueViolation(err error) bool

IsUniqueViolation reports whether err is a database unique-constraint (or primary-key) violation. It is dialect-aware across the three databases the control plane supports — SQLite, PostgreSQL and SQL Server — matching on the stable substrings/error codes each driver surfaces.

Detection is by err.Error() substring, so a violation wrapped with fmt.Errorf("...: %w", err) is still detected without unwrapping.

Types

type APIKeyRepo

type APIKeyRepo struct {
	// contains filtered or unexported fields
}

APIKeyRepo implements APIKeyRepository

func (*APIKeyRepo) Create

func (r *APIKeyRepo) Create(key *model.APIKey) error

Create inserts a new API key record

func (*APIKeyRepo) Delete

func (r *APIKeyRepo) Delete(artifactUUID, name string) error

Delete removes an API key record permanently

func (*APIKeyRepo) GetByArtifactAndName

func (r *APIKeyRepo) GetByArtifactAndName(artifactUUID, name string) (*model.APIKey, error)

GetByArtifactAndName retrieves an API key by artifact UUID and name

func (*APIKeyRepo) ListAPIKeysByUser

func (r *APIKeyRepo) ListAPIKeysByUser(orgUUID, username string, kinds []string) ([]*model.UserAPIKey, error)

ListAPIKeysByUser retrieves API keys created by a given user within an org, optionally filtered by artifact kinds. If kinds is empty, all supported kinds (RestApi, LlmProvider, LlmProxy) are returned.

func (*APIKeyRepo) ListByArtifact

func (r *APIKeyRepo) ListByArtifact(artifactUUID string) ([]*model.APIKey, error)

ListByArtifact retrieves all API keys for a given artifact UUID

func (*APIKeyRepo) ListByGatewayAndKind

func (r *APIKeyRepo) ListByGatewayAndKind(gatewayID, orgID, kind, issuer string) ([]*model.APIKey, error)

ListByGatewayAndKind retrieves all API keys for artifacts of the given kind that have an active deployment association on the specified gateway within the organization (status_desired in DEPLOYED or UNDEPLOYED). When issuer is non-empty only keys whose issuer column matches are returned; an empty issuer returns keys regardless of their issuer value.

func (*APIKeyRepo) Revoke

func (r *APIKeyRepo) Revoke(artifactUUID, name string) error

Revoke marks an API key as revoked

func (*APIKeyRepo) Update

func (r *APIKeyRepo) Update(key *model.APIKey) error

Update modifies an existing API key record identified by (artifact_uuid, name)

type APIKeyRepository

type APIKeyRepository interface {
	Create(key *model.APIKey) error
	Update(key *model.APIKey) error
	Revoke(artifactUUID, name string) error
	GetByArtifactAndName(artifactUUID, name string) (*model.APIKey, error)
	ListByArtifact(artifactUUID string) ([]*model.APIKey, error)
	ListByGatewayAndKind(gatewayID, orgID, kind, issuer string) ([]*model.APIKey, error)
	Delete(artifactUUID, name string) error
	ListAPIKeysByUser(orgUUID, username string, kinds []string) ([]*model.UserAPIKey, error)
}

APIKeyRepository defines the interface for API key persistence

func NewAPIKeyRepo

func NewAPIKeyRepo(db *database.DB, reg *ArtifactTableRegistry) APIKeyRepository

NewAPIKeyRepo creates a new API key repository

type APIRepo

type APIRepo struct {
	// contains filtered or unexported fields
}

APIRepo implements APIRepository

func (*APIRepo) CheckAPIExistsByHandleInOrganization

func (r *APIRepo) CheckAPIExistsByHandleInOrganization(handle, orgUUID string) (bool, error)

CheckAPIExistsByHandleInOrganization checks if an API with the given handle exists within a specific organization

func (*APIRepo) CheckAPIExistsByNameAndVersionInOrganization

func (r *APIRepo) CheckAPIExistsByNameAndVersionInOrganization(name, version, orgUUID, excludeHandle string) (bool, error)

CheckAPIExistsByNameAndVersionInOrganization checks if an API with the given name and version exists within a specific organization excludeHandle: if provided, excludes the API with this handle from the check (useful for updates)

func (*APIRepo) CountAPIsByOrganizationUUID added in v0.11.2

func (r *APIRepo) CountAPIsByOrganizationUUID(orgUUID, projectUUID, search string) (int, error)

CountAPIsByOrganizationUUID returns the total number of APIs for an organization (with an optional project filter), independent of pagination.

func (*APIRepo) CreateAPI

func (r *APIRepo) CreateAPI(api *model.API) error

CreateAPI inserts a new API with all its configurations

func (*APIRepo) CreateAPIAssociation

func (r *APIRepo) CreateAPIAssociation(association *model.APIAssociation) error

CreateAPIAssociation creates a gateway-API association in artifact_gateway_mappings.

func (*APIRepo) DeleteAPI

func (r *APIRepo) DeleteAPI(apiUUID, orgUUID string) error

DeleteAPI removes an API and all its configurations

func (*APIRepo) GetAPIAssociations

func (r *APIRepo) GetAPIAssociations(apiUUID, associationType, orgUUID string) ([]*model.APIAssociation, error)

GetAPIAssociations retrieves all gateway associations for an API. associationType is accepted for interface compatibility but only 'gateway' associations are stored.

func (*APIRepo) GetAPIByUUID

func (r *APIRepo) GetAPIByUUID(apiUUID, orgUUID string) (*model.API, error)

GetAPIByUUID retrieves an API by UUID with all its configurations

func (*APIRepo) GetAPIGatewaysWithDetails

func (r *APIRepo) GetAPIGatewaysWithDetails(apiUUID, orgUUID string) ([]*model.APIGatewayWithDetails, error)

GetAPIGatewaysWithDetails retrieves all gateways associated with an API including deployment details.

func (*APIRepo) GetAPIMetadataByHandle

func (r *APIRepo) GetAPIMetadataByHandle(handle, orgUUID string) (*model.APIMetadata, error)

GetAPIMetadataByHandle retrieves minimal API information by handle and organization ID

func (*APIRepo) GetAPIsByGatewayUUID

func (r *APIRepo) GetAPIsByGatewayUUID(gatewayUUID, orgUUID string) ([]*model.API, error)

GetAPIsByGatewayUUID retrieves all APIs associated with a specific gateway

func (*APIRepo) GetAPIsByOrganizationUUID

func (r *APIRepo) GetAPIsByOrganizationUUID(orgUUID string, projectUUID string) ([]*model.API, error)

GetAPIsByOrganizationUUID retrieves all APIs for an organization with optional project filter

func (*APIRepo) GetAPIsByOrganizationUUIDPaginated added in v0.11.2

func (r *APIRepo) GetAPIsByOrganizationUUIDPaginated(orgUUID, projectUUID string, opts ListOptions) ([]*model.API, error)

GetAPIsByOrganizationUUIDPaginated retrieves a single page of APIs for an organization with an optional project filter, applying LIMIT/OFFSET at the database via the dialect-aware pagination clause.

func (*APIRepo) GetAPIsByProjectUUID

func (r *APIRepo) GetAPIsByProjectUUID(projectUUID, orgUUID string) ([]*model.API, error)

GetAPIsByProjectUUID retrieves all APIs for a project

func (*APIRepo) GetAPIsByUUIDs

func (r *APIRepo) GetAPIsByUUIDs(uuids []string, orgUUID string) (map[string]string, error)

GetAPIsByUUIDs returns a map of API UUID to handle for the given UUIDs in the organization. Used for bulk lookup to avoid N+1 queries. Returns empty map for empty input.

func (*APIRepo) UpdateAPI

func (r *APIRepo) UpdateAPI(api *model.API) error

UpdateAPI modifies an existing API

func (*APIRepo) UpdateAPIAssociation

func (r *APIRepo) UpdateAPIAssociation(apiUUID, resourceId, associationType, orgUUID string) error

UpdateAPIAssociation updates the updated_at timestamp for a gateway-API association.

type APIRepository

type APIRepository interface {
	CreateAPI(api *model.API) error
	GetAPIByUUID(apiUUID, orgUUID string) (*model.API, error)
	GetAPIsByUUIDs(uuids []string, orgUUID string) (map[string]string, error)
	GetAPIMetadataByHandle(handle, orgUUID string) (*model.APIMetadata, error)
	GetAPIsByProjectUUID(projectUUID, orgUUID string) ([]*model.API, error)
	GetAPIsByOrganizationUUID(orgUUID string, projectUUID string) ([]*model.API, error)
	GetAPIsByOrganizationUUIDPaginated(orgUUID, projectUUID string, opts ListOptions) ([]*model.API, error)
	CountAPIsByOrganizationUUID(orgUUID, projectUUID, search string) (int, error)
	GetAPIsByGatewayUUID(gatewayUUID, orgUUID string) ([]*model.API, error)
	UpdateAPI(api *model.API) error
	DeleteAPI(apiUUID, orgUUID string) error

	// API-Gateway association methods
	GetAPIGatewaysWithDetails(apiUUID, orgUUID string) ([]*model.APIGatewayWithDetails, error)

	// Unified API association methods (supports both gateways and dev portals)
	CreateAPIAssociation(association *model.APIAssociation) error
	GetAPIAssociations(apiUUID, associationType, orgUUID string) ([]*model.APIAssociation, error)
	UpdateAPIAssociation(apiUUID, resourceId, associationType, orgUUID string) error

	// API name validation methods
	CheckAPIExistsByHandleInOrganization(handle, orgUUID string) (bool, error)
	CheckAPIExistsByNameAndVersionInOrganization(name, version, orgUUID, excludeHandle string) (bool, error)
}

APIRepository defines the interface for API data operations

func NewAPIRepo

func NewAPIRepo(db *database.DB) APIRepository

NewAPIRepo creates a new API repository

type ApplicationRepo

type ApplicationRepo struct {
	// contains filtered or unexported fields
}

func (*ApplicationRepo) AddApplicationAPIKeys

func (r *ApplicationRepo) AddApplicationAPIKeys(applicationUUID string, apiKeyIDs []string) error

func (*ApplicationRepo) AddApplicationAssociations

func (r *ApplicationRepo) AddApplicationAssociations(applicationUUID string, targetUUIDs []string) error

func (*ApplicationRepo) CheckApplicationHandleExists

func (r *ApplicationRepo) CheckApplicationHandleExists(handle, orgID string) (bool, error)

func (*ApplicationRepo) CountApplicationsByOrganizationID

func (r *ApplicationRepo) CountApplicationsByOrganizationID(orgID string) (int, error)

func (*ApplicationRepo) CountApplicationsByProjectID

func (r *ApplicationRepo) CountApplicationsByProjectID(projectID, orgID, search string) (int, error)

func (*ApplicationRepo) CreateApplication

func (r *ApplicationRepo) CreateApplication(app *model.Application) error

func (*ApplicationRepo) DeleteApplication

func (r *ApplicationRepo) DeleteApplication(appID, orgID string) error

func (*ApplicationRepo) GetAPIKeyByNameAndArtifactHandle

func (r *ApplicationRepo) GetAPIKeyByNameAndArtifactHandle(keyName, artifactHandle, orgID string) (*model.ApplicationAPIKey, error)

func (*ApplicationRepo) GetApplicationByIDOrHandle

func (r *ApplicationRepo) GetApplicationByIDOrHandle(appIDOrHandle, orgID string) (*model.Application, error)

func (*ApplicationRepo) GetApplicationByNameInProject

func (r *ApplicationRepo) GetApplicationByNameInProject(name, projectID, orgID string) (*model.Application, error)

func (*ApplicationRepo) GetApplicationByUUID

func (r *ApplicationRepo) GetApplicationByUUID(appID string) (*model.Application, error)

func (*ApplicationRepo) GetApplicationsByAPIKeyID

func (r *ApplicationRepo) GetApplicationsByAPIKeyID(apiKeyID, orgID string) ([]*model.Application, error)

GetApplicationsByAPIKeyID returns the applications the given API key is currently mapped to within the organization. Used to broadcast a mapping update to the affected gateways when a key is dissociated — the previously-owning application must be captured before the mapping is removed.

func (*ApplicationRepo) GetApplicationsByOrganizationID

func (r *ApplicationRepo) GetApplicationsByOrganizationID(orgID string) ([]*model.Application, error)

func (*ApplicationRepo) GetApplicationsByOrganizationIDPaginated

func (r *ApplicationRepo) GetApplicationsByOrganizationIDPaginated(orgID string, limit, offset int) ([]*model.Application, error)

func (*ApplicationRepo) GetApplicationsByProjectID

func (r *ApplicationRepo) GetApplicationsByProjectID(projectID, orgID string) ([]*model.Application, error)

func (*ApplicationRepo) GetApplicationsByProjectIDPaginated

func (r *ApplicationRepo) GetApplicationsByProjectIDPaginated(projectID, orgID string, opts ListOptions) ([]*model.Application, error)

func (*ApplicationRepo) GetAssociationTargetByIDOrHandle

func (r *ApplicationRepo) GetAssociationTargetByIDOrHandle(targetIDOrHandle, orgID string) (*model.Artifact, error)

func (*ApplicationRepo) GetAssociationTargetByIDOrHandleAndKind

func (r *ApplicationRepo) GetAssociationTargetByIDOrHandleAndKind(targetIDOrHandle, kind, orgID string) (*model.Artifact, error)

func (*ApplicationRepo) GetAssociationTargetByUUID

func (r *ApplicationRepo) GetAssociationTargetByUUID(targetUUID, orgID string) (*model.Artifact, error)

func (*ApplicationRepo) GetDeployedGatewayIDsByArtifactUUID

func (r *ApplicationRepo) GetDeployedGatewayIDsByArtifactUUID(artifactUUID, orgID string) ([]string, error)

func (*ApplicationRepo) GetLLMProxyProjectUUID

func (r *ApplicationRepo) GetLLMProxyProjectUUID(targetUUID, orgID string) (string, error)

func (*ApplicationRepo) ListApplicationAssociations

func (r *ApplicationRepo) ListApplicationAssociations(applicationUUID string) ([]*model.ApplicationAssociationTarget, error)

func (*ApplicationRepo) ListMappedAPIKeys

func (r *ApplicationRepo) ListMappedAPIKeys(applicationUUID string) ([]*model.ApplicationAPIKey, error)

func (*ApplicationRepo) RemoveAPIKeyFromAllApplications

func (r *ApplicationRepo) RemoveAPIKeyFromAllApplications(apiKeyID string) error

RemoveAPIKeyFromAllApplications removes the given API key from every application it is mapped to. Used to reconcile a Developer Portal apikey.application_updated event (a key belongs to at most one application), where the previous application is not carried in the event.

func (*ApplicationRepo) RemoveApplicationAPIKey

func (r *ApplicationRepo) RemoveApplicationAPIKey(applicationUUID, apiKeyID string) error

func (*ApplicationRepo) RemoveApplicationAssociation

func (r *ApplicationRepo) RemoveApplicationAssociation(applicationUUID, targetUUID string) error

func (*ApplicationRepo) UpdateApplication

func (r *ApplicationRepo) UpdateApplication(app *model.Application) error

type ApplicationRepository

type ApplicationRepository interface {
	CreateApplication(app *model.Application) error
	GetApplicationByUUID(appID string) (*model.Application, error)
	GetApplicationByIDOrHandle(appIDOrHandle, orgID string) (*model.Application, error)
	GetAssociationTargetByUUID(targetUUID, orgID string) (*model.Artifact, error)
	GetAssociationTargetByIDOrHandle(targetIDOrHandle, orgID string) (*model.Artifact, error)
	GetAssociationTargetByIDOrHandleAndKind(targetIDOrHandle, kind, orgID string) (*model.Artifact, error)
	GetLLMProxyProjectUUID(artifactUUID, orgID string) (string, error)
	GetApplicationsByProjectID(projectID, orgID string) ([]*model.Application, error)
	GetApplicationsByOrganizationID(orgID string) ([]*model.Application, error)
	GetApplicationsByProjectIDPaginated(projectID, orgID string, opts ListOptions) ([]*model.Application, error)
	GetApplicationsByOrganizationIDPaginated(orgID string, limit, offset int) ([]*model.Application, error)
	CountApplicationsByProjectID(projectID, orgID, search string) (int, error)
	CountApplicationsByOrganizationID(orgID string) (int, error)
	GetApplicationByNameInProject(name, projectID, orgID string) (*model.Application, error)
	CheckApplicationHandleExists(handle, orgID string) (bool, error)
	UpdateApplication(app *model.Application) error
	DeleteApplication(appID, orgID string) error

	GetAPIKeyByNameAndArtifactHandle(keyName, artifactHandle, orgID string) (*model.ApplicationAPIKey, error)
	GetDeployedGatewayIDsByArtifactUUID(artifactUUID, orgID string) ([]string, error)
	ListMappedAPIKeys(applicationUUID string) ([]*model.ApplicationAPIKey, error)
	ListApplicationAssociations(applicationUUID string) ([]*model.ApplicationAssociationTarget, error)
	AddApplicationAPIKeys(applicationUUID string, apiKeyIDs []string) error
	AddApplicationAssociations(applicationUUID string, targetUUIDs []string) error
	GetApplicationsByAPIKeyID(apiKeyID, orgID string) ([]*model.Application, error)
	RemoveApplicationAPIKey(applicationUUID, apiKeyID string) error
	RemoveAPIKeyFromAllApplications(apiKeyID string) error
	RemoveApplicationAssociation(applicationUUID, targetUUID string) error
}

ApplicationRepository defines the interface for application data access

type ArtifactRepo

type ArtifactRepo struct {
	// contains filtered or unexported fields
}

func NewArtifactRepo

func NewArtifactRepo(db *database.DB, reg ...*ArtifactTableRegistry) *ArtifactRepo

NewArtifactRepo creates an ArtifactRepo. When reg is provided it is used for dynamic UNION queries and kind validation; when omitted the core-only default registry (rest_apis, llm_providers, llm_proxies, mcp_proxies) is used.

func (*ArtifactRepo) CountByKindAndOrg

func (r *ArtifactRepo) CountByKindAndOrg(kind, orgUUID string) (int, error)

func (*ArtifactRepo) Create

func (r *ArtifactRepo) Create(tx *sql.Tx, artifact *model.Artifact) error

func (*ArtifactRepo) Delete

func (r *ArtifactRepo) Delete(tx *sql.Tx, uuid string) error

func (*ArtifactRepo) Exists

func (r *ArtifactRepo) Exists(kind, handle, orgUUID string) (bool, error)

Exists checks whether an artifact with the given type+handle exists for the org. Since handle moved to the type-specific tables, we query them directly.

func (*ArtifactRepo) ExistsByUUIDs

func (r *ArtifactRepo) ExistsByUUIDs(uuids []string, orgUUID string) ([]string, error)

ExistsByUUIDs returns the subset of provided UUIDs that exist in the artifacts table for the given org.

func (*ArtifactRepo) GetAPIMetadataByHandle

func (r *ArtifactRepo) GetAPIMetadataByHandle(handle, orgUUID string) (*model.APIMetadata, error)

GetAPIMetadataByHandle retrieves minimal API metadata by handle across all registered artifact tables.

func (*ArtifactRepo) GetAPIMetadataByHandleAndKind

func (r *ArtifactRepo) GetAPIMetadataByHandleAndKind(handle, kind, orgUUID string) (*model.APIMetadata, error)

GetAPIMetadataByHandleAndKind retrieves minimal API metadata by handle from the table backing the given kind. Unlike GetAPIMetadataByHandle it does not union across every table, so the caller resolves the handle against exactly one artifact kind. Returns (nil, nil) when no matching artifact exists.

func (*ArtifactRepo) GetByHandle

func (r *ArtifactRepo) GetByHandle(handle, orgUUID string) (*model.Artifact, error)

GetByHandle finds an artifact by handle across all registered artifact tables. Returns the artifact with its supplemental fields derived from the matching table.

func (*ArtifactRepo) GetByUUID

func (r *ArtifactRepo) GetByUUID(uuid, orgUUID string) (*model.Artifact, error)

GetByUUID finds an artifact by UUID across all registered artifact tables. Returns the artifact with its supplemental fields derived from the matching table.

func (*ArtifactRepo) GetMetadataByUUIDs

func (r *ArtifactRepo) GetMetadataByUUIDs(uuids []string, orgUUID string) (map[string]*model.APIMetadata, error)

GetMetadataByUUIDs returns a map of artifact UUID to minimal metadata (handle, kind, ...) for the given UUIDs, resolved across all registered artifact tables. Missing UUIDs are simply absent from the returned map. Used for bulk handle/kind resolution (avoids N+1 queries).

func (*ArtifactRepo) Update

func (r *ArtifactRepo) Update(_ *sql.Tx, _ *model.Artifact) error

Update is a no-op: artifact rows no longer store mutable fields (name/version moved to type-specific tables).

type ArtifactRepository

type ArtifactRepository interface {
	Create(tx *sql.Tx, artifact *model.Artifact) error
	Delete(tx *sql.Tx, uuid string) error
	Update(tx *sql.Tx, artifact *model.Artifact) error
	Exists(kind, handle, orgUUID string) (bool, error)
	GetByHandle(handle, orgUUID string) (*model.Artifact, error)
	GetByUUID(uuid, orgUUID string) (*model.Artifact, error)
	GetAPIMetadataByHandle(handle, orgUUID string) (*model.APIMetadata, error)
	GetAPIMetadataByHandleAndKind(handle, kind, orgUUID string) (*model.APIMetadata, error)
	GetMetadataByUUIDs(uuids []string, orgUUID string) (map[string]*model.APIMetadata, error)
	CountByKindAndOrg(kind, orgUUID string) (int, error)
	ExistsByUUIDs(uuids []string, orgUUID string) ([]string, error)
}

type ArtifactTableEntry

type ArtifactTableEntry struct {
	// Table is the SQL table name, e.g. "websub_apis".
	Table string
	// KindAlias is the value stored in artifacts.type, e.g. "WebSubApi".
	KindAlias string
	// KindKeys are the acceptable kind strings for Exists() lookup (typically the
	// HTTP handle form "websub-api" and the Go constant form "WebSubApi").
	KindKeys []string
}

ArtifactTableEntry describes a kind-specific child table that backs artifact rows. Core tables are pre-registered; plugins register their own entries during Init.

type ArtifactTableRegistry

type ArtifactTableRegistry struct {
	// contains filtered or unexported fields
}

ArtifactTableRegistry maintains the set of kind-specific tables that back artifact rows. Core tables (rest_apis, llm_providers, llm_proxies, mcp_proxies) are pre-registered; plugins call Register during Init to contribute their own tables.

func NewArtifactTableRegistry

func NewArtifactTableRegistry() *ArtifactTableRegistry

NewArtifactTableRegistry returns a registry pre-seeded with the four core artifact tables.

func (*ArtifactTableRegistry) Entries

Entries returns a snapshot copy of all registered entries in registration order.

func (*ArtifactTableRegistry) IsValidKindAlias

func (r *ArtifactTableRegistry) IsValidKindAlias(alias string) bool

IsValidKindAlias reports whether alias matches any registered entry's KindAlias.

func (*ArtifactTableRegistry) Register

Register appends an entry. Plugins call this during Init before the server starts accepting requests.

func (*ArtifactTableRegistry) TableByKindKey

func (r *ArtifactTableRegistry) TableByKindKey(key string) (ArtifactTableEntry, bool)

TableByKindKey returns the entry whose KindKeys slice contains key, and true if found.

func (*ArtifactTableRegistry) UnionAllSelect

func (r *ArtifactTableRegistry) UnionAllSelect(cols ...string) string

UnionAllSelect builds a "SELECT cols FROM t1 UNION ALL SELECT cols FROM t2 …" fragment for all registered tables. cols must not include a trailing space. The result has no leading or trailing newline and is suitable for use inside a subquery.

type AuditRepo

type AuditRepo struct {
	// contains filtered or unexported fields
}

AuditRepo writes records to the audit table.

func (*AuditRepo) Record

func (r *AuditRepo) Record(action, resourceUUID, resourceType, orgUUID, performedBy string) error

Record inserts a single audit row. Failures are non-fatal — callers should ignore the returned error.

type AuditRepository

type AuditRepository interface {
	Record(action, resourceUUID, resourceType, orgUUID, performedBy string) error
}

AuditRepository defines the interface for audit record writes.

func NewAuditRepo

func NewAuditRepo(db *database.DB) AuditRepository

NewAuditRepo creates a new AuditRepo.

type CustomPolicyRepo

type CustomPolicyRepo struct {
	// contains filtered or unexported fields
}

CustomPolicyRepo implements CustomPolicyRepository

func (*CustomPolicyRepo) CountCustomPolicyUsages

func (r *CustomPolicyRepo) CountCustomPolicyUsages(policyUUID string) (int, error)

CountCustomPolicyUsages returns the number of APIs that reference this custom policy via the join table.

func (*CustomPolicyRepo) DeleteCustomPolicy

func (r *CustomPolicyRepo) DeleteCustomPolicy(orgUUID, name, version string) error

DeleteCustomPolicy removes a custom policy by org, name, and version.

func (*CustomPolicyRepo) DeleteCustomPolicyIfUnused

func (r *CustomPolicyRepo) DeleteCustomPolicyIfUnused(orgUUID, policyUUID string) error

DeleteCustomPolicyIfUnused atomically deletes the policy only when it has no active usages.

func (*CustomPolicyRepo) DeleteCustomPolicyUsage

func (r *CustomPolicyRepo) DeleteCustomPolicyUsage(policyUUID, apiUUID string) error

DeleteCustomPolicyUsage removes the usage entry.

func (*CustomPolicyRepo) GetCustomPoliciesByName

func (r *CustomPolicyRepo) GetCustomPoliciesByName(orgUUID, name string) ([]*model.CustomPolicy, error)

GetCustomPoliciesByName retrieves all versions of a custom policy for a given org and name.

func (*CustomPolicyRepo) GetCustomPolicyByNameAndVersion

func (r *CustomPolicyRepo) GetCustomPolicyByNameAndVersion(orgUUID, name, version string) (*model.CustomPolicy, error)

GetCustomPolicyByNameAndVersion retrieves a custom policy by org, name, and version.

func (*CustomPolicyRepo) GetCustomPolicyByUUID

func (r *CustomPolicyRepo) GetCustomPolicyByUUID(orgUUID, policyUUID string) (*model.CustomPolicy, error)

GetCustomPolicyByUUID retrieves a custom policy by its UUID, scoped to an organization.

func (*CustomPolicyRepo) GetCustomPolicyUsagesByAPIUUID

func (r *CustomPolicyRepo) GetCustomPolicyUsagesByAPIUUID(apiUUID string) ([]string, error)

GetCustomPolicyUsagesByAPIUUID returns all policy UUIDs currently used with the given API.

func (*CustomPolicyRepo) InsertCustomPolicy

func (r *CustomPolicyRepo) InsertCustomPolicy(policy *model.CustomPolicy) error

InsertCustomPolicy inserts or updates a custom policy by (organization_uuid, name, version).

func (*CustomPolicyRepo) InsertCustomPolicyUsage

func (r *CustomPolicyRepo) InsertCustomPolicyUsage(policyUUID, apiUUID string) error

InsertCustomPolicyUsage adds a custom policy usage entry for the given API.

func (*CustomPolicyRepo) ListCustomPolicyByOrganization

func (r *CustomPolicyRepo) ListCustomPolicyByOrganization(orgUUID string) ([]*model.CustomPolicy, error)

ListCustomPolicyByOrganization retrieves all custom policies for an organization.

func (*CustomPolicyRepo) UpdateCustomPolicy

func (r *CustomPolicyRepo) UpdateCustomPolicy(policy *model.CustomPolicy, oldVersion string) error

UpdateCustomPolicy updates an existing policy's version and definition identified by (org, name, oldVersion).

type CustomPolicyRepository

type CustomPolicyRepository interface {
	InsertCustomPolicy(policy *model.CustomPolicy) error
	UpdateCustomPolicy(policy *model.CustomPolicy, oldVersion string) error
	GetCustomPolicyByNameAndVersion(orgUUID, name, version string) (*model.CustomPolicy, error)
	GetCustomPolicyByUUID(orgUUID, policyUUID string) (*model.CustomPolicy, error)
	GetCustomPoliciesByName(orgUUID, name string) ([]*model.CustomPolicy, error)
	ListCustomPolicyByOrganization(orgUUID string) ([]*model.CustomPolicy, error)
	DeleteCustomPolicy(orgUUID, name, version string) error
	CountCustomPolicyUsages(policyUUID string) (int, error)
	// DeleteCustomPolicyIfUnused atomically deletes the policy only when it has no active usages.
	DeleteCustomPolicyIfUnused(orgUUID, policyUUID string) error
	// Gateway Custom Policy usage tracking methods.
	GetCustomPolicyUsagesByAPIUUID(apiUUID string) ([]string, error)
	InsertCustomPolicyUsage(policyUUID, apiUUID string) error
	DeleteCustomPolicyUsage(policyUUID, apiUUID string) error
}

CustomPolicyRepository defines the interface for custom policy persistence

func NewCustomPolicyRepo

func NewCustomPolicyRepo(db *database.DB) CustomPolicyRepository

NewCustomPolicyRepo creates a new CustomPolicyRepo

type DeploymentRepo

type DeploymentRepo struct {
	// contains filtered or unexported fields
}

DeploymentRepo implements DeploymentRepository

func (*DeploymentRepo) CreateWithLimitEnforcement

func (r *DeploymentRepo) CreateWithLimitEnforcement(deployment *model.Deployment, hardLimit int) error

CreateWithLimitEnforcement atomically creates a deployment with hard limit enforcement If deployment count >= hardLimit, deletes oldest 5 ARCHIVED deployments before inserting new one This entire operation is wrapped in a single transaction to ensure atomicity and to leverage row-level locks during deletion to reduce race conditions.

func (*DeploymentRepo) Delete

func (r *DeploymentRepo) Delete(deploymentID, artifactUUID, orgUUID string) error

Delete deletes a deployment record

func (*DeploymentRepo) DeleteStatus

func (r *DeploymentRepo) DeleteStatus(artifactUUID, orgUUID, gatewayID string) error

DeleteStatus deletes the status entry for an artifact on a gateway

func (*DeploymentRepo) GetArtifactUUIDByDeploymentID

func (r *DeploymentRepo) GetArtifactUUIDByDeploymentID(deploymentID, orgUUID string) (string, error)

GetArtifactUUIDByDeploymentID resolves the artifact UUID for a given deployment ID. Used to normalise ack handling where the gateway may send a string handle instead of a UUID.

func (*DeploymentRepo) GetControlPlaneDeploymentsByGateway

func (r *DeploymentRepo) GetControlPlaneDeploymentsByGateway(gatewayID, orgUUID string, since *time.Time) ([]*model.DeploymentInfo, error)

GetControlPlaneDeploymentsByGateway retrieves the control-plane-owned deployments for a specific gateway. Data-plane-originated (gateway_api) artifacts are excluded because they are owned by the gateway and pushed up to the CP (DP->CP); syncing them back down would make the gateway try to re-create artifacts it already has. Returns lightweight DeploymentInfo for listing deployments Only returns deployments that have an active status (DEPLOYED or UNDEPLOYED) Results are ordered by kind (RestApi -> LlmProvider -> LlmProxy -> Mcp) to ensure dependencies are processed in correct order (LLM Proxies depend on LLM Providers) If since is provided, only returns deployments updated after that timestamp

func (*DeploymentRepo) GetCurrentByGateway

func (r *DeploymentRepo) GetCurrentByGateway(artifactUUID, gatewayID, orgUUID string) (*model.Deployment, error)

GetCurrentByGateway retrieves the currently DEPLOYED deployment for an artifact on a gateway Returns only deployments with DEPLOYED status (filters out UNDEPLOYED/suspended deployments)

func (*DeploymentRepo) GetDeployedGatewayIDs

func (r *DeploymentRepo) GetDeployedGatewayIDs(artifactUUID, orgUUID string) ([]string, error)

GetDeployedGatewayIDs returns the gateway IDs that have an active deployment status (DEPLOYED or UNDEPLOYED) for the given artifact. Since the deployment_status table only holds rows for those two states, a plain SELECT is sufficient.

func (*DeploymentRepo) GetDeploymentContentByIDs

func (r *DeploymentRepo) GetDeploymentContentByIDs(deploymentIDs []string, orgUUID string, gatewayUUID string) (map[string]*model.DeploymentContent, error)

GetDeploymentContentByIDs retrieves deployment content for a batch of deployment IDs. Returns a map of deploymentID -> DeploymentContent. This is the only query that joins with the artifacts table to fetch Kind, keeping that concern isolated to the batch sync use case.

func (*DeploymentRepo) GetDeploymentsWithState

func (r *DeploymentRepo) GetDeploymentsWithState(artifactUUID, orgUUID string, gatewayID *string, status *string, maxPerAPIGW int) ([]*model.Deployment, error)

GetDeploymentsWithState retrieves deployments with their lifecycle states. It enforces a soft limit of N records per Gateway, ensuring that the currently DEPLOYED or UNDEPLOYED record is always included regardless of its age.

func (*DeploymentRepo) GetLatestDeploymentTime

func (r *DeploymentRepo) GetLatestDeploymentTime(artifactUUID, orgUUID string) (*time.Time, error)

GetLatestDeploymentTime returns the most recent deployment created_at across all gateways for the given artifact, or nil when the artifact has no deployment records. The DP->CP import flow uses this as the "latest deployment" watermark for its last-in-wins decision: the control plane's working copy is updated only when an incoming push's deployment time is later than every recorded deployment of the artifact.

func (*DeploymentRepo) GetSecretHandlesByGateway

func (r *DeploymentRepo) GetSecretHandlesByGateway(gatewayID, orgUUID string) ([]string, error)

GetSecretHandlesByGateway returns the distinct secret handles referenced by all artifacts currently deployed on the gateway. Sourced from artifact_secret_refs where gateway_id matches — maintained at deploy/undeploy time.

func (*DeploymentRepo) GetStaleTransitionalStatuses

func (r *DeploymentRepo) GetStaleTransitionalStatuses(timeout time.Duration) ([]StaleDeploymentStatus, error)

GetStaleTransitionalStatuses finds deployment_status rows stuck in DEPLOYING/UNDEPLOYING for longer than the given timeout duration.

func (*DeploymentRepo) GetStatus

func (r *DeploymentRepo) GetStatus(artifactUUID, orgUUID, gatewayID string) (string, model.DeploymentStatus, *time.Time, error)

GetStatus retrieves the current deployment status for an artifact on a gateway (lightweight - no content)

func (*DeploymentRepo) GetStatusFull

func (r *DeploymentRepo) GetStatusFull(artifactUUID, orgUUID, gatewayID string) (deploymentID string, status model.DeploymentStatus, performedAt *time.Time, statusReason string, err error)

GetStatusFull retrieves the full deployment status including performed_at and status_reason

func (*DeploymentRepo) GetWithContent

func (r *DeploymentRepo) GetWithContent(deploymentID, artifactUUID, orgUUID string) (*model.Deployment, error)

GetWithContent retrieves a deployment including its content (for rollback/base deployment scenarios)

func (*DeploymentRepo) GetWithState

func (r *DeploymentRepo) GetWithState(deploymentID, artifactUUID, orgUUID string) (*model.Deployment, error)

GetWithState retrieves a deployment with its lifecycle state populated (without content - lightweight)

func (*DeploymentRepo) HasActiveDeployment

func (r *DeploymentRepo) HasActiveDeployment(artifactUUID, orgUUID string) (bool, error)

HasActiveDeployment reports whether the artifact has a DEPLOYED (or in-flight DEPLOYING/UNDEPLOYING) status on any gateway. Used to gate deletion of data-plane-originated artifacts, which may only be deleted once they are undeployed on every gateway they were deployed to.

func (*DeploymentRepo) SetCurrent

func (r *DeploymentRepo) SetCurrent(artifactUUID, orgUUID, gatewayID, deploymentID string, status model.DeploymentStatus) (time.Time, error)

SetCurrent inserts or updates the deployment status record to set the current deployment for an artifact on a gateway

func (*DeploymentRepo) SetCurrentWithDetails

func (r *DeploymentRepo) SetCurrentWithDetails(artifactUUID, orgUUID, gatewayID, deploymentID string, status model.DeploymentStatus, statusDesired string, performedAt *time.Time, statusReason string) (time.Time, error)

SetCurrentWithDetails inserts or updates the deployment status record with full lifecycle fields. statusDesired is the user's intended final state (DEPLOYED/UNDEPLOYED). performedAt, if non-nil, is used as the concurrency token; otherwise defaults to now. statusReason is an optional error code (cleared on new deployments). Also maintains artifact_secret_refs (gateway_id rows): inserts refs on DEPLOYED, deletes them otherwise.

func (*DeploymentRepo) UpdateStatusWithPerformedAtGuard

func (r *DeploymentRepo) UpdateStatusWithPerformedAtGuard(artifactUUID, orgUUID, gatewayID string, newStatus model.DeploymentStatus, statusReason string, performedAt time.Time, requireCurrentStatus []model.DeploymentStatus) (int64, error)

UpdateStatusWithPerformedAtGuard conditionally updates the deployment status only if performed_at matches. Returns the number of rows affected (0 means stale ack was discarded).

type DeploymentRepository

type DeploymentRepository interface {
	// Deployment artifact methods (immutable deployments)
	CreateWithLimitEnforcement(deployment *model.Deployment, hardLimit int) error // Atomic: count, cleanup if needed, create
	GetWithContent(deploymentID, artifactUUID, orgUUID string) (*model.Deployment, error)
	GetWithState(deploymentID, artifactUUID, orgUUID string) (*model.Deployment, error)
	GetDeploymentsWithState(artifactUUID, orgUUID string, gatewayID *string, status *string, maxPerAPIGW int) ([]*model.Deployment, error)
	Delete(deploymentID, artifactUUID, orgUUID string) error
	GetCurrentByGateway(artifactUUID, gatewayID, orgUUID string) (*model.Deployment, error)

	// Deployment status methods (mutable state tracking)
	SetCurrent(artifactUUID, orgUUID, gatewayID, deploymentID string, status model.DeploymentStatus) (updatedAt time.Time, err error)
	SetCurrentWithDetails(artifactUUID, orgUUID, gatewayID, deploymentID string, status model.DeploymentStatus, statusDesired string, performedAt *time.Time, statusReason string) (updatedAt time.Time, err error)
	GetStatus(artifactUUID, orgUUID, gatewayID string) (deploymentID string, status model.DeploymentStatus, updatedAt *time.Time, err error)
	GetStatusFull(artifactUUID, orgUUID, gatewayID string) (deploymentID string, status model.DeploymentStatus, performedAt *time.Time, statusReason string, err error)
	UpdateStatusWithPerformedAtGuard(artifactUUID, orgUUID, gatewayID string, newStatus model.DeploymentStatus, statusReason string, performedAt time.Time, requireCurrentStatus []model.DeploymentStatus) (rowsAffected int64, err error)
	GetStaleTransitionalStatuses(timeout time.Duration) ([]StaleDeploymentStatus, error)
	DeleteStatus(artifactUUID, orgUUID, gatewayID string) error
	GetDeployedGatewayIDs(artifactUUID, orgUUID string) ([]string, error)
	HasActiveDeployment(artifactUUID, orgUUID string) (bool, error)
	GetLatestDeploymentTime(artifactUUID, orgUUID string) (*time.Time, error)

	// Gateway deployment methods
	GetControlPlaneDeploymentsByGateway(gatewayID, orgUUID string, since *time.Time) ([]*model.DeploymentInfo, error)
	GetDeploymentContentByIDs(deploymentIDs []string, orgUUID string, gatewayUUID string) (map[string]*model.DeploymentContent, error)
	// GetSecretHandlesByGateway returns the distinct secret handles referenced by all
	// artifacts currently deployed on a gateway, sourced from artifact_secret_refs (gateway_id rows).
	GetSecretHandlesByGateway(gatewayID, orgUUID string) ([]string, error)
}

DeploymentRepository defines the interface for deployment data operations

func NewDeploymentRepo

func NewDeploymentRepo(db *database.DB, reg *ArtifactTableRegistry) DeploymentRepository

NewDeploymentRepo creates a new deployment repository

type GatewayRepo

type GatewayRepo struct {
	// contains filtered or unexported fields
}

GatewayRepo implements GatewayRepository

func (*GatewayRepo) CountActiveTokens

func (r *GatewayRepo) CountActiveTokens(gatewayId string) (int, error)

CountActiveTokens counts the number of active tokens for a gateway

func (*GatewayRepo) CountGateways added in v0.11.2

func (r *GatewayRepo) CountGateways(orgID, search string) (int, error)

CountGateways returns the total number of gateways, optionally scoped to an organization (empty orgID counts all), independent of any pagination.

func (*GatewayRepo) Create

func (r *GatewayRepo) Create(gateway *model.Gateway) error

Create inserts a new gateway

func (*GatewayRepo) CreateToken

func (r *GatewayRepo) CreateToken(token *model.GatewayToken) error

CreateToken inserts a new token

func (*GatewayRepo) Delete

func (r *GatewayRepo) Delete(gatewayID, organizationID string) error

Delete removes a gateway with organization isolation and cleans up all associations

func (*GatewayRepo) GetActiveTokenByHash

func (r *GatewayRepo) GetActiveTokenByHash(tokenHash string) (*model.GatewayToken, error)

GetActiveTokenByHash retrieves an active token by its hash

func (*GatewayRepo) GetActiveTokensByGatewayUUID

func (r *GatewayRepo) GetActiveTokensByGatewayUUID(gatewayId string) ([]*model.GatewayToken, error)

GetActiveTokensByGatewayUUID retrieves all active tokens for a gateway

func (*GatewayRepo) GetByHandleAndOrgID

func (r *GatewayRepo) GetByHandleAndOrgID(handle, orgID string) (*model.Gateway, error)

GetByHandleAndOrgID checks if a gateway with the given handle exists within an organization

func (*GatewayRepo) GetByOrganizationID

func (r *GatewayRepo) GetByOrganizationID(orgID string) ([]*model.Gateway, error)

GetByOrganizationID retrieves all gateways for an organization

func (*GatewayRepo) GetByUUID

func (r *GatewayRepo) GetByUUID(gatewayId string) (*model.Gateway, error)

GetByUUID retrieves a gateway by ID

func (*GatewayRepo) GetGatewayManifest

func (r *GatewayRepo) GetGatewayManifest(gatewayID string) ([]byte, error)

GetGatewayManifest returns the raw manifest JSON stored for the gateway. Returns nil data (no error) if the gateway exists but has no manifest yet. Returns an error if the gateway row does not exist.

func (*GatewayRepo) GetTokenByUUID

func (r *GatewayRepo) GetTokenByUUID(tokenId string) (*model.GatewayToken, error)

GetTokenByUUID retrieves a specific token by UUID

func (*GatewayRepo) HasGatewayAssociations

func (r *GatewayRepo) HasGatewayAssociations(gatewayID, organizationID string) (bool, error)

HasGatewayAssociations checks if a gateway has any associations

func (*GatewayRepo) HasGatewayAssociationsOrDeployments

func (r *GatewayRepo) HasGatewayAssociationsOrDeployments(gatewayID, organizationID string) (bool, error)

HasGatewayAssociationsOrDeployments checks if a gateway has any associations (deployments or associations)

func (*GatewayRepo) HasGatewayDeployments

func (r *GatewayRepo) HasGatewayDeployments(gatewayID, organizationID string) (bool, error)

HasGatewayDeployments checks if a gateway has any deployments

func (*GatewayRepo) List

func (r *GatewayRepo) List() ([]*model.Gateway, error)

List retrieves all gateways

func (*GatewayRepo) ListPaginated added in v0.11.2

func (r *GatewayRepo) ListPaginated(orgID string, opts ListOptions) ([]*model.Gateway, error)

ListPaginated returns a single page of gateways. Pagination is applied to the gateways table in an inner query BEFORE the endpoint join, so LIMIT/OFFSET count distinct gateways rather than joined endpoint rows. When orgID is empty all organizations are included. Endpoints for the selected page are then aggregated by aggregateGatewayJoinRows.

func (*GatewayRepo) RevokeToken

func (r *GatewayRepo) RevokeToken(tokenId, revokedBy string) error

RevokeToken updates token status to revoked

func (*GatewayRepo) UpdateActiveStatus

func (r *GatewayRepo) UpdateActiveStatus(gatewayId string, isActive bool) error

UpdateActiveStatus updates the is_active status of a gateway

func (*GatewayRepo) UpdateGateway

func (r *GatewayRepo) UpdateGateway(gateway *model.Gateway) error

UpdateGateway updates gateway details

func (*GatewayRepo) UpdateGatewayManifest

func (r *GatewayRepo) UpdateGatewayManifest(gatewayID string, manifest []byte) error

UpdateGatewayManifest persists the gateway manifest JSON to the gateway row.

func (*GatewayRepo) UpdateGatewayVersion

func (r *GatewayRepo) UpdateGatewayVersion(gatewayID, version string) error

UpdateGatewayVersion persists the version string reported by the gateway controller on manifest push.

type GatewayRepository

type GatewayRepository interface {
	// Gateway operations
	Create(gateway *model.Gateway) error
	GetByUUID(gatewayId string) (*model.Gateway, error)
	GetByOrganizationID(orgID string) ([]*model.Gateway, error)
	GetByHandleAndOrgID(handle, orgID string) (*model.Gateway, error)
	List() ([]*model.Gateway, error)
	ListPaginated(orgID string, opts ListOptions) ([]*model.Gateway, error)
	CountGateways(orgID, search string) (int, error)
	Delete(gatewayID, organizationID string) error
	UpdateGateway(gateway *model.Gateway) error
	UpdateActiveStatus(gatewayId string, isActive bool) error

	// Gateway association checking operations
	HasGatewayDeployments(gatewayID, organizationID string) (bool, error)
	HasGatewayAssociations(gatewayID, organizationID string) (bool, error)
	HasGatewayAssociationsOrDeployments(gatewayID, organizationID string) (bool, error)

	// Token operations
	CreateToken(token *model.GatewayToken) error
	GetActiveTokensByGatewayUUID(gatewayId string) ([]*model.GatewayToken, error)
	GetActiveTokenByHash(tokenHash string) (*model.GatewayToken, error)
	GetTokenByUUID(tokenId string) (*model.GatewayToken, error)
	RevokeToken(tokenId, revokedBy string) error
	CountActiveTokens(gatewayId string) (int, error)

	// Manifest operations
	UpdateGatewayManifest(gatewayID string, manifest []byte) error
	GetGatewayManifest(gatewayID string) ([]byte, error)

	// Version update — persists the version reported by the gateway controller on connect.
	UpdateGatewayVersion(gatewayID, version string) error
}

GatewayRepository defines the interface for gateway data access

func NewGatewayRepo

func NewGatewayRepo(db *database.DB) GatewayRepository

NewGatewayRepo creates a new gateway repository

type LLMProviderRepo

type LLMProviderRepo struct {
	// contains filtered or unexported fields
}

func (*LLMProviderRepo) Count

func (r *LLMProviderRepo) Count(orgUUID string) (int, error)

func (*LLMProviderRepo) Create

func (r *LLMProviderRepo) Create(p *model.LLMProvider) error

func (*LLMProviderRepo) Delete

func (r *LLMProviderRepo) Delete(providerID, orgUUID string) error

func (*LLMProviderRepo) EnsureGatewayAssociation

func (r *LLMProviderRepo) EnsureGatewayAssociation(providerUUID, gatewayUUID, orgUUID, deployMetadata string, metadataProvided bool) (string, error)

EnsureGatewayAssociation creates a gateway association for the provider if one does not already exist and resolves the metadata to use for the deployment. See ensureArtifactGatewayAssociation for the full semantics.

func (*LLMProviderRepo) Exists

func (r *LLMProviderRepo) Exists(providerID, orgUUID string) (bool, error)

func (*LLMProviderRepo) GetByID

func (r *LLMProviderRepo) GetByID(providerID, orgUUID string) (*model.LLMProvider, error)

func (*LLMProviderRepo) List

func (r *LLMProviderRepo) List(orgUUID string, limit, offset int) ([]*model.LLMProvider, error)

func (*LLMProviderRepo) Update

func (r *LLMProviderRepo) Update(p *model.LLMProvider) error

type LLMProviderRepository

type LLMProviderRepository interface {
	Create(p *model.LLMProvider) error
	GetByID(providerID, orgUUID string) (*model.LLMProvider, error)
	List(orgUUID string, limit, offset int) ([]*model.LLMProvider, error)
	Count(orgUUID string) (int, error)
	Update(p *model.LLMProvider) error
	Delete(providerID, orgUUID string) error
	Exists(providerID, orgUUID string) (bool, error)
	// EnsureGatewayAssociation creates a gateway association for the provider if one
	// does not already exist and resolves the metadata to use for the deployment.
	EnsureGatewayAssociation(providerUUID, gatewayUUID, orgUUID, deployMetadata string, metadataProvided bool) (string, error)
}

LLMProviderRepository defines the interface for LLM provider persistence

func NewLLMProviderRepo

func NewLLMProviderRepo(db *database.DB) LLMProviderRepository

type LLMProviderTemplateRepo

type LLMProviderTemplateRepo struct {
	// contains filtered or unexported fields
}

func (*LLMProviderTemplateRepo) Count

func (r *LLMProviderTemplateRepo) Count(orgUUID string) (int, error)

func (*LLMProviderTemplateRepo) CountAllVersions

func (r *LLMProviderTemplateRepo) CountAllVersions(orgUUID string) (int, error)

func (*LLMProviderTemplateRepo) CountProvidersUsingTemplate

func (r *LLMProviderTemplateRepo) CountProvidersUsingTemplate(groupID, orgUUID, version string) (int, error)

func (*LLMProviderTemplateRepo) CountVersions

func (r *LLMProviderTemplateRepo) CountVersions(groupID, orgUUID string) (int, error)

func (*LLMProviderTemplateRepo) Create

func (*LLMProviderTemplateRepo) CreateNewVersion

func (r *LLMProviderTemplateRepo) CreateNewVersion(t *model.LLMProviderTemplate) error

func (*LLMProviderTemplateRepo) DeleteVersion

func (r *LLMProviderTemplateRepo) DeleteVersion(groupID, orgUUID, version string) error

func (*LLMProviderTemplateRepo) Exists

func (r *LLMProviderTemplateRepo) Exists(templateID, orgUUID string) (bool, error)

func (*LLMProviderTemplateRepo) GetByID

func (r *LLMProviderTemplateRepo) GetByID(templateID, orgUUID string) (*model.LLMProviderTemplate, error)

func (*LLMProviderTemplateRepo) GetByUUID

func (r *LLMProviderTemplateRepo) GetByUUID(uuid, orgUUID string) (*model.LLMProviderTemplate, error)

func (*LLMProviderTemplateRepo) GetByVersion

func (r *LLMProviderTemplateRepo) GetByVersion(groupID, orgUUID, version string) (*model.LLMProviderTemplate, error)

func (*LLMProviderTemplateRepo) GetGroupID

func (r *LLMProviderTemplateRepo) GetGroupID(handle, orgUUID string) (string, error)

func (*LLMProviderTemplateRepo) List

func (r *LLMProviderTemplateRepo) List(orgUUID string, limit, offset int) ([]*model.LLMProviderTemplate, error)

func (*LLMProviderTemplateRepo) ListAllVersions

func (r *LLMProviderTemplateRepo) ListAllVersions(orgUUID string, limit, offset int) ([]*model.LLMProviderTemplate, error)

func (*LLMProviderTemplateRepo) ListVersions

func (r *LLMProviderTemplateRepo) ListVersions(groupID, orgUUID string, limit, offset int) ([]*model.LLMProviderTemplate, error)

func (*LLMProviderTemplateRepo) ManagedByForHandle

func (r *LLMProviderTemplateRepo) ManagedByForHandle(handle, orgUUID string) (string, error)

func (*LLMProviderTemplateRepo) RenameFamily

func (r *LLMProviderTemplateRepo) RenameFamily(baseHandle, orgUUID, name string) error

func (*LLMProviderTemplateRepo) SetEnabled

func (r *LLMProviderTemplateRepo) SetEnabled(groupID, orgUUID, version string, enabled bool) error

func (*LLMProviderTemplateRepo) Update

type LLMProviderTemplateRepository

type LLMProviderTemplateRepository interface {
	Create(t *model.LLMProviderTemplate) error
	CreateNewVersion(t *model.LLMProviderTemplate) error
	GetByID(templateID, orgUUID string) (*model.LLMProviderTemplate, error)
	GetByUUID(uuid, orgUUID string) (*model.LLMProviderTemplate, error)
	GetByVersion(templateID, orgUUID, version string) (*model.LLMProviderTemplate, error)
	ListVersions(templateID, orgUUID string, limit, offset int) ([]*model.LLMProviderTemplate, error)
	CountVersions(templateID, orgUUID string) (int, error)
	List(orgUUID string, limit, offset int) ([]*model.LLMProviderTemplate, error)
	Count(orgUUID string) (int, error)
	ListAllVersions(orgUUID string, limit, offset int) ([]*model.LLMProviderTemplate, error)
	CountAllVersions(orgUUID string) (int, error)
	Update(t *model.LLMProviderTemplate) error
	RenameFamily(baseHandle, orgUUID, name string) error
	SetEnabled(templateID, orgUUID, version string, enabled bool) error
	DeleteVersion(templateID, orgUUID, version string) error
	Exists(templateID, orgUUID string) (bool, error)
	GetGroupID(handle, orgUUID string) (string, error)
	ManagedByForHandle(handle, orgUUID string) (string, error)
	CountProvidersUsingTemplate(templateID, orgUUID, version string) (int, error)
}

LLMProviderTemplateRepository defines the interface for LLM provider template persistence

func NewLLMProviderTemplateRepo

func NewLLMProviderTemplateRepo(db *database.DB) LLMProviderTemplateRepository

type LLMProxyRepo

type LLMProxyRepo struct {
	// contains filtered or unexported fields
}

func (*LLMProxyRepo) Count

func (r *LLMProxyRepo) Count(orgUUID string) (int, error)

func (*LLMProxyRepo) CountByProject

func (r *LLMProxyRepo) CountByProject(orgUUID, projectUUID string) (int, error)

func (*LLMProxyRepo) CountByProvider

func (r *LLMProxyRepo) CountByProvider(orgUUID, providerUUID string) (int, error)

func (*LLMProxyRepo) Create

func (r *LLMProxyRepo) Create(p *model.LLMProxy) error

func (*LLMProxyRepo) Delete

func (r *LLMProxyRepo) Delete(proxyID, orgUUID string) error

func (*LLMProxyRepo) EnsureGatewayAssociation

func (r *LLMProxyRepo) EnsureGatewayAssociation(proxyUUID, gatewayUUID, orgUUID, deployMetadata string, metadataProvided bool) (string, error)

EnsureGatewayAssociation creates a gateway association for the proxy if one does not already exist and resolves the metadata to use for the deployment. See ensureArtifactGatewayAssociation for the full semantics.

func (*LLMProxyRepo) Exists

func (r *LLMProxyRepo) Exists(proxyID, orgUUID string) (bool, error)

func (*LLMProxyRepo) GetByID

func (r *LLMProxyRepo) GetByID(proxyID, orgUUID string) (*model.LLMProxy, error)

func (*LLMProxyRepo) List

func (r *LLMProxyRepo) List(orgUUID string, limit, offset int) ([]*model.LLMProxy, error)

func (*LLMProxyRepo) ListByProject

func (r *LLMProxyRepo) ListByProject(orgUUID, projectUUID string, limit, offset int) ([]*model.LLMProxy, error)

func (*LLMProxyRepo) ListByProvider

func (r *LLMProxyRepo) ListByProvider(orgUUID, providerUUID string, limit, offset int) ([]*model.LLMProxy, error)

func (*LLMProxyRepo) Update

func (r *LLMProxyRepo) Update(p *model.LLMProxy) error

type LLMProxyRepository

type LLMProxyRepository interface {
	Create(p *model.LLMProxy) error
	GetByID(proxyID, orgUUID string) (*model.LLMProxy, error)
	List(orgUUID string, limit, offset int) ([]*model.LLMProxy, error)
	ListByProject(orgUUID, projectUUID string, limit, offset int) ([]*model.LLMProxy, error)
	ListByProvider(orgUUID, providerID string, limit, offset int) ([]*model.LLMProxy, error)
	Count(orgUUID string) (int, error)
	CountByProject(orgUUID, projectUUID string) (int, error)
	CountByProvider(orgUUID, providerID string) (int, error)
	Update(p *model.LLMProxy) error
	Delete(proxyID, orgUUID string) error
	Exists(proxyID, orgUUID string) (bool, error)
	// EnsureGatewayAssociation creates a gateway association for the proxy if one does
	// not already exist and resolves the metadata to use for the deployment.
	EnsureGatewayAssociation(proxyUUID, gatewayUUID, orgUUID, deployMetadata string, metadataProvided bool) (string, error)
}

LLMProxyRepository defines the interface for LLM proxy persistence

func NewLLMProxyRepo

func NewLLMProxyRepo(db *database.DB) LLMProxyRepository

type ListOptions added in v0.11.2

type ListOptions struct {
	Limit     int
	Offset    int
	SortBy    string // API sort token (e.g. "name", "createdAt"); "" = default
	SortOrder string // "asc" or "desc"; anything else defaults to descending
	Search    string // case-insensitive handle substring; "" = no filter
}

ListOptions carries the pagination, sorting, and search inputs shared by collection list queries. Limit/Offset are already normalized by the handler layer; SortBy/SortOrder/Search are raw client tokens that MUST be resolved through resolveSort / handleSearchClause before touching SQL — they are never interpolated into a query verbatim.

type MCPProxyRepo

type MCPProxyRepo struct {
	// contains filtered or unexported fields
}

MCPProxyRepo handles database operations for MCP proxies

func NewMCPProxyRepo

func NewMCPProxyRepo(db *database.DB) *MCPProxyRepo

NewMCPProxyRepo creates a new MCPProxyRepo instance

func (*MCPProxyRepo) Count

func (r *MCPProxyRepo) Count(orgUUID string) (int, error)

Count returns the total number of MCP proxies for an organization

func (*MCPProxyRepo) CountByProject

func (r *MCPProxyRepo) CountByProject(orgUUID, projectUUID string) (int, error)

CountByProject returns the total number of MCP proxies for a specific project

func (*MCPProxyRepo) Create

func (r *MCPProxyRepo) Create(p *model.MCPProxy) error

Create creates a new MCP proxy in the database

func (*MCPProxyRepo) Delete

func (r *MCPProxyRepo) Delete(handle, orgUUID string) error

Delete deletes an MCP proxy by its handle and organization UUID

func (*MCPProxyRepo) EnsureGatewayAssociation

func (r *MCPProxyRepo) EnsureGatewayAssociation(proxyUUID, gatewayUUID, orgUUID, deployMetadata string, metadataProvided bool) (string, error)

EnsureGatewayAssociation creates a gateway association for the MCP proxy if one does not already exist and resolves the metadata to use for the deployment. See ensureArtifactGatewayAssociation for the full semantics.

func (*MCPProxyRepo) Exists

func (r *MCPProxyRepo) Exists(handle, orgUUID string) (bool, error)

Exists checks if an MCP proxy exists by its handle and organization UUID

func (*MCPProxyRepo) GetByHandle

func (r *MCPProxyRepo) GetByHandle(handle, orgUUID string) (*model.MCPProxy, error)

GetByHandle retrieves an MCP proxy by its handle and organization UUID

func (*MCPProxyRepo) GetByUUID

func (r *MCPProxyRepo) GetByUUID(uuid, orgUUID string) (*model.MCPProxy, error)

GetByUUID retrieves an MCP proxy by its UUID and organization UUID

func (*MCPProxyRepo) List

func (r *MCPProxyRepo) List(orgUUID string, limit, offset int) ([]*model.MCPProxy, error)

List retrieves all MCP proxies for an organization

func (*MCPProxyRepo) ListByProject

func (r *MCPProxyRepo) ListByProject(orgUUID, projectUUID string) ([]*model.MCPProxy, error)

ListByProject retrieves all MCP proxies for a specific project

func (*MCPProxyRepo) Update

func (r *MCPProxyRepo) Update(p *model.MCPProxy) error

Update updates an existing MCP proxy

type MCPProxyRepository

type MCPProxyRepository interface {
	Create(p *model.MCPProxy) error
	GetByHandle(handle, orgUUID string) (*model.MCPProxy, error)
	GetByUUID(uuid, orgUUID string) (*model.MCPProxy, error)
	List(orgUUID string, limit, offset int) ([]*model.MCPProxy, error)
	ListByProject(orgUUID, projectUUID string) ([]*model.MCPProxy, error)
	Count(orgUUID string) (int, error)
	CountByProject(orgUUID, projectUUID string) (int, error)
	Update(p *model.MCPProxy) error
	Delete(handle, orgUUID string) error
	Exists(handle, orgUUID string) (bool, error)
	EnsureGatewayAssociation(proxyUUID, gatewayUUID, orgUUID, deployMetadata string, metadataProvided bool) (string, error)
}

MCPProxyRepository defines the interface for MCP proxy persistence

type OrganizationRepo

type OrganizationRepo struct {
	// contains filtered or unexported fields
}

OrganizationRepo implements OrganizationRepository

func (*OrganizationRepo) CountOrganizations

func (r *OrganizationRepo) CountOrganizations() (int, error)

CountOrganizations returns the total number of organizations, independent of any pagination applied by ListOrganizations.

func (*OrganizationRepo) CreateOrganization

func (r *OrganizationRepo) CreateOrganization(org *model.Organization) error

CreateOrganization inserts a new organization

func (*OrganizationRepo) DeleteOrganization

func (r *OrganizationRepo) DeleteOrganization(orgId string) error

func (*OrganizationRepo) GetOrganizationByHandle

func (r *OrganizationRepo) GetOrganizationByHandle(handle string) (*model.Organization, error)

func (*OrganizationRepo) GetOrganizationByIdOrHandle

func (r *OrganizationRepo) GetOrganizationByIdOrHandle(id, handle string) (*model.Organization, error)

func (*OrganizationRepo) GetOrganizationByIdpOrgRefUUID

func (r *OrganizationRepo) GetOrganizationByIdpOrgRefUUID(idpOrgRefUUID string) (*model.Organization, error)

GetOrganizationByIdpOrgRefUUID looks up an organization by the identity provider's organization UUID (the value stored from the token's org claim). The empty string is never matched, so file-based organizations (which have no IDP reference) are not returned.

func (*OrganizationRepo) GetOrganizationByUUID

func (r *OrganizationRepo) GetOrganizationByUUID(orgId string) (*model.Organization, error)

func (*OrganizationRepo) ListOrganizations

func (r *OrganizationRepo) ListOrganizations(limit, offset int) ([]*model.Organization, error)

func (*OrganizationRepo) UpdateOrganization

func (r *OrganizationRepo) UpdateOrganization(org *model.Organization) error

type OrganizationRepository

type OrganizationRepository interface {
	CreateOrganization(org *model.Organization) error
	GetOrganizationByIdOrHandle(id, handle string) (*model.Organization, error)
	GetOrganizationByUUID(orgId string) (*model.Organization, error)
	GetOrganizationByHandle(handle string) (*model.Organization, error)
	GetOrganizationByIdpOrgRefUUID(idpOrgRefUUID string) (*model.Organization, error)
	UpdateOrganization(org *model.Organization) error
	DeleteOrganization(orgId string) error
	ListOrganizations(limit, offset int) ([]*model.Organization, error)
	CountOrganizations() (int, error)
}

OrganizationRepository defines the interface for organization data access

func NewOrganizationRepo

func NewOrganizationRepo(db *database.DB) OrganizationRepository

NewOrganizationRepo creates a new organization repository

type ProjectRepo

type ProjectRepo struct {
	// contains filtered or unexported fields
}

ProjectRepo implements ProjectRepository

func (*ProjectRepo) CountProjects added in v0.11.2

func (r *ProjectRepo) CountProjects(orgID, search string) (int, error)

CountProjects returns the total number of projects in an organization, independent of any pagination applied by ListProjects.

func (*ProjectRepo) CreateProject

func (r *ProjectRepo) CreateProject(project *model.Project) error

CreateProject inserts a new project

func (*ProjectRepo) DeleteProject

func (r *ProjectRepo) DeleteProject(projectId string) error

DeleteProject removes a project

func (*ProjectRepo) GetProjectByHandleAndOrgID

func (r *ProjectRepo) GetProjectByHandleAndOrgID(handle, orgID string) (*model.Project, error)

GetProjectByHandleAndOrgID retrieves a project by handle within an organization

func (*ProjectRepo) GetProjectByNameAndOrgID

func (r *ProjectRepo) GetProjectByNameAndOrgID(name, orgID string) (*model.Project, error)

GetProjectByNameAndOrgID retrieves a project by name within an organization

func (*ProjectRepo) GetProjectByUUID

func (r *ProjectRepo) GetProjectByUUID(projectId string) (*model.Project, error)

GetProjectByUUID retrieves a project by ID

func (*ProjectRepo) GetProjectsByOrganizationID

func (r *ProjectRepo) GetProjectsByOrganizationID(orgID string) ([]*model.Project, error)

GetProjectsByOrganizationID retrieves all projects for an organization

func (*ProjectRepo) ListProjects

func (r *ProjectRepo) ListProjects(orgID string, opts ListOptions) ([]*model.Project, error)

ListProjects retrieves projects with pagination

func (*ProjectRepo) UpdateProject

func (r *ProjectRepo) UpdateProject(project *model.Project) error

UpdateProject modifies an existing project

type ProjectRepository

type ProjectRepository interface {
	CreateProject(project *model.Project) error
	GetProjectByUUID(projectId string) (*model.Project, error)
	GetProjectByNameAndOrgID(name, orgID string) (*model.Project, error)
	GetProjectByHandleAndOrgID(handle, orgID string) (*model.Project, error)
	GetProjectsByOrganizationID(orgID string) ([]*model.Project, error)
	UpdateProject(project *model.Project) error
	DeleteProject(projectId string) error
	ListProjects(orgID string, opts ListOptions) ([]*model.Project, error)
	CountProjects(orgID, search string) (int, error)
}

ProjectRepository defines the interface for project data access

func NewProjectRepo

func NewProjectRepo(db *database.DB) ProjectRepository

NewProjectRepo creates a new project repository

type SecretRepo

type SecretRepo struct {
	// contains filtered or unexported fields
}

func (*SecretRepo) Count

func (r *SecretRepo) Count(orgID string) (int, error)

func (*SecretRepo) Create

func (r *SecretRepo) Create(s *model.Secret) error

func (*SecretRepo) Exists

func (r *SecretRepo) Exists(orgID, handle string) (bool, error)

func (*SecretRepo) FindRefs

func (r *SecretRepo) FindRefs(orgID, handle string) ([]model.SecretReference, error)

func (*SecretRepo) FindRefsAndSoftDelete

func (r *SecretRepo) FindRefsAndSoftDelete(orgID, handle, updatedBy string) ([]model.SecretReference, error)

FindRefsAndSoftDelete checks for active artifact references and deprecates the secret in a single transaction, eliminating the TOCTOU window. Returns the references without deprecating if any are found.

func (*SecretRepo) GetByHandle

func (r *SecretRepo) GetByHandle(orgID, handle string) (*model.Secret, error)

func (*SecretRepo) List

func (r *SecretRepo) List(orgID string, limit, offset int, updatedAfter *time.Time) ([]*model.Secret, error)

func (*SecretRepo) ListByHandles

func (r *SecretRepo) ListByHandles(orgID string, handles []string, updatedAfter *time.Time) ([]*model.Secret, error)

ListByHandles returns secrets for the given org whose handle is in the provided list. If updatedAfter is set, only secrets updated after that time are returned. Returns nil (not an error) when handles is empty.

func (*SecretRepo) Update

func (r *SecretRepo) Update(s *model.Secret) error

type SecretRepository

type SecretRepository interface {
	Create(s *model.Secret) error
	GetByHandle(orgID, handle string) (*model.Secret, error)
	List(orgID string, limit, offset int, updatedAfter *time.Time) ([]*model.Secret, error)
	ListByHandles(orgID string, handles []string, updatedAfter *time.Time) ([]*model.Secret, error)
	Count(orgID string) (int, error)
	Update(s *model.Secret) error
	FindRefsAndSoftDelete(orgID, handle, updatedBy string) ([]model.SecretReference, error)
	FindRefs(orgID, handle string) ([]model.SecretReference, error)
	Exists(orgID, handle string) (bool, error)
}

SecretRepository defines the interface for secret persistence.

func NewSecretRepo

func NewSecretRepo(db *database.DB) SecretRepository

type StaleDeploymentStatus

type StaleDeploymentStatus struct {
	ArtifactUUID     string
	OrganizationUUID string
	GatewayUUID      string
	DeploymentID     string
	Status           model.DeploymentStatus
	StatusDesired    string
	PerformedAt      time.Time
}

StaleDeploymentStatus represents a deployment status row that has been in a transitional state too long

type SubscriptionPlanRepo

type SubscriptionPlanRepo struct {
	// contains filtered or unexported fields
}

SubscriptionPlanRepo implements SubscriptionPlanRepository

func (*SubscriptionPlanRepo) CountByOrganization added in v0.11.2

func (r *SubscriptionPlanRepo) CountByOrganization(orgUUID string) (int, error)

CountByOrganization returns the total number of subscription plans in an organization, independent of any pagination applied by ListByOrganization.

func (*SubscriptionPlanRepo) Create

Create inserts a new subscription plan together with its single throttling limit row.

func (*SubscriptionPlanRepo) Delete

func (r *SubscriptionPlanRepo) Delete(planID, orgUUID string) error

Delete removes a subscription plan by ID and organization

func (*SubscriptionPlanRepo) ExistsByHandleAndOrg

func (r *SubscriptionPlanRepo) ExistsByHandleAndOrg(handle, orgUUID string) (bool, error)

ExistsByHandleAndOrg returns true if a plan with the given handle exists in the organization

func (*SubscriptionPlanRepo) GetByHandleAndOrg

func (r *SubscriptionPlanRepo) GetByHandleAndOrg(handle, orgUUID string) (*model.SubscriptionPlan, error)

GetByHandleAndOrg retrieves a subscription plan by handle and organization

func (*SubscriptionPlanRepo) GetByID

func (r *SubscriptionPlanRepo) GetByID(planID, orgUUID string) (*model.SubscriptionPlan, error)

GetByID retrieves a subscription plan by ID and organization

func (*SubscriptionPlanRepo) GetByIDs

func (r *SubscriptionPlanRepo) GetByIDs(planIDs []string, orgUUID string) (map[string]string, error)

GetByIDs returns a map of plan UUID to plan name for the given IDs in the organization. Used for bulk lookup to avoid N+1 queries. Returns empty map for empty input.

func (*SubscriptionPlanRepo) ListByOrganization

func (r *SubscriptionPlanRepo) ListByOrganization(orgUUID string, limit, offset int) ([]*model.SubscriptionPlan, error)

ListByOrganization returns subscription plans for an organization with pagination

func (*SubscriptionPlanRepo) Update

Update updates an existing subscription plan

type SubscriptionPlanRepository

type SubscriptionPlanRepository interface {
	Create(plan *model.SubscriptionPlan) error
	GetByID(planID, orgUUID string) (*model.SubscriptionPlan, error)
	GetByIDs(planIDs []string, orgUUID string) (map[string]string, error)
	GetByHandleAndOrg(handle, orgUUID string) (*model.SubscriptionPlan, error)
	ListByOrganization(orgUUID string, limit, offset int) ([]*model.SubscriptionPlan, error)
	CountByOrganization(orgUUID string) (int, error)
	Update(plan *model.SubscriptionPlan) error
	Delete(planID, orgUUID string) error
	ExistsByHandleAndOrg(handle, orgUUID string) (bool, error)
}

SubscriptionPlanRepository defines the interface for subscription plan data operations

func NewSubscriptionPlanRepo

func NewSubscriptionPlanRepo(db *database.DB) SubscriptionPlanRepository

NewSubscriptionPlanRepo creates a new subscription plan repository

type SubscriptionRepo

type SubscriptionRepo struct {
	// contains filtered or unexported fields
}

SubscriptionRepo implements SubscriptionRepository

func (*SubscriptionRepo) CountByFilters

func (r *SubscriptionRepo) CountByFilters(orgUUID string, apiUUID *string, subscriberID *string, applicationID *string, status *string) (int, error)

CountByFilters returns the total count of subscriptions matching the same filters as ListByFilters.

func (*SubscriptionRepo) Create

func (r *SubscriptionRepo) Create(sub *model.Subscription) error

Create inserts a new subscription. The token is encrypted for storage and hashed for uniqueness; sub.SubscriptionToken retains the raw value for the create response.

func (*SubscriptionRepo) Delete

func (r *SubscriptionRepo) Delete(subscriptionID, orgUUID string) error

Delete removes a subscription by ID and organization

func (*SubscriptionRepo) ExistsByAPIAndSubscriber

func (r *SubscriptionRepo) ExistsByAPIAndSubscriber(apiUUID, subscriberID, orgUUID string) (bool, error)

ExistsByAPIAndSubscriber returns true if a subscription exists for the given API and subscriber.

func (*SubscriptionRepo) GetByID

func (r *SubscriptionRepo) GetByID(subscriptionID, orgUUID string) (*model.Subscription, error)

GetByID retrieves a subscription by ID and organization. Decrypts subscription_token for API response.

func (*SubscriptionRepo) ListByFilters

func (r *SubscriptionRepo) ListByFilters(orgUUID string, apiUUID *string, subscriberID *string, applicationID *string, status *string, limit, offset int) ([]*model.Subscription, error)

ListByFilters returns subscriptions filtered by API/subscriber and/or application for an organization. Decrypts subscription_token for each row.

func (*SubscriptionRepo) Update

func (r *SubscriptionRepo) Update(sub *model.Subscription) error

Update updates an existing subscription with all mutable fields.

func (*SubscriptionRepo) UpdateToken

func (r *SubscriptionRepo) UpdateToken(subscriptionID, orgUUID, newToken string) error

UpdateToken rotates a subscription's token: the new value is hashed (for the uniqueness/lookup column) and encrypted (for at-rest storage), mirroring Create. Returns ErrSubscriptionNotFound when no row matches.

type SubscriptionRepository

type SubscriptionRepository interface {
	Create(sub *model.Subscription) error
	GetByID(subscriptionID, orgUUID string) (*model.Subscription, error)
	// ListByFilters returns subscriptions filtered by API and/or application for an organization.
	// If apiUUID is nil, all APIs are considered. If applicationID is nil, all applications are considered.
	ListByFilters(orgUUID string, apiUUID *string, subscriberID *string, applicationID *string, status *string, limit, offset int) ([]*model.Subscription, error)
	// CountByFilters returns the total count of subscriptions matching the same filters as ListByFilters.
	CountByFilters(orgUUID string, apiUUID *string, subscriberID *string, applicationID *string, status *string) (int, error)
	Update(sub *model.Subscription) error
	UpdateToken(subscriptionID, orgUUID, newToken string) error
	Delete(subscriptionID, orgUUID string) error
	ExistsByAPIAndSubscriber(apiUUID, subscriberID, orgUUID string) (bool, error)
}

SubscriptionRepository defines the interface for application-level subscription data operations

func NewSubscriptionRepo

func NewSubscriptionRepo(db *database.DB) SubscriptionRepository

NewSubscriptionRepo creates a new subscription repository

type UserIdentityMappingRepo

type UserIdentityMappingRepo struct {
	// contains filtered or unexported fields
}

UserIdentityMappingRepo persists the internal-UUID <-> IdP-identity mapping.

func (*UserIdentityMappingRepo) GetOrCreateUUID

func (r *UserIdentityMappingRepo) GetOrCreateUUID(identity string) (string, error)

GetOrCreateUUID returns the internal platform UUID mapped to the given resolved actor identity, creating the mapping on first use. An empty identity returns an empty UUID without creating a row — callers that must never fail on a missing identity (e.g. anonymous writes) mint their own standalone UUID instead (see service.IdentityService.InternalUserID); this method never stores a row with an empty idp_id.

func (*UserIdentityMappingRepo) GetSubByUUID

func (r *UserIdentityMappingRepo) GetSubByUUID(uuid string) (string, bool, error)

GetSubByUUID returns the resolved actor identity mapped to uuid, or found=false if uuid has no mapping (a "hanging" UUID — e.g. an anonymous write, or a mapping that was removed).

func (*UserIdentityMappingRepo) GetSubsByUUIDs

func (r *UserIdentityMappingRepo) GetSubsByUUIDs(uuids []string) (map[string]string, error)

GetSubsByUUIDs batch-resolves multiple UUIDs to their mapped identity in a single query, for list endpoints (avoids N+1). UUIDs with no mapping are absent from the returned map.

type UserIdentityMappingRepository

type UserIdentityMappingRepository interface {
	GetOrCreateUUID(identity string) (string, error)
	// GetSubByUUID returns the resolved actor identity mapped to uuid, or
	// found=false if uuid has no mapping (a "hanging" UUID).
	GetSubByUUID(uuid string) (identity string, found bool, err error)
	// GetSubsByUUIDs batch-resolves multiple UUIDs to their mapped identity in
	// a single query (avoids N+1 on list endpoints). UUIDs with no mapping are
	// absent from the returned map.
	GetSubsByUUIDs(uuids []string) (map[string]string, error)
}

UserIdentityMappingRepository defines the interface for internal-UUID <-> IdP-identity mapping persistence.

func NewUserIdentityMappingRepo

func NewUserIdentityMappingRepo(db *database.DB) UserIdentityMappingRepository

NewUserIdentityMappingRepo creates a new UserIdentityMappingRepo.

type UserOrganizationMappingRepo

type UserOrganizationMappingRepo struct {
	// contains filtered or unexported fields
}

UserOrganizationMappingRepo persists user<->organization membership rows.

func (*UserOrganizationMappingRepo) AddMembership

func (r *UserOrganizationMappingRepo) AddMembership(userUUID, orgUUID string) error

AddMembership records that userUUID has onboarded to orgUUID. Idempotent: a duplicate (userUUID, orgUUID) pair is treated as success, not an error.

func (*UserOrganizationMappingRepo) DeleteByOrg

func (r *UserOrganizationMappingRepo) DeleteByOrg(tx *sql.Tx, orgUUID string) error

DeleteByOrg removes all membership rows for orgUUID, within tx. Callers must run this before deleting the referenced organizations row (no ON DELETE CASCADE on that FK by design).

func (*UserOrganizationMappingRepo) DeleteByUser

func (r *UserOrganizationMappingRepo) DeleteByUser(tx *sql.Tx, userUUID string) error

DeleteByUser removes all membership rows for userUUID, within tx. Callers must run this before deleting the referenced user_idp_references row (no ON DELETE CASCADE on that FK by design).

type UserOrganizationMappingRepository

type UserOrganizationMappingRepository interface {
	// AddMembership records that userUUID has onboarded to orgUUID. Idempotent:
	// a duplicate (userUUID, orgUUID) pair is a no-op, not an error.
	AddMembership(userUUID, orgUUID string) error
	// DeleteByUser removes all membership rows for userUUID, within tx.
	DeleteByUser(tx *sql.Tx, userUUID string) error
	// DeleteByOrg removes all membership rows for orgUUID, within tx.
	DeleteByOrg(tx *sql.Tx, orgUUID string) error
}

UserOrganizationMappingRepository defines the interface for user<->organization membership persistence. Populate-only today (no reader depends on it). Both FKs are declared without ON DELETE CASCADE; DeleteByUser/DeleteByOrg exist so callers can perform the cascade in application code, in the same transaction as the parent delete.

func NewUserOrganizationMappingRepo

func NewUserOrganizationMappingRepo(db *database.DB) UserOrganizationMappingRepository

NewUserOrganizationMappingRepo creates a new UserOrganizationMappingRepo.

type WebBrokerAPIRepository

type WebBrokerAPIRepository interface {
	Create(api *model.WebBrokerAPI) error
	GetByHandle(handle, orgUUID string) (*model.WebBrokerAPI, error)
	GetByUUID(uuid, orgUUID string) (*model.WebBrokerAPI, error)
	List(orgUUID, projectUUID string, limit, offset int) ([]*model.WebBrokerAPI, error)
	Count(orgUUID string) (int, error)
	CountByProject(orgUUID, projectUUID string) (int, error)
	Update(api *model.WebBrokerAPI) error
	Delete(handle, orgUUID string) error
	Exists(handle, orgUUID string) (bool, error)
}

WebBrokerAPIRepository defines the interface for WebBroker API persistence

type WebSubAPIHmacSecretRepository

type WebSubAPIHmacSecretRepository interface {
	Create(secret *model.WebSubAPIHmacSecret) error
	GetByArtifactAndName(artifactUUID, name string) (*model.WebSubAPIHmacSecret, error)
	ListByArtifact(artifactUUID string) ([]*model.WebSubAPIHmacSecret, error)
	Update(secret *model.WebSubAPIHmacSecret) error
	Delete(artifactUUID, name string) error
}

WebSubAPIHmacSecretRepository defines the interface for WebSub API HMAC secret persistence

type WebSubAPIRepository

type WebSubAPIRepository interface {
	Create(api *model.WebSubAPI) error
	GetByHandle(handle, orgUUID string) (*model.WebSubAPI, error)
	GetByUUID(uuid, orgUUID string) (*model.WebSubAPI, error)
	List(orgUUID, projectUUID string, limit, offset int) ([]*model.WebSubAPI, error)
	Count(orgUUID string) (int, error)
	CountByProject(orgUUID, projectUUID string) (int, error)
	Update(api *model.WebSubAPI) error
	Delete(handle, orgUUID string) error
	Exists(handle, orgUUID string) (bool, error)
}

WebSubAPIRepository defines the interface for WebSub API persistence

Jump to

Keyboard shortcuts

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