Skip to content

Commit

Permalink
Validate config modules earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
godrei committed Jul 11, 2024
1 parent 2e721fa commit 1a258e1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions configmerge/configmerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ func (m *Merger) buildConfigTree(configContent []byte, reference ConfigReference
if err := yaml.Unmarshal(configContent, &config); err != nil {
return nil, err
}

if len(config.Include) > MaxIncludeCountPerFile {
return nil, fmt.Errorf("max include count (%d) exceeded", MaxIncludeCountPerFile)
}
if m.filesCount+len(config.Include) > MaxFilesCountTotal {
return nil, fmt.Errorf("max file count (%d) exceeded", MaxFilesCountTotal)
}

for idx, include := range config.Include {
if err := include.Validate(); err != nil {
return nil, err
Expand All @@ -140,15 +148,6 @@ func (m *Merger) buildConfigTree(configContent []byte, reference ConfigReference
}
}

if len(config.Include) > MaxIncludeCountPerFile {
return nil, fmt.Errorf("max include count (%d) exceeded", MaxIncludeCountPerFile)

}

if m.filesCount+len(config.Include) > MaxFilesCountTotal {
return nil, fmt.Errorf("max file count (%d) exceeded", MaxFilesCountTotal)
}

var includedConfigTrees []models.ConfigFileTreeModel
for _, include := range config.Include {
moduleBytes, err := m.readConfigModule(include, m.repoInfo)
Expand Down

0 comments on commit 1a258e1

Please sign in to comment.