Skip to content

Commit

Permalink
[chore] Move config validation into validate function (#24015)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed Jul 7, 2023
1 parent ab5a083 commit d3f5cd4
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pkg/stanza/fileconsumer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ type Config struct {

// Build will build a file input operator from the supplied configuration
func (c Config) Build(logger *zap.SugaredLogger, emit EmitFunc) (*Manager, error) {
if c.DeleteAfterRead && !allowFileDeletion.IsEnabled() {
return nil, fmt.Errorf("`delete_after_read` requires feature gate `%s`", allowFileDeletion.ID())
}

if c.Header != nil && !AllowHeaderMetadataParsing.IsEnabled() {
return nil, fmt.Errorf("`header` requires feature gate `%s`", AllowHeaderMetadataParsing.ID())
}

if err := c.validate(); err != nil {
return nil, err
}
Expand All @@ -95,8 +87,7 @@ func (c Config) Build(logger *zap.SugaredLogger, emit EmitFunc) (*Manager, error
}

// BuildWithSplitFunc will build a file input operator with customized splitFunc function
func (c Config) BuildWithSplitFunc(
logger *zap.SugaredLogger, emit EmitFunc, splitFunc bufio.SplitFunc) (*Manager, error) {
func (c Config) BuildWithSplitFunc(logger *zap.SugaredLogger, emit EmitFunc, splitFunc bufio.SplitFunc) (*Manager, error) {
if err := c.validate(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -168,6 +159,14 @@ func (c Config) buildManager(logger *zap.SugaredLogger, emit EmitFunc, factory s
}

func (c Config) validate() error {
if c.DeleteAfterRead && !allowFileDeletion.IsEnabled() {
return fmt.Errorf("`delete_after_read` requires feature gate `%s`", allowFileDeletion.ID())
}

if c.Header != nil && !AllowHeaderMetadataParsing.IsEnabled() {
return fmt.Errorf("`header` requires feature gate `%s`", AllowHeaderMetadataParsing.ID())
}

if len(c.Include) == 0 {
return fmt.Errorf("required argument `include` is empty")
}
Expand Down

0 comments on commit d3f5cd4

Please sign in to comment.