plugin

package
v2.0.0-...-2631c5f Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GoOSLinux   = "linux"
	GoOSWindows = "windows"
	GoOSDarwin  = "darwin"

	GoArchAmd64 = "amd64"
	GoArchArm64 = "arm64"
)

Variables

View Source
var DefaultBuildTargets = []BuildTarget{
	{OS: GoOSLinux, Arch: GoArchAmd64},
	{OS: GoOSLinux, Arch: GoArchArm64},
	{OS: GoOSWindows, Arch: GoArchAmd64},
	{OS: GoOSDarwin, Arch: GoArchAmd64},
	{OS: GoOSDarwin, Arch: GoArchArm64},
}
View Source
var ErrNotImplemented = fmt.Errorf("not implemented")

Functions

func JSONSchemaValidator

func JSONSchemaValidator(jsonSchema string) (*jsonschema.Schema, error)

func MatchesTable

func MatchesTable(name string, includeTablesPattern []string, skipTablesPattern []string) bool

func RecordsDiff

func RecordsDiff(sc *arrow.Schema, have, want []arrow.Record) string

func TableDiff

func TableDiff(have, want arrow.Table) string

func TestWriterSuiteRunner

func TestWriterSuiteRunner(t *testing.T, p *Plugin, tests WriterTestSuiteTests, opts ...func(o *WriterTestSuite))

func TotalRows

func TotalRows(records []arrow.Record) int64

func UnimplementedTestConnectionFn

func UnimplementedTestConnectionFn(context.Context, zerolog.Logger, []byte) error

func ValidateNoEmptyColumns

func ValidateNoEmptyColumns(t *testing.T, tables schema.Tables, messages message.SyncMessages)

func WithHomogeneousTypes

func WithHomogeneousTypes() func(o *WriterTestSuite)

func WithRandomSeed

func WithRandomSeed(seed int64) func(o *WriterTestSuite)

func WithTestDataOptions

func WithTestDataOptions(opts schema.TestSourceOptions) func(o *WriterTestSuite)

func WithTestIgnoreNullsInLists

func WithTestIgnoreNullsInLists() func(o *WriterTestSuite)

func WithTestSourceAllowNull

func WithTestSourceAllowNull(allowNull func(arrow.DataType) bool) func(o *WriterTestSuite)

Types

type AllowNullFunc

type AllowNullFunc func(arrow.DataType) bool

type BackendOptions

type BackendOptions struct {
	TableName  string
	Connection string
}

type BuildTarget

type BuildTarget struct {
	OS   string   `json:"os"`
	Arch string   `json:"arch"`
	CGO  bool     `json:"cgo"`
	Env  []string `json:"env"`
}

func (BuildTarget) EnvVariables

func (t BuildTarget) EnvVariables() []string

type Client

type Client interface {
	SourceClient
	DestinationClient
}

type ConnectionTester

type ConnectionTester func(ctx context.Context, logger zerolog.Logger, spec []byte) error

type DestinationClient

type DestinationClient interface {
	Close(ctx context.Context) error
	Read(ctx context.Context, table *schema.Table, res chan<- arrow.Record) error
	Write(ctx context.Context, res <-chan message.WriteMessage) error
}

type Kind

type Kind string
const (
	KindSource      Kind = "source"
	KindDestination Kind = "destination"
)

func (Kind) Validate

func (k Kind) Validate() error

type Meta

type Meta struct {
	Team            cqapi.PluginTeam
	Kind            cqapi.PluginKind
	Name            cqapi.PluginName
	SkipUsageClient bool
}

type MigrateMode

type MigrateMode int
const (
	MigrateModeSafe MigrateMode = iota
	MigrateModeForce
)

func (MigrateMode) String

func (m MigrateMode) String() string

type Migrations

type Migrations struct {
	RemoveUniqueConstraint bool
	MovePKToCQOnly         bool
}

Migrations defines which migrations should be skipped completely

type NewClientOptions

type NewClientOptions struct {
	NoConnection bool
	InvocationID string
	PluginMeta   Meta
}

type NewPluginFunc

type NewPluginFunc func() *Plugin

type NewSourceClientFunc

type NewSourceClientFunc func(context.Context, zerolog.Logger, any) (SourceClient, error)

type OnBeforeSender

type OnBeforeSender interface {
	OnBeforeSend(context.Context, message.SyncMessage) (message.SyncMessage, error)
}

type OnSyncFinisher

type OnSyncFinisher interface {
	OnSyncFinish(context.Context) error
}

OnSyncFinisher is an interface that can be implemented by a plugin client to be notified when a sync finishes.

type Option

type Option func(*Plugin)

func WithBuildTargets

func WithBuildTargets(targets []BuildTarget) Option

func WithConnectionTester

func WithConnectionTester(tester ConnectionTester) Option

WithConnectionTester can be specified by a plugin to enable explicit connection testing, given a spec.

func WithCustomConfig

func WithCustomConfig(cfg *aws.Config) Option

func WithJSONSchema

func WithJSONSchema(schema string) Option

func WithKind

func WithKind(kind string) Option

func WithTeam

func WithTeam(team string) Option

type PackageType

type PackageType string
const (
	PackageTypeNative PackageType = "native"
)

type Plugin

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

Plugin is the base structure required to pass to sdk.serve We take a declarative approach to API here similar to Cobra

func NewPlugin

func NewPlugin(name string, version string, newClient NewClientFunc, options ...Option) *Plugin

NewPlugin returns a new CloudQuery Plugin with the given name, version and implementation. Depending on the options, it can be a write-only plugin, read-only plugin, or both.

func NewSourcePlugin

func NewSourcePlugin(name string, version string, newClient NewSourceClientFunc, options ...Option) *Plugin

NewSourcePlugin returns a new CloudQuery Plugin with the given name, version and implementation. Source plugins only support read operations. For Read & Write plugin use NewPlugin.

func (*Plugin) Close

func (p *Plugin) Close(ctx context.Context) error

func (*Plugin) Init

func (p *Plugin) Init(ctx context.Context, spec []byte, options NewClientOptions) error

Init initializes the plugin with the given spec.

func (*Plugin) InvocationID

func (p *Plugin) InvocationID() string

InvocationID returns the invocation ID for the current execution

func (*Plugin) JSONSchema

func (p *Plugin) JSONSchema() string

func (*Plugin) Kind

func (p *Plugin) Kind() Kind

Kind returns the kind of this plugin

func (*Plugin) Meta

func (p *Plugin) Meta() Meta

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the name of this plugin

func (*Plugin) OnBeforeSend

func (p *Plugin) OnBeforeSend(ctx context.Context, msg message.SyncMessage) (message.SyncMessage, error)

OnBeforeSend gets called before every message is sent to the destination. A plugin client that implements the OnBeforeSender interface will have this method called.

func (*Plugin) OnSyncFinish

func (p *Plugin) OnSyncFinish(ctx context.Context) error

OnSyncFinish gets called after a sync finishes.

func (*Plugin) Read

func (p *Plugin) Read(ctx context.Context, table *schema.Table, res chan<- arrow.Record) error

Read is read data from the requested table to the given channel, returned in the same format as the table

func (*Plugin) SetLogger

func (p *Plugin) SetLogger(logger zerolog.Logger)

func (*Plugin) SetSkipTableValidation

func (p *Plugin) SetSkipTableValidation(v bool)

SetSkipTableValidation sets whether table validation should be skipped

func (*Plugin) SetSkipUsageClient

func (p *Plugin) SetSkipUsageClient(v bool)

SetSkipUsageClient sets whether the usage client should be skipped

func (*Plugin) Sync

func (p *Plugin) Sync(ctx context.Context, options SyncOptions, res chan<- message.SyncMessage, resourceCh chan<- *schema.Resource) error

Sync is syncing data from the requested tables in spec to the given channel

func (*Plugin) SyncAll

func (p *Plugin) SyncAll(ctx context.Context, options SyncOptions) (message.SyncMessages, error)

func (*Plugin) Tables

func (p *Plugin) Tables(ctx context.Context, options TableOptions) (schema.Tables, error)

func (*Plugin) Targets

func (p *Plugin) Targets() []BuildTarget

func (*Plugin) Team

func (p *Plugin) Team() string

Team returns the name of the team that authored this plugin

func (*Plugin) TestConnection

func (p *Plugin) TestConnection(ctx context.Context, logger zerolog.Logger, spec []byte) error

func (*Plugin) Version

func (p *Plugin) Version() string

Version returns the version of this plugin

func (*Plugin) Write

func (p *Plugin) Write(ctx context.Context, res <-chan message.WriteMessage) error

func (*Plugin) WriteAll

func (p *Plugin) WriteAll(ctx context.Context, resources []message.WriteMessage) error

WriteAll is currently used mostly for testing, so it's not a public api

type SafeMigrations

type SafeMigrations struct {
	AddColumn              bool
	AddColumnNotNull       bool
	RemoveColumn           bool
	RemoveColumnNotNull    bool
	ChangeColumn           bool
	RemoveUniqueConstraint bool
	MovePKToCQOnly         bool
}

SafeMigrations defines which migrations are supported by the plugin in safe migrate mode

type SourceClient

type SourceClient interface {
	Close(ctx context.Context) error
	Tables(ctx context.Context, options TableOptions) (schema.Tables, error)
	Sync(ctx context.Context, options SyncOptions, res chan<- message.SyncMessage, resourceCh chan<- *schema.Resource) error
}

type SyncOptions

type SyncOptions struct {
	Tables              []string
	SkipTables          []string
	SkipDependentTables bool
	DeterministicCQID   bool
	BackendOptions      *BackendOptions
}

type TableOptions

type TableOptions struct {
	Tables              []string
	SkipTables          []string
	SkipDependentTables bool
}

type TestConnError

type TestConnError struct {
	Code    string
	Message error
}

func NewTestConnError

func NewTestConnError(code string, err error) *TestConnError

func (*TestConnError) Error

func (e *TestConnError) Error() string

func (*TestConnError) Is

func (e *TestConnError) Is(err error) bool

func (*TestConnError) Unwrap

func (e *TestConnError) Unwrap() error

type UnimplementedDestination

type UnimplementedDestination struct{}

func (UnimplementedDestination) Read

func (UnimplementedDestination) Write

type UnimplementedSource

type UnimplementedSource struct{}

func (UnimplementedSource) Sync

func (UnimplementedSource) Tables

type WriteTests

type WriteTests struct {
	DuplicatePK bool
}

WriteTests defines which tests should be skipped in the write test suite

type WriterTestSuite

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

type WriterTestSuiteTests

type WriterTestSuiteTests struct {
	// SkipUpsert skips testing with message.Insert and Upsert=true.
	// Usually when a destination is not supporting primary keys
	SkipUpsert bool

	// SkipDeleteStale skips testing message.Delete events.
	SkipDeleteStale bool

	// SkipDeleteRecord skips testing message.DeleteRecord events.
	SkipDeleteRecord bool

	// SkipAppend skips testing message.Insert and Upsert=false.
	SkipInsert bool

	// SkipMigrate skips testing migration
	SkipMigrate bool

	// SafeMigrations defines which tests should work with force migration
	// and which should pass with safe migration
	SafeMigrations SafeMigrations

	SkipSpecificMigrations Migrations

	SkipSpecificWriteTests WriteTests
}

Jump to

Keyboard shortcuts

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