Documentation
¶
Index ¶
- Variables
- type CreateParams
- type CredentialMetadata
- type DataSource
- type MarkSchemaImportFailedParams
- type MarkTestSuccessParams
- type ProviderAccount
- type Repository
- type RepositoryWithLogging
- func (_d RepositoryWithLogging) Create(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, params *CreateParams) (dp1 *DataSource, err error)
- func (_d RepositoryWithLogging) DataSourceHasProjectBackendReferences(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (b1 bool, err error)
- func (_d RepositoryWithLogging) Delete(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
- func (_d RepositoryWithLogging) FindBySlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (dp1 *DataSource, err error)
- func (_d RepositoryWithLogging) IsSlugReserved(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (b1 bool, err error)
- func (_d RepositoryWithLogging) ListByOrg(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, ...) (dpa1 []*DataSource, err error)
- func (_d RepositoryWithLogging) LockDataSourceForUpdate(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
- func (_d RepositoryWithLogging) MarkTestFailure(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (dp1 *DataSource, err error)
- func (_d RepositoryWithLogging) MarkTestSuccess(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (dp1 *DataSource, err error)
- func (_d RepositoryWithLogging) Restore(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
- func (_d RepositoryWithLogging) SetReadOnly(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (err error)
- func (_d RepositoryWithLogging) Update(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (dp1 *DataSource, err error)
- func (_d RepositoryWithLogging) UpdateCredentials(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (dp1 *DataSource, err error)
- type SchemaImportDiagnostic
- type SchemaImportState
- type SchemaMetadata
- type SchemaMetadataRepository
- type SchemaMetadataRepositoryWithLogging
- func (_d SchemaMetadataRepositoryWithLogging) DeleteByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
- func (_d SchemaMetadataRepositoryWithLogging) FindByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (sp1 *SchemaMetadata, err error)
- func (_d SchemaMetadataRepositoryWithLogging) FindCurrentImportAttemptByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (sp1 *SchemaImportState, err error)
- func (_d SchemaMetadataRepositoryWithLogging) FindImportStateByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (sp1 *SchemaImportState, err error)
- func (_d SchemaMetadataRepositoryWithLogging) MarkImportFailedByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (sp1 *SchemaImportState, err error)
- func (_d SchemaMetadataRepositoryWithLogging) MarkImportReadyByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (sp1 *SchemaImportState, err error)
- func (_d SchemaMetadataRepositoryWithLogging) ResetImportByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (sp1 *SchemaImportState, err error)
- func (_d SchemaMetadataRepositoryWithLogging) StartImportByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (sp1 *SchemaImportState, err error)
- func (_d SchemaMetadataRepositoryWithLogging) UpsertByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, ...) (sp1 *SchemaMetadata, err error)
- type UpdateCredentialsParams
- type UpdateParams
- type UpsertSchemaMetadataParams
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDataSourceNotFound indicates that the data source does not exist. ErrDataSourceNotFound = xerror.NotFound(xerror.DataSource) // ErrDataSourceUsedAsProjectBackend indicates the data source is still referenced by a project backend. ErrDataSourceUsedAsProjectBackend = xerror.InvalidInput(xerror.DataSource). Detail("data source is used as a project pipeline backend") // ErrSlugTaken indicates that the slug is already in use within the organization. ErrSlugTaken = xerror.AlreadyExists(xerror.DataSource) // ErrConnectionTestConflict indicates that the tested data source changed before the outcome was stored. ErrConnectionTestConflict = xerror.New( xerror.KindAlreadyExists, "DATA_SOURCE_CONNECTION_TEST_CONFLICT", "data source changed during connection test", ) // ErrSchemaMetadataNotFound indicates that cached schema metadata does not exist. ErrSchemaMetadataNotFound = xerror.NotFound(xerror.SchemaMetadata) // ErrSchemaImportAttemptNotCurrent indicates that a queued import attempt is stale. ErrSchemaImportAttemptNotCurrent = xerror.New( xerror.KindNotFound, "DATA_SOURCE_SCHEMA_IMPORT_ATTEMPT_NOT_CURRENT", "data source schema import attempt not current", ) )
Functions ¶
This section is empty.
Types ¶
type CreateParams ¶
type CreateParams struct {
Slug slug.Slug
Name string
Type model.DataSourceType
ConfigJSON json.RawMessage
CredentialSlug slug.Slug
ReadOnly bool
}
CreateParams contains parameters for creating a data source.
type CredentialMetadata ¶
type CredentialMetadata struct {
Slug slug.Slug `json:"slug"`
Kind string `json:"kind"`
Status string `json:"status"`
Provider string `json:"provider"`
UpdatedAt time.Time `json:"updated_at"`
AccessTokenExpiresAt *time.Time `json:"access_token_expires_at"`
Scopes []string `json:"scopes"`
Account ProviderAccount `json:"account"`
LastRefreshedAt *time.Time `json:"last_refreshed_at"`
RevokedAt *time.Time `json:"revoked_at"`
FailureCode string `json:"failure_code"`
FailureMessage string `json:"failure_message"`
}
CredentialMetadata contains only the safe lifecycle fields needed with persisted data sources.
type DataSource ¶
type DataSource struct {
OrganizationGitLabConnection bool
Slug slug.Slug
Name string
Type model.DataSourceType
Config json.RawMessage
EncryptedCredentials []byte
IsActive bool
ReadOnly bool
SchemaImportStatus model.DataSourceSchemaImportStatus
SchemaImportDiagnostic *SchemaImportDiagnostic
SchemaImportStartedAt *time.Time
SchemaImportFinishedAt *time.Time
LastTestedAt *time.Time
TestError *string
ConnectionTestRevision int64
Schema json.RawMessage
CreatedAt time.Time
UpdatedAt time.Time
Credential *CredentialMetadata
}
DataSource represents a registered data source.
type MarkSchemaImportFailedParams ¶
type MarkSchemaImportFailedParams struct {
AttemptID string
ErrorCode string
ErrorMessage string
FinishedAt time.Time
}
MarkSchemaImportFailedParams stores the sanitized terminal failure from one import attempt.
type MarkTestSuccessParams ¶
type ProviderAccount ¶
type ProviderAccount struct {
ID string `json:"ID"`
Name string `json:"Name"`
Email string `json:"Email"`
}
ProviderAccount contains the safe provider identity metadata persisted with an OAuth grant.
type Repository ¶
type Repository interface {
// Create inserts a new data source and returns it.
Create(
ctx context.Context,
tx postgres.DBTX,
orgSlug slug.Slug,
params *CreateParams,
) (*DataSource, error)
// FindBySlug fetches a data source by its slug within an organization.
FindBySlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
) (*DataSource, error)
// IsSlugReserved reports whether an active or soft-deleted data source reserves the slug.
IsSlugReserved(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug slug.Slug) (bool, error)
// ListByOrg lists all data sources in an organization.
ListByOrg(
ctx context.Context,
tx postgres.DBTX,
orgSlug slug.Slug,
req model.ListRequest,
) ([]*DataSource, error)
// Update updates an existing data source by slug.
Update(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
params *UpdateParams,
) (*DataSource, error)
// UpdateCredentials updates credentials for an existing data source by slug.
UpdateCredentials(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
params *UpdateCredentialsParams,
) (*DataSource, error)
// MarkTestSuccess marks a data source as active and stores the introspected schema.
MarkTestSuccess(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
params *MarkTestSuccessParams,
) (*DataSource, error)
// MarkTestFailure marks a data source as inactive and records the test error.
MarkTestFailure(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
expectedRevision int64,
errMsg string,
schema json.RawMessage,
) (*DataSource, error)
// Delete soft-deletes a data source by slug.
Delete(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug slug.Slug) error
// DataSourceHasProjectBackendReferences reports whether any project uses this data source as its pipeline backend.
DataSourceHasProjectBackendReferences(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug slug.Slug) (bool, error)
// LockDataSourceForUpdate locks an active data source row for update within the current transaction.
LockDataSourceForUpdate(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug slug.Slug) error
// Restore clears the deletion tombstone for a data source by slug.
Restore(ctx context.Context, tx postgres.DBTX, orgSlug, dsSlug slug.Slug) error
// SetReadOnly sets the read_only flag for a data source.
SetReadOnly(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
readOnly bool,
) error
}
Repository provides access to data source data.
func NewRepositoryWithLogging ¶
func NewRepositoryWithLogging(base Repository, logger *slog.Logger) Repository
NewRepositoryWithLogging wraps base with method completion logging.
type RepositoryWithLogging ¶
type RepositoryWithLogging struct {
// contains filtered or unexported fields
}
RepositoryWithLogging implements Repository with method completion logging.
func (RepositoryWithLogging) Create ¶
func (_d RepositoryWithLogging) Create(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, params *CreateParams) (dp1 *DataSource, err error)
Create implements Repository.
func (RepositoryWithLogging) DataSourceHasProjectBackendReferences ¶
func (_d RepositoryWithLogging) DataSourceHasProjectBackendReferences(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (b1 bool, err error)
DataSourceHasProjectBackendReferences implements Repository.
func (RepositoryWithLogging) Delete ¶
func (_d RepositoryWithLogging) Delete(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
Delete implements Repository.
func (RepositoryWithLogging) FindBySlug ¶
func (_d RepositoryWithLogging) FindBySlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (dp1 *DataSource, err error)
FindBySlug implements Repository.
func (RepositoryWithLogging) IsSlugReserved ¶
func (_d RepositoryWithLogging) IsSlugReserved(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (b1 bool, err error)
IsSlugReserved implements Repository.
func (RepositoryWithLogging) ListByOrg ¶
func (_d RepositoryWithLogging) ListByOrg(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, req model.ListRequest) (dpa1 []*DataSource, err error)
ListByOrg implements Repository.
func (RepositoryWithLogging) LockDataSourceForUpdate ¶
func (_d RepositoryWithLogging) LockDataSourceForUpdate(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
LockDataSourceForUpdate implements Repository.
func (RepositoryWithLogging) MarkTestFailure ¶
func (_d RepositoryWithLogging) MarkTestFailure(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, expectedRevision int64, errMsg string, schema json.RawMessage) (dp1 *DataSource, err error)
MarkTestFailure implements Repository.
func (RepositoryWithLogging) MarkTestSuccess ¶
func (_d RepositoryWithLogging) MarkTestSuccess(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, params *MarkTestSuccessParams) (dp1 *DataSource, err error)
MarkTestSuccess implements Repository.
func (RepositoryWithLogging) Restore ¶
func (_d RepositoryWithLogging) Restore(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
Restore implements Repository.
func (RepositoryWithLogging) SetReadOnly ¶
func (_d RepositoryWithLogging) SetReadOnly(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, readOnly bool) (err error)
SetReadOnly implements Repository.
func (RepositoryWithLogging) Update ¶
func (_d RepositoryWithLogging) Update(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, params *UpdateParams) (dp1 *DataSource, err error)
Update implements Repository.
func (RepositoryWithLogging) UpdateCredentials ¶
func (_d RepositoryWithLogging) UpdateCredentials(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, params *UpdateCredentialsParams) (dp1 *DataSource, err error)
UpdateCredentials implements Repository.
type SchemaImportDiagnostic ¶
SchemaImportDiagnostic contains safe operator-facing import failure details.
type SchemaImportState ¶
type SchemaImportState struct {
DataSourceSlug slug.Slug
Status model.DataSourceSchemaImportStatus
Diagnostic *SchemaImportDiagnostic
StartedAt *time.Time
FinishedAt *time.Time
// Started is true when this call transitioned the import into importing instead of reusing an in-flight attempt.
Started bool
}
SchemaImportState represents the durable schema import lifecycle for one data source.
type SchemaMetadata ¶
type SchemaMetadata struct {
Slug slug.Slug
SchemaData json.RawMessage
CreatedAt time.Time
UpdatedAt time.Time
}
SchemaMetadata represents cached introspected schema for a data source.
type SchemaMetadataRepository ¶
type SchemaMetadataRepository interface {
FindByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
) (*SchemaMetadata, error)
DeleteByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
) error
UpsertByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
params *UpsertSchemaMetadataParams,
) (*SchemaMetadata, error)
FindImportStateByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
) (*SchemaImportState, error)
StartImportByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
attemptID string,
startedAt time.Time,
) (*SchemaImportState, error)
FindCurrentImportAttemptByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
attemptID string,
) (*SchemaImportState, error)
MarkImportReadyByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
attemptID string,
finishedAt time.Time,
) (*SchemaImportState, error)
MarkImportFailedByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
params *MarkSchemaImportFailedParams,
) (*SchemaImportState, error)
ResetImportByDataSourceSlug(
ctx context.Context,
tx postgres.DBTX,
orgSlug, dsSlug slug.Slug,
) (*SchemaImportState, error)
}
SchemaMetadataRepository provides access to schema metadata persistence.
func NewSchemaMetadataRepository ¶
func NewSchemaMetadataRepository() SchemaMetadataRepository
func NewSchemaMetadataRepositoryWithLogging ¶
func NewSchemaMetadataRepositoryWithLogging(base SchemaMetadataRepository, logger *slog.Logger) SchemaMetadataRepository
NewSchemaMetadataRepositoryWithLogging wraps base with method completion logging.
type SchemaMetadataRepositoryWithLogging ¶
type SchemaMetadataRepositoryWithLogging struct {
// contains filtered or unexported fields
}
SchemaMetadataRepositoryWithLogging implements SchemaMetadataRepository with method completion logging.
func (SchemaMetadataRepositoryWithLogging) DeleteByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) DeleteByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (err error)
DeleteByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) FindByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) FindByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (sp1 *SchemaMetadata, err error)
FindByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) FindCurrentImportAttemptByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) FindCurrentImportAttemptByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, attemptID string) (sp1 *SchemaImportState, err error)
FindCurrentImportAttemptByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) FindImportStateByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) FindImportStateByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (sp1 *SchemaImportState, err error)
FindImportStateByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) MarkImportFailedByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) MarkImportFailedByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, params *MarkSchemaImportFailedParams) (sp1 *SchemaImportState, err error)
MarkImportFailedByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) MarkImportReadyByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) MarkImportReadyByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, attemptID string, finishedAt time.Time) (sp1 *SchemaImportState, err error)
MarkImportReadyByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) ResetImportByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) ResetImportByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug) (sp1 *SchemaImportState, err error)
ResetImportByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) StartImportByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) StartImportByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, attemptID string, startedAt time.Time) (sp1 *SchemaImportState, err error)
StartImportByDataSourceSlug implements SchemaMetadataRepository.
func (SchemaMetadataRepositoryWithLogging) UpsertByDataSourceSlug ¶
func (_d SchemaMetadataRepositoryWithLogging) UpsertByDataSourceSlug(ctx context.Context, tx postgres.DBTX, orgSlug slug.Slug, dsSlug slug.Slug, params *UpsertSchemaMetadataParams) (sp1 *SchemaMetadata, err error)
UpsertByDataSourceSlug implements SchemaMetadataRepository.
type UpdateCredentialsParams ¶
UpdateCredentialsParams contains parameters for updating data source credentials.
type UpdateParams ¶
type UpdateParams struct {
Name string
ConfigJSON json.RawMessage
IsActive *bool
ReadOnly bool
ReadOnlySet bool
}
UpdateParams contains parameters for updating a data source.
type UpsertSchemaMetadataParams ¶
type UpsertSchemaMetadataParams struct {
SchemaData json.RawMessage
}