Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dataset.name to dataset.id and dataset.path #176

Merged
merged 5 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Change `requirements.kibana.version.min/max` to `requirements.kibana.versions: {semver-range}`
* Encode Kibana objects during packaging. [#157](https://github.com/elastic/integrations-registry/pull/157)
* Prefix package download url with `/epr/{package-name}`.
* Remove dataset.name but introduce dataset.id and dataset.path. [#176](https://github.com/elastic/package-registry/pull/176)

### Bugfixes

Expand Down
5 changes: 3 additions & 2 deletions docs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@
"format_version": "1.0.0",
"datasets": [
{
"id": "bar",
"title": "Foo",
"name": "foo",
"release": "beta",
"type": "logs",
"ingest_pipeline": "pipeline-entry",
"package": "example"
"package": "example",
"path": "foo"
}
],
"download": "/epr/example/example-1.0.0.tar.gz",
Expand Down
3 changes: 3 additions & 0 deletions testdata/package/example-1.0.0/dataset/foo/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This dataset has a different id then the path
id: bar

title: Foo

# Needs to describe the type of this input
Expand Down
5 changes: 3 additions & 2 deletions testdata/public/package/default-pipeline-0.0.2/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"format_version": "1.0.0",
"datasets": [
{
"id": "default-pipeline.foo",
"title": "Foo",
"name": "foo",
"release": "beta",
"type": "logs",
"ingest_pipeline": "default",
"package": "default-pipeline"
"package": "default-pipeline",
"path": "foo"
}
],
"download": "/epr/default-pipeline/default-pipeline-0.0.2.tar.gz",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This dataset has a different id then the path
id: bar

title: Foo

# Needs to describe the type of this input
Expand Down
5 changes: 3 additions & 2 deletions testdata/public/package/example-1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@
"format_version": "1.0.0",
"datasets": [
{
"id": "bar",
"title": "Foo",
"name": "foo",
"release": "beta",
"type": "logs",
"ingest_pipeline": "pipeline-entry",
"package": "example"
"package": "example",
"path": "foo"
}
],
"download": "/epr/example/example-1.0.0.tar.gz",
Expand Down
13 changes: 8 additions & 5 deletions util/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ import (
)

type DataSet struct {
ID string `config:"id" json:"id"`
Title string `config:"title" json:"title" validate:"required"`
Name string `config:"name" json:"name"`
Release string `config:"release" json:"release"`
Type string `config:"type" json:"type" validate:"required"`
IngestPipeline string `config:"ingest_pipeline,omitempty" config:"ingest_pipeline" json:"ingest_pipeline,omitempty"`
Vars []map[string]interface{} `config:"vars" json:"vars,omitempty"`
Package string `json:"package"`

// Generated fields
Path string `json:"path"`
}

func (d *DataSet) Validate() error {
pipelineDir := d.Name + "/elasticsearch/ingest-pipeline/"
pipelineDir := d.Path + "/elasticsearch/ingest-pipeline/"
paths, err := filepath.Glob(pipelineDir + "*")
if err != nil {
return err
}

if strings.Contains(d.Name, "-") {
return fmt.Errorf("dataset name is not allowed to contain `-`: %s", d.Name)
if strings.Contains(d.ID, "-") {
return fmt.Errorf("dataset name is not allowed to contain `-`: %s", d.ID)
}

if d.IngestPipeline == "" {
Expand All @@ -43,7 +46,7 @@ func (d *DataSet) Validate() error {
}

if d.IngestPipeline == "" && len(paths) > 0 {
return fmt.Errorf("Package contains pipelines which are not used: %v, %s", paths, d.Name)
return fmt.Errorf("Package contains pipelines which are not used: %v, %s", paths, d.ID)
}

// In case an ingest pipeline is set, check if it is around
Expand Down
14 changes: 10 additions & 4 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,30 +288,36 @@ func (p *Package) LoadDataSets(packagePath string) error {
return err
}

dataSetNames, err := filepath.Glob("*")
datasetPaths, err := filepath.Glob("*")
if err != nil {
return err
}

for _, dataSetName := range dataSetNames {
for _, datasetPath := range datasetPaths {
// Check if manifest exists
manifestPath := dataSetName + "/manifest.yml"
manifestPath := datasetPath + "/manifest.yml"
_, err := os.Stat(manifestPath)
if err != nil && os.IsNotExist(err) {
return errors.Wrapf(err, "manifest does not exist for package: %s", packagePath)
}

manifest, err := yaml.NewConfigWithFile(manifestPath, ucfg.PathSep("."))
var d = &DataSet{
Name: dataSetName,
Package: p.Name,
// This is the name of the directory of the dataset
Path: datasetPath,
}
// go-ucfg automatically calls the `Validate` method on the Dataset object here
err = manifest.Unpack(d)
if err != nil {
return errors.Wrapf(err, "error building dataset in package: %s", p.Name)
}

// if id is not set, {package}.{datasetPath} is the default
if d.ID == "" {
d.ID = p.Name + "." + datasetPath
}

if d.Release == "" {
d.Release = "beta"
}
Expand Down