Skip to content

Commit

Permalink
Validate packages to only use predefined categories (#100)
Browse files Browse the repository at this point in the history
This required to move the categories to util package.
  • Loading branch information
ruflin authored Sep 12, 2019
1 parent 1036e16 commit 2176d2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Add validation check that Kibana min/max are valid semver versions. [#99](https://github.com/elastic/integrations-registry/pull/99)
* Adding Cache-Control max-age headers to all http responses set to 1h. [#101](https://github.com/elastic/integrations-registry/pull/101)
* Validate packages to guarantee only predefined categories can be used. [#100](https://github.com/elastic/integrations-registry/pull/100)

### Changed

Expand Down
7 changes: 2 additions & 5 deletions categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import (
"github.com/elastic/integrations-registry/util"
)

var categoryTitles = map[string]string{
"logs": "Logs",
"metrics": "Metrics",
}


type Category struct {
Id string `yaml:"id" json:"id"`
Expand Down Expand Up @@ -85,7 +82,7 @@ func getCategoriesOutput(categories map[string]*Category) ([]byte, error) {
var outputCategories []*Category
for _, k := range keys {
c := categories[k]
if title, ok := categoryTitles[c.Title]; ok {
if title, ok := util.CategoryTitles[c.Title]; ok {
c.Title = title
}
outputCategories = append(outputCategories, c)
Expand Down
11 changes: 11 additions & 0 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (

const defaultType = "integration"

var CategoryTitles = map[string]string{
"logs": "Logs",
"metrics": "Metrics",
}

type Package struct {
Name string `yaml:"name" json:"name"`
Title *string `yaml:"title,omitempty" json:"title,omitempty"`
Expand Down Expand Up @@ -217,5 +222,11 @@ func (p *Package) Validate() error {
}
}

for _, c := range p.Categories {
if _, ok := CategoryTitles[c]; !ok {
return fmt.Errorf("invalid category: %s", c)
}
}

return nil
}
10 changes: 10 additions & 0 deletions util/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ var packageTests = []struct {
Max: "4.5.6",
},
},
Categories: []string{"metrics", "logs", "foo"},
},
false,
"invalid category ",
},
{
Package{
Title: &title,
Description: "my description",
Categories: []string{"metrics", "logs"},
},
true,
"complete",
Expand Down

0 comments on commit 2176d2f

Please sign in to comment.