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

Prepare for support of multiple, independent package types #323

Merged
merged 4 commits into from
Apr 26, 2022
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
4 changes: 2 additions & 2 deletions code/go/internal/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
spec "github.com/elastic/package-spec"
)

func TestBundledSpecs(t *testing.T) {
func TestBundledSpecsForIntegration(t *testing.T) {
fs := spec.FS()
_, err := fs.Open("1/spec.yml")
_, err := fs.Open("1/integration/spec.yml")
require.NoError(t, err)
}
7 changes: 7 additions & 0 deletions code/go/internal/validator/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// Package represents an Elastic Package Registry package
type Package struct {
Name string
Type string
SpecVersion *semver.Version

fs fs.FS
Expand Down Expand Up @@ -64,12 +65,17 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) {

var manifest struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
SpecVersion string `yaml:"format_version"`
}
if err := yaml.Unmarshal(data, &manifest); err != nil {
return nil, errors.Wrapf(err, "could not parse package manifest file [%v]", pkgManifestPath)
}

if manifest.Type == "" {
return nil, errors.New("package type undefined in the package manifest file")
}

specVersion, err := semver.NewVersion(manifest.SpecVersion)
if err != nil {
return nil, errors.Wrapf(err, "could not read specification version from package manifest file [%v]", pkgManifestPath)
Expand All @@ -78,6 +84,7 @@ func NewPackageFromFS(location string, fsys fs.FS) (*Package, error) {
// Instantiate Package object and return it
p := Package{
Name: manifest.Name,
Type: manifest.Type,
SpecVersion: specVersion,
fs: fsys,

Expand Down
2 changes: 1 addition & 1 deletion code/go/internal/validator/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s Spec) ValidatePackage(pkg Package) ve.ValidationErrors {
var errs ve.ValidationErrors

var rootSpec folderSpec
rootSpecPath := path.Join(s.specPath, "spec.yml")
rootSpecPath := path.Join(s.specPath, pkg.Type, "spec.yml")
err := rootSpec.load(s.fs, rootSpecPath)
if err != nil {
errs = append(errs, errors.Wrap(err, "could not read root folder spec file"))
Expand Down
1 change: 1 addition & 0 deletions code/go/pkg/validator/testdata/limits/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: good
title: Good package
description: This package is good.
version: 1.0.0
type: integration
conditions:
kibana.version: '^7.9.0'
policy_templates:
Expand Down
2 changes: 1 addition & 1 deletion spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"io/fs"
)

//go:embed versions/1 versions/1/_dev versions/1/data_stream/_dev
//go:embed versions/1 versions/1/integration/_dev versions/1/integration/data_stream/_dev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsoriano Does Go ignore _underscore-dirs by design? I must have missed something here.

Copy link
Member

@jsoriano jsoriano Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are certain parts of Go that ignore dirs prefixed with underscores and the testdata directory. For example I think that go get doesn't get these files by default, and go test ./... probably doesn't look for tests there.
I think that files referenced by embed are also seen by go get and some other commands that would ignore them otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess it's a workaround then. The PR is ready for a review round.

var content embed.FS

// FS returns an io/fs.FS for accessing the "package-spec/version" contents.
Expand Down
1 change: 1 addition & 0 deletions test/packages/bad_deploy_variants/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: bad_deploy_variants
title: Bad Deploy Variants
description: This package contains a bad _dev/deploy folder.
version: 0.1.2
type: integration
release: beta
owner:
github: elastic/foobar
1 change: 1 addition & 0 deletions test/packages/bad_kibana_ids/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: bad_kibana_ids
title: Bad Kibana IDs
description: This package contains Kibana object files with non-matching IDs
version: 0.1.2
type: integration
release: beta
owner:
github: elastic/foobar
1 change: 1 addition & 0 deletions test/packages/deploy_docker/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: bad_deploy_variants
title: Bad Deploy Variants
description: This package contains a bad _dev/deploy folder.
version: 0.1.2
type: integration
release: beta
owner:
github: elastic/foobar
1 change: 1 addition & 0 deletions test/packages/deploy_terraform/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: bad_deploy_variants
title: Bad Deploy Variants
description: This package contains a bad _dev/deploy folder.
version: 0.1.2
type: integration
release: beta
owner:
github: elastic/foobar
1 change: 1 addition & 0 deletions test/packages/docs_extra_files/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: docs_extra_files
title: Extra files in docs
description: This package is bad.
version: 0.1.2
type: integration
release: beta
conditions:
kibana.version: '^7.9.0'
Expand Down
1 change: 1 addition & 0 deletions test/packages/good/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: good
title: Good package
description: This package is good.
version: 1.0.0
type: integration
conditions:
kibana.version: '^7.9.0'
policy_templates:
Expand Down
1 change: 1 addition & 0 deletions test/packages/input_template/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: integration
title: integration
description: integration, really
version: 0.1.2
type: integration
release: beta
conditions:
kibana.version: '^7.9.0'
Expand Down
1 change: 1 addition & 0 deletions test/packages/missing_data_stream/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: good
title: GOOD
description: This package is good.
version: 0.1.2
type: integration
release: beta
conditions:
kibana.version: '^7.9.0'
Expand Down
1 change: 1 addition & 0 deletions test/packages/missing_image_files/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: missing_image_files
title: Missing Image Files
description: This package is bad.
version: 0.1.2
type: integration
release: beta
conditions:
kibana.version: '^7.9.0'
Expand Down
1 change: 1 addition & 0 deletions test/packages/missing_pipeline_dashes/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: good
title: GOOD
description: This package is good.
version: 0.1.2
type: integration
release: beta
conditions:
kibana.version: '^7.9.0'
Expand Down
1 change: 1 addition & 0 deletions test/packages/missing_required_fields/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: missing_required_fields
title: Package without required fields
description: This package doesn't have expected fields
version: 1.0.0
type: integration
conditions:
kibana.version: '^8.0.0'
policy_templates:
Expand Down
3 changes: 2 additions & 1 deletion test/packages/no_spec_version/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# no format_version in this file
name: mypackage
name: mypackage
type: integration
1 change: 1 addition & 0 deletions test/packages/wrong_kibana_filename/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: bad
title: BAD
description: This package is bad.
version: 0.1.2
type: integration
release: beta
conditions:
kibana.version: '^7.9.0'
Expand Down
3 changes: 3 additions & 0 deletions versions/1/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- description: Add Kibana/osquery-saved-query
type: enhancement
link: https://github.com/elastic/package-spec/pull/321
- description: Prepare for support of multiple, independent package types. Require "type" to be present in manifest.
type: enhancement
link: https://github.com/elastic/package-spec/pull/323
- version: 1.7.0
changes:
- description: Add kibana/osquery-pack-asset
Expand Down
File renamed without changes.
File renamed without changes.
Loading