Skip to content

Support input references by package (input type no longer required)#1605

Merged
teresaromero merged 11 commits intoelastic:mainfrom
teresaromero:input-type-not-required
Mar 10, 2026
Merged

Support input references by package (input type no longer required)#1605
teresaromero merged 11 commits intoelastic:mainfrom
teresaromero:input-type-not-required

Conversation

@teresaromero
Copy link
Copy Markdown
Contributor

@teresaromero teresaromero commented Mar 4, 2026

What

  • Added Package field to Input and Stream structs, allowing inputs/streams to reference another package instead of specifying a type/input directly
  • Made Input.Type and Stream.Input optional (removed validate:"required" tags, added omitempty)
  • Added validation in Package.validatePackageReference() and DataStream.validStreamsInput() to enforce that each input/stream has either a type/input or a package reference, but not both and not neither
  • Added test packages (package_reference, stream_validation, stream_validation_invalid, etc.) covering valid and invalid scenarios
  • Moved test files to a dedicated folder to avoid marshalling errors on good packages

Why

  • Package spec: As of elastic/package-spec#1071 (merged), the spec defines package dependencies and input references. For format_version 3.6.0 and onwards, either package or type is required for inputs in policy templates and data streams; type is no longer required when package is used.
  • elastic-package: This work aligns the registry with the composable packages model and unblocks elastic/elastic-package#3278 (Bundle templates of required input packages), where integration packages depend on input packages and their templates are bundled at build time. The registry must correctly load and serve packages that reference input packages via package instead of type.

Checklist

  • Input struct supports optional type and package
  • Test package and golden files updated
  • No breaking change: packages that still use type continue to work

Related

@teresaromero teresaromero requested a review from a team as a code owner March 4, 2026 09:22
@prodsecmachine
Copy link
Copy Markdown

prodsecmachine commented Mar 4, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

As here it does not run the validation from package-spec, would it be helpful to add the validation to ensure that Type or Package is set in the manifest (policy template)? and the Input or Package is set in Datastreams ?

func (p *Package) Validate() error {

func (d *DataStream) Validate() error {

Comment on lines 91 to 92
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I missed the datastream one! thanks. I've added the field to Streams and remove the validation tag at the Input. I was going through and did not see why input was missing the yaml tag at the struct, so i added too.

- Introduced `validStreamsInput` method in `DataStream` to validate stream inputs.
- Added `validatePackageReference` method in `Package` to enforce XOR rule for policy template inputs.
- Implemented unit tests for various package validation scenarios, including valid and invalid configurations.
- Created test data packages to validate stream input rules and ensure proper error handling for invalid cases.
@teresaromero
Copy link
Copy Markdown
Contributor Author

As here it does not run the validation from package-spec, would it be helpful to add the validation to ensure that Type or Package is set in the manifest (policy template)? and the Input or Package is set in Datastreams ?

@mrodm i thought about it on the initial implementation, but i finally thought that validation is done when building the package, thanks to the package-spec validation. Also an argument was that this is special from a certain version of the spec... so not all the packages share this.

However, i've added after your comment as i think there is no harm in double check this and make sure as we remove a requirement, the rule is well stablished. I've added tests with mock packages to validate the aproach, i wonder if package-spec should be a dependency here 🤔 as we are kind of duplicating the validations

teresaromero and others added 2 commits March 9, 2026 08:38
Co-authored-by: Mario Rodriguez Molins <marrodmo@gmail.com>
Copy link
Copy Markdown
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

LGTM
Just add some final comments to update changelog and test packages.

CHANGELOG.md Outdated

### Added

* Support input references by package: input `type` is no longer required when `package` is set (format_version 3.6.0+, aligns with package-spec and composable packages). [#1605](https://github.com/elastic/package-registry/pull/1605)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit.
This should add a reference to the streams (input and package fields).

@@ -0,0 +1,11 @@
format_version: 3.0.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit. Would these packages require spec 3.6.0?

Suggested change
format_version: 3.0.0
format_version: 3.6.0

@@ -0,0 +1,20 @@
format_version: 3.0.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit. spec 3.6.0 ?

Suggested change
format_version: 3.0.0
format_version: 3.6.0

@@ -0,0 +1,21 @@
format_version: 3.0.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As mentioned in the other test packages.

Suggested change
format_version: 3.0.0
format_version: 3.6.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As these test packages are used as part of the packages module, I'd move those to https://github.com/elastic/package-registry/tree/main/packages/testdata

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i've moved the success test cases to the package folder. i still want to test validation introduced with wrong packages

…put validation

- Updated package paths in `package_test.go` to use relative paths.
- Introduced new test data packages for policy templates and stream validation, including:
  - `policy_template_both_inputs` with both type and package set (invalid case).
  - `policy_template_type_input` with type only (valid case).
  - `stream_validation_invalid` with an invalid stream definition.
- Added corresponding README files for documentation.
@elasticmachine
Copy link
Copy Markdown

💚 Build Succeeded

History

@teresaromero teresaromero merged commit 47fe54d into elastic:main Mar 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundle templates of required input packages

4 participants