58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
)
|
|
|
|
type commandDependencies struct {
|
|
diagnostics io.Writer
|
|
resolvePipelineConfigPath func(string) (string, error)
|
|
loadPipelineConfig func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error)
|
|
downloadObjectToTemp func(context.Context, storage.ObjectStore, string, string) (string, error)
|
|
loadSecretsDir func(string) (*configkit.SecretsReport, error)
|
|
secretsBootstrap *secretsBootstrap
|
|
newObjectStore func(context.Context, *config.Config) (storage.ObjectStore, error)
|
|
discoverRemoteCurrentState func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error)
|
|
buildRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, storage.ObjectStore, RestorePlanOptions) (*RestorePlan, error)
|
|
executeRestorePlan func(context.Context, *config.Config, *RemoteCurrentState, *RestorePlan, *RestoreReport, storage.ObjectStore) (*RestoreExecutionResult, error)
|
|
}
|
|
|
|
func normalizeCommandDependencies(deps commandDependencies) commandDependencies {
|
|
if deps.diagnostics == nil {
|
|
deps.diagnostics = io.Discard
|
|
}
|
|
if deps.resolvePipelineConfigPath == nil {
|
|
deps.resolvePipelineConfigPath = resolvePipelineConfigPath
|
|
}
|
|
if deps.loadPipelineConfig == nil {
|
|
deps.loadPipelineConfig = config.LoadPipelineWithOptions
|
|
}
|
|
if deps.downloadObjectToTemp == nil {
|
|
deps.downloadObjectToTemp = storage.DownloadObjectToTemp
|
|
}
|
|
if deps.loadSecretsDir == nil {
|
|
deps.loadSecretsDir = configkit.LoadSecretsDir
|
|
}
|
|
if deps.secretsBootstrap == nil {
|
|
deps.secretsBootstrap = &secretsBootstrap{}
|
|
}
|
|
if deps.newObjectStore == nil {
|
|
deps.newObjectStore = storage.NewObjectStoreFromConfig
|
|
}
|
|
if deps.discoverRemoteCurrentState == nil {
|
|
deps.discoverRemoteCurrentState = discoverRemoteCurrentState
|
|
}
|
|
if deps.buildRestorePlan == nil {
|
|
deps.buildRestorePlan = buildRestorePlan
|
|
}
|
|
if deps.executeRestorePlan == nil {
|
|
deps.executeRestorePlan = executeRestorePlan
|
|
}
|
|
return deps
|
|
}
|