Skip to content

Commit

Permalink
Add validation for dataset type
Browse files Browse the repository at this point in the history
The valid dataset types at the moment are logs and metrics.
  • Loading branch information
ruflin committed Jun 10, 2020
1 parent e56da29 commit dc2d3bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Generate index.json file. [#470](https://github.com/elastic/package-registry/pull/470)
* Stream archived package content. [#472](https://github.com/elastic/package-registry/pull/472)
* Generate package index.json files. [#479](https://github.com/elastic/package-registry/pull/479)
* Add validation for dataset type. [#](https://github.com/elastic/package-registry/pull/)

### Deprecated

Expand Down
14 changes: 14 additions & 0 deletions util/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const (
DirIngestPipeline = "ingest-pipeline"
)

var ValidTypes = map[string]interface{}{
"logs": nil,
"metrics": nil,
}

type DataSet struct {
ID string `config:"id" json:"id,omitempty" yaml:"id,omitempty"`
Title string `config:"title" json:"title" validate:"required"`
Expand Down Expand Up @@ -140,6 +145,10 @@ func (d *DataSet) Validate() error {
return fmt.Errorf("dataset name is not allowed to contain `-`: %s", d.ID)
}

if !d.ValidType() {
return fmt.Errorf("type is not valid: %s", d.Type)
}

if d.IngestPipeline == "" {
// Check that no ingest pipeline exists in the directory except default
for _, path := range paths {
Expand Down Expand Up @@ -191,6 +200,11 @@ func (d *DataSet) Validate() error {
return nil
}

func (d *DataSet) ValidType() bool {
_, exists := ValidTypes[d.Type]
return exists
}

func validateIngestPipelineFile(pipelinePath string) error {
f, err := ioutil.ReadFile(pipelinePath)
if err != nil {
Expand Down

0 comments on commit dc2d3bd

Please sign in to comment.