Skip to content

Commit 36bdda0

Browse files
committed
IsConfigValid utility function
1 parent 5ea1064 commit 36bdda0

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ toolchain go1.23.4
66

77
require (
88
github.com/gobwas/glob v0.2.3
9+
github.com/pkg/errors v0.9.1
910
github.com/stretchr/testify v1.10.0
1011
gopkg.in/yaml.v3 v3.0.1
1112
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
1212
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1313
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1414
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
15+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
16+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1517
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1618
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1719
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=

pkg/validator/validate.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package validator
22

33
import (
4+
"context"
5+
46
"github.com/nullify-platform/config-file-parser/pkg/models"
7+
"github.com/nullify-platform/config-file-parser/pkg/parser"
8+
"github.com/pkg/errors"
59
)
610

711
// ValidateConfig return true if provided configuration is valid
@@ -12,3 +16,13 @@ func ValidateConfig(config *models.Configuration) bool {
1216
ValidatePaths(config) &&
1317
ValidateAutoFix(config)
1418
}
19+
20+
func IsConfigValid(ctx context.Context, configString string) (bool, error) {
21+
parsedConfig, err := parser.ParseConfiguration([]byte(configString))
22+
if err != nil {
23+
return false, errors.Wrap(err, "failed to parse config")
24+
}
25+
26+
isValid := ValidateConfig(parsedConfig)
27+
return isValid, nil
28+
}

0 commit comments

Comments
 (0)