Carry dependencies through pipeline commands
This commit is contained in:
@@ -47,6 +47,12 @@ func (f commonConfigFlags) sessionOptions() config.SessionLoadOptions {
|
||||
|
||||
// Session dispatches session helper subcommands.
|
||||
func Session(ctx context.Context, args []string, out io.Writer) error {
|
||||
return sessionWithDependencies(ctx, args, out, commandDependencies{
|
||||
newObjectStore: newObjectStoreFromConfigFn,
|
||||
})
|
||||
}
|
||||
|
||||
func sessionWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("session: expected subcommand: init|validate|status|plan|restore|artifacts|locks")
|
||||
}
|
||||
@@ -56,9 +62,9 @@ func Session(ctx context.Context, args []string, out io.Writer) error {
|
||||
case "validate":
|
||||
return SessionValidate(ctx, args[1:], out)
|
||||
case "status":
|
||||
return Status(ctx, args[1:], out)
|
||||
return statusWithDependencies(ctx, args[1:], out, deps)
|
||||
case "plan":
|
||||
return Plan(ctx, args[1:], out)
|
||||
return planWithDependencies(ctx, args[1:], out, deps)
|
||||
case "restore":
|
||||
return Restore(ctx, args[1:], out)
|
||||
case "artifacts":
|
||||
@@ -142,10 +148,16 @@ func loadHelperContext(ctx context.Context, flags commonConfigFlags, needStore b
|
||||
}
|
||||
|
||||
func objectStoreIfConfigured(ctx context.Context, cfg *config.Config) (storage.ObjectStore, error) {
|
||||
return objectStoreIfConfiguredWithDependencies(ctx, cfg, commandDependencies{
|
||||
newObjectStore: newObjectStoreFromConfigFn,
|
||||
})
|
||||
}
|
||||
|
||||
func objectStoreIfConfiguredWithDependencies(ctx context.Context, cfg *config.Config, deps commandDependencies) (storage.ObjectStore, error) {
|
||||
if cfg == nil || cfg.Pipeline == nil || cfg.Pipeline.Storage.S3 == nil || strings.TrimSpace(cfg.Pipeline.Storage.S3.Bucket) == "" {
|
||||
return nil, nil
|
||||
}
|
||||
store, err := newCommandObjectStore(ctx, cfg, nil)
|
||||
store, err := newCommandObjectStoreWithDependencies(ctx, cfg, nil, deps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user