refactor(pipeline): ввести Runner интерфейс
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -35,17 +35,7 @@ var (
|
||||
outputWriter io.Writer = os.Stderr
|
||||
)
|
||||
|
||||
type pipelineRunner interface {
|
||||
Run(
|
||||
ctx context.Context,
|
||||
pgDumpOpts pgdump.Options,
|
||||
recipients []crypto.RecipientPub,
|
||||
sink domain.Sink,
|
||||
rand io.Reader,
|
||||
) error
|
||||
}
|
||||
|
||||
func defaultNewRunner(options ...pipeline.Option) pipelineRunner {
|
||||
func defaultNewRunner(options ...pipeline.Option) pipeline.Runner {
|
||||
return pipeline.NewRunner(options...)
|
||||
}
|
||||
|
||||
@@ -91,7 +81,8 @@ var backupCmd = &cobra.Command{
|
||||
return fmt.Errorf("load classical public key: %w", err)
|
||||
}
|
||||
|
||||
recipients := []crypto.RecipientPub{pqPub, classicalPub}
|
||||
recipients := make([]crypto.RecipientPub, 0, 2)
|
||||
recipients = append(recipients, pqPub, classicalPub)
|
||||
|
||||
pgDumpOpts := pgdump.Options{
|
||||
Host: cfg.PG.Host,
|
||||
@@ -110,7 +101,7 @@ var backupCmd = &cobra.Command{
|
||||
slog.String("output_path", finalPath),
|
||||
)
|
||||
|
||||
sink := newLocalSink(cfg.Backup.Dir)
|
||||
var sink domain.Sink = newLocalSink(cfg.Backup.Dir)
|
||||
|
||||
registry := crypto.NewRegistry()
|
||||
_ = registry.Register(0x0006, func() crypto.KEM { return mlkem768.New() })
|
||||
|
||||
@@ -183,7 +183,7 @@ func TestBackupCmd_Success(t *testing.T) {
|
||||
|
||||
testData := []byte("test backup payload")
|
||||
dumper := &successDumper{data: testData}
|
||||
newRunner = func(...pipeline.Option) pipelineRunner {
|
||||
newRunner = func(...pipeline.Option) pipeline.Runner {
|
||||
return pipeline.NewRunner(
|
||||
pipeline.WithDumper(dumper),
|
||||
pipeline.WithEncryptor(&passthroughEncryptor{}),
|
||||
@@ -320,7 +320,7 @@ func TestBackupCmd_PgDumpFailure(t *testing.T) {
|
||||
return mockKM
|
||||
}
|
||||
|
||||
newRunner = func(...pipeline.Option) pipelineRunner {
|
||||
newRunner = func(...pipeline.Option) pipeline.Runner {
|
||||
return pipeline.NewRunner(
|
||||
pipeline.WithDumper(&failDumper{}),
|
||||
pipeline.WithEncryptor(&passthroughEncryptor{}),
|
||||
|
||||
@@ -9,6 +9,18 @@ import (
|
||||
"git.tswf.io/infra/go-synapse-backupper/pkg/domain/pgdump"
|
||||
)
|
||||
|
||||
// Runner orchestrates the dump → encrypt → sink pipeline.
|
||||
type Runner interface {
|
||||
// Run executes the full backup pipeline: pg_dump → encrypt → sink.
|
||||
Run(
|
||||
ctx context.Context,
|
||||
pgDumpOpts pgdump.Options,
|
||||
recipients []crypto.RecipientPub,
|
||||
sink domain.Sink,
|
||||
rand io.Reader,
|
||||
) error
|
||||
}
|
||||
|
||||
// Option configures a Runner.
|
||||
type Option func(*runner)
|
||||
|
||||
@@ -26,14 +38,14 @@ func WithEncryptor(encryptor crypto.Encryptor) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Runner orchestrates the dump → encrypt → sink pipeline.
|
||||
// runner is the private implementation of Runner.
|
||||
type runner struct {
|
||||
dumper pgdump.Dumper
|
||||
encryptor crypto.Encryptor
|
||||
}
|
||||
|
||||
// NewRunner creates a pipeline runner with the given functional options.
|
||||
func NewRunner(options ...Option) *runner {
|
||||
func NewRunner(options ...Option) Runner {
|
||||
r := &runner{}
|
||||
for _, option := range options {
|
||||
option(r)
|
||||
|
||||
Reference in New Issue
Block a user