Harden configuration validation
This commit is contained in:
@@ -130,8 +130,19 @@ func validatePipeline(cfg *PipelineConfig) error {
|
||||
}
|
||||
|
||||
func validateStorage(cfg StorageConfig) error {
|
||||
if cfg.S3 == nil {
|
||||
backend := strings.ToLower(strings.TrimSpace(cfg.Backend))
|
||||
switch backend {
|
||||
case "", StorageBackendLocal:
|
||||
if cfg.S3 != nil {
|
||||
return fmt.Errorf("pipeline.storage.s3 is only supported when pipeline.storage.backend is s3")
|
||||
}
|
||||
return nil
|
||||
case StorageBackendS3:
|
||||
if cfg.S3 == nil {
|
||||
return fmt.Errorf("pipeline.storage.s3 is required when pipeline.storage.backend is s3")
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("pipeline.storage.backend must be one of: local, s3")
|
||||
}
|
||||
if strings.TrimSpace(cfg.S3.RootPrefix) == "" {
|
||||
return fmt.Errorf("pipeline.storage.s3.root_prefix must be non-empty")
|
||||
@@ -783,13 +794,16 @@ func validateCrossConfig(pipeline *PipelineConfig, session *SessionConfig) error
|
||||
if pipeline == nil || session == nil {
|
||||
return nil
|
||||
}
|
||||
if pipeline.Storage.S3 == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
audioS3Enabled := session.Inputs.AudioS3 != nil
|
||||
publishUploadEnabled := publishUploadConfiguredForS3(pipeline)
|
||||
if (audioS3Enabled || publishUploadEnabled) && strings.TrimSpace(pipeline.Storage.S3.Bucket) == "" {
|
||||
if audioS3Enabled && !strings.EqualFold(strings.TrimSpace(pipeline.Storage.Backend), StorageBackendS3) {
|
||||
return fmt.Errorf("pipeline.storage.backend must be s3 when session.inputs.audio_s3 is configured")
|
||||
}
|
||||
if !audioS3Enabled && !publishUploadEnabled {
|
||||
return nil
|
||||
}
|
||||
if pipeline.Storage.S3 == nil || strings.TrimSpace(pipeline.Storage.S3.Bucket) == "" {
|
||||
return fmt.Errorf("pipeline.storage.s3.bucket is required when S3 session audio or publish upload is enabled")
|
||||
}
|
||||
return nil
|
||||
@@ -799,7 +813,7 @@ func publishUploadConfiguredForS3(pipeline *PipelineConfig) bool {
|
||||
if pipeline == nil || pipeline.Publish == nil {
|
||||
return false
|
||||
}
|
||||
if !strings.EqualFold(strings.TrimSpace(pipeline.Storage.Backend), "s3") {
|
||||
if !strings.EqualFold(strings.TrimSpace(pipeline.Storage.Backend), StorageBackendS3) {
|
||||
return false
|
||||
}
|
||||
enabled := true
|
||||
@@ -975,9 +989,13 @@ func validateDuration(fieldName, value string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := time.ParseDuration(trimmed); err != nil {
|
||||
duration, err := time.ParseDuration(trimmed)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s must be a valid duration: %w", fieldName, err)
|
||||
}
|
||||
if duration <= 0 {
|
||||
return fmt.Errorf("%s must be positive", fieldName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user