46 lines
1.9 KiB
Go
46 lines
1.9 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
"gitea.maximumdirect.net/eric/narratio/internal/logging"
|
|
configkit "go.maximumdirect.net/configkit"
|
|
)
|
|
|
|
type commandDependencies struct {
|
|
reporter logging.Reporter
|
|
pipelineSearch *configkit.Search
|
|
preparePipelineSource func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error)
|
|
loadPipelineSource func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error)
|
|
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.preparePipelineSource == nil {
|
|
deps.preparePipelineSource = func(source configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
|
return configkit.LoadSecretsIntoEnvironmentFromConfig(source)
|
|
}
|
|
}
|
|
if deps.loadPipelineSource == nil {
|
|
deps.loadPipelineSource = config.LoadPipelineSourceWithOptions
|
|
}
|
|
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
|
|
}
|