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:
2026-08-09 00:32:07 +03:00
parent 328f517543
commit 9c6fc8cffa
3 changed files with 20 additions and 17 deletions
+4 -13
View File
@@ -35,17 +35,7 @@ var (
outputWriter io.Writer = os.Stderr outputWriter io.Writer = os.Stderr
) )
type pipelineRunner interface { func defaultNewRunner(options ...pipeline.Option) pipeline.Runner {
Run(
ctx context.Context,
pgDumpOpts pgdump.Options,
recipients []crypto.RecipientPub,
sink domain.Sink,
rand io.Reader,
) error
}
func defaultNewRunner(options ...pipeline.Option) pipelineRunner {
return pipeline.NewRunner(options...) return pipeline.NewRunner(options...)
} }
@@ -91,7 +81,8 @@ var backupCmd = &cobra.Command{
return fmt.Errorf("load classical public key: %w", err) 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{ pgDumpOpts := pgdump.Options{
Host: cfg.PG.Host, Host: cfg.PG.Host,
@@ -110,7 +101,7 @@ var backupCmd = &cobra.Command{
slog.String("output_path", finalPath), slog.String("output_path", finalPath),
) )
sink := newLocalSink(cfg.Backup.Dir) var sink domain.Sink = newLocalSink(cfg.Backup.Dir)
registry := crypto.NewRegistry() registry := crypto.NewRegistry()
_ = registry.Register(0x0006, func() crypto.KEM { return mlkem768.New() }) _ = registry.Register(0x0006, func() crypto.KEM { return mlkem768.New() })
+2 -2
View File
@@ -183,7 +183,7 @@ func TestBackupCmd_Success(t *testing.T) {
testData := []byte("test backup payload") testData := []byte("test backup payload")
dumper := &successDumper{data: testData} dumper := &successDumper{data: testData}
newRunner = func(...pipeline.Option) pipelineRunner { newRunner = func(...pipeline.Option) pipeline.Runner {
return pipeline.NewRunner( return pipeline.NewRunner(
pipeline.WithDumper(dumper), pipeline.WithDumper(dumper),
pipeline.WithEncryptor(&passthroughEncryptor{}), pipeline.WithEncryptor(&passthroughEncryptor{}),
@@ -320,7 +320,7 @@ func TestBackupCmd_PgDumpFailure(t *testing.T) {
return mockKM return mockKM
} }
newRunner = func(...pipeline.Option) pipelineRunner { newRunner = func(...pipeline.Option) pipeline.Runner {
return pipeline.NewRunner( return pipeline.NewRunner(
pipeline.WithDumper(&failDumper{}), pipeline.WithDumper(&failDumper{}),
pipeline.WithEncryptor(&passthroughEncryptor{}), pipeline.WithEncryptor(&passthroughEncryptor{}),
+14 -2
View File
@@ -9,6 +9,18 @@ import (
"git.tswf.io/infra/go-synapse-backupper/pkg/domain/pgdump" "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. // Option configures a Runner.
type Option func(*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 { type runner struct {
dumper pgdump.Dumper dumper pgdump.Dumper
encryptor crypto.Encryptor encryptor crypto.Encryptor
} }
// NewRunner creates a pipeline runner with the given functional options. // NewRunner creates a pipeline runner with the given functional options.
func NewRunner(options ...Option) *runner { func NewRunner(options ...Option) Runner {
r := &runner{} r := &runner{}
for _, option := range options { for _, option := range options {
option(r) option(r)