30 lines
915 B
Go
30 lines
915 B
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
)
|
|
|
|
// NewObjectStoreFromConfig constructs a remote object store from resolved config.
|
|
func NewObjectStoreFromConfig(ctx context.Context, cfg *config.Config) (ObjectStore, error) {
|
|
if cfg == nil || cfg.Pipeline == nil {
|
|
return nil, fmt.Errorf("pipeline config is required")
|
|
}
|
|
|
|
if strings.EqualFold(strings.TrimSpace(cfg.Pipeline.Storage.Backend), "s3") {
|
|
if cfg.Pipeline.Storage.S3 == nil {
|
|
return nil, fmt.Errorf("pipeline.storage.s3 is required when pipeline.storage.backend is s3")
|
|
}
|
|
return NewS3BackendFromConfig(ctx, *cfg.Pipeline.Storage.S3)
|
|
}
|
|
|
|
if cfg.Pipeline.Storage.S3 != nil && strings.TrimSpace(cfg.Pipeline.Storage.S3.Bucket) != "" {
|
|
return NewS3BackendFromConfig(ctx, *cfg.Pipeline.Storage.S3)
|
|
}
|
|
|
|
return nil, fmt.Errorf("no remote object store backend is configured")
|
|
}
|