Skip to content

Commit

Permalink
Fleshing out
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Apr 20, 2021
1 parent f02071f commit b35eb59
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
4 changes: 1 addition & 3 deletions code/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
github.com/xeipuuv/gojsonschema v1.2.0
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
)

replace github.com/elastic/package-spec/code/go/internal/pkgpath => ./internal/pkgpath
)
27 changes: 24 additions & 3 deletions code/go/internal/validator/semantic/kibana_object_ids.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
package semantic

import (
"fmt"
"path/filepath"
"strings"

"github.com/elastic/package-spec/code/go/internal/validator"

"github.com/pkg/errors"

"github.com/elastic/package-spec/code/go/internal/pkgpath"
)

func ValidateKibanaObjectIDs(pkgRoot string) error {
filePaths := filepath.Join(pkgRoot, "kibana", "dashboard", "*.json")
_, err := pkgpath.Files(filePaths)
dashboardFiles, err := pkgpath.Files(filePaths)
if err != nil {
return err
return errors.Wrap(err, "unable to find dashboard files")
}

var errs validator.ValidationErrors
for _, dashboardFile := range dashboardFiles {
name := dashboardFile.Name()
dashboardID, err := dashboardFile.Values("$.id")
if err != nil {
return errors.Wrap(err, "unable to get dashboard ID")
}

fileID := strings.TrimRight(name, ".json")
if fileID != dashboardID {
err := fmt.Errorf("dashboard file '%s' defines non-matching ID '%s'", name, dashboardID)
errs = append(errs, err)
}
}

return nil
return errs
}
10 changes: 9 additions & 1 deletion code/go/internal/validator/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path"
"strconv"

"github.com/elastic/package-spec/code/go/internal/validator/semantic"

"github.com/Masterminds/semver/v3"
"github.com/pkg/errors"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -54,5 +56,11 @@ func (s Spec) ValidatePackage(pkg Package) ValidationErrors {
return errs
}

return rootSpec.validate(pkg.Name, pkg.RootPath)
// Syntactic validations
errs = rootSpec.validate(pkg.Name, pkg.RootPath)

// Semantic validations
errs = append(errs, semantic.ValidateKibanaObjectIDs(pkg.RootPath)...)

return errs
}

0 comments on commit b35eb59

Please sign in to comment.