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

Support input packages #809

Merged
merged 20 commits into from
Jun 1, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Prepare stub for Storage Indexer. Disable fetching packages from Package Storage v1. [#811](https://github.com/elastic/package-registry/pull/811)
* Support input packages. [#809](https://github.com/elastic/package-registry/pull/809)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Indexer interface {
type CombinedIndexer []Indexer

func NewCombinedIndexer(indexers ...Indexer) CombinedIndexer {
return CombinedIndexer(indexers)
return indexers
}

func (c CombinedIndexer) Init(ctx context.Context) error {
Expand Down
4 changes: 4 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func TestEndpoints(t *testing.T) {
{"/search?prerelease=true", "/search", "search-package-prerelease.json", searchHandler(indexer, testCacheTime)},
{"/search?prerelease=foo", "/search", "search-package-prerelease-error.txt", searchHandler(indexer, testCacheTime)},
{"/search?category=datastore&prerelease=true", "/search", "search-category-datastore-prerelease.json", searchHandler(indexer, testCacheTime)},
{"/search?type=input", "/search", "search-input-packages.json", searchHandler(indexer, testCacheTime)},
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
{"/search?type=input&package=integration_input", "/search", "search-input-integration-package.json", searchHandler(indexer, testCacheTime)},
{"/search?type=integration&package=integration_input", "/search", "search-integration-integration-package.json", searchHandler(indexer, testCacheTime)},
{"/favicon.ico", "", "favicon.ico", faviconHandleFunc},

// Removed flags, kept to ensure that they don't break requests from old versions.
Expand Down Expand Up @@ -323,6 +326,7 @@ func TestPackageIndex(t *testing.T) {
{"/package/missing/1.0.0/", packageIndexRouterPath, "index-package-not-found.txt", packageIndexHandler},
{"/package/example/999.0.0/", packageIndexRouterPath, "index-package-revision-not-found.txt", packageIndexHandler},
{"/package/example/a.b.c/", packageIndexRouterPath, "index-package-invalid-version.txt", packageIndexHandler},
{"/package/sql_input/1.0.1/", packageIndexRouterPath, "sql-input-package.json", packageIndexHandler},
}

for _, test := range tests {
Expand Down
7 changes: 6 additions & 1 deletion packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ type PolicyTemplate struct {
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
DataStreams []string `config:"data_streams,omitempty" json:"data_streams,omitempty" yaml:"data_streams,omitempty"`
Inputs []Input `config:"inputs" json:"inputs"`
Inputs []Input `config:"inputs" json:"inputs,omitempty" yaml:"inputs,omitempty"`
Multiple *bool `config:"multiple" json:"multiple,omitempty" yaml:"multiple,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
Screenshots []Image `config:"screenshots,omitempty" json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
Readme *string `config:"readme,omitempty" json:"readme,omitempty" yaml:"readme,omitempty"`

// For purposes of "input packages"
Type string `config:"type,omitempty" json:"type,omitempty" yaml:"type,omitempty"`
Input string `config:"input,omitempty" json:"input,omitempty" yaml:"input,omitempty"`
TemplatePath string `config:"template_path,omitempty" json:"template_path,omitempty" yaml:"template_path,omitempty"`
}

type Conditions struct {
Expand Down
5 changes: 5 additions & 0 deletions packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ type Filter struct {
KibanaVersion *semver.Version
PackageName string
PackageVersion string
PackageType string

// Deprecated, release tags to be removed.
Experimental bool
Expand Down Expand Up @@ -295,6 +296,10 @@ func (f *Filter) Apply(ctx context.Context, packages Packages) Packages {
continue
}

if f.PackageType != "" && f.PackageType != p.Type {
continue
}

addPackage := true
if !f.AllVersions {
// Check if the version exists and if it should be added or not.
Expand Down
4 changes: 4 additions & 0 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func newSearchFilterFromQuery(query url.Values) (*packages.Filter, error) {
filter.PackageName = v
}

if v := query.Get("type"); v != "" {
filter.PackageType = v
}

if v := query.Get("all"); v != "" {
// Default is false, also on error
filter.AllVersions, err = strconv.ParseBool(v)
Expand Down
4 changes: 2 additions & 2 deletions testdata/generated/categories-experimental.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
{
"id": "custom",
"title": "Custom",
"count": 14
"count": 16
},
{
"id": "datastore",
"title": "Datastore",
"count": 1
"count": 3
},
{
"id": "message_queue",
Expand Down
4 changes: 2 additions & 2 deletions testdata/generated/categories-include-policy-templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
{
"id": "custom",
"title": "Custom",
"count": 12
"count": 13
},
{
"id": "datastore",
"title": "Datastore",
"count": 2
"count": 3
},
{
"id": "web",
Expand Down
7 changes: 6 additions & 1 deletion testdata/generated/categories-kibana652.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
{
"id": "custom",
"title": "Custom",
"count": 6
"count": 7
},
{
"id": "datastore",
"title": "Datastore",
"count": 1
},
{
"id": "message_queue",
Expand Down
7 changes: 6 additions & 1 deletion testdata/generated/categories-prerelease-kibana652.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
{
"id": "custom",
"title": "Custom",
"count": 6
"count": 7
},
{
"id": "datastore",
"title": "Datastore",
"count": 1
},
{
"id": "message_queue",
Expand Down
4 changes: 2 additions & 2 deletions testdata/generated/categories-prerelease.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
{
"id": "custom",
"title": "Custom",
"count": 14
"count": 16
},
{
"id": "datastore",
"title": "Datastore",
"count": 1
"count": 3
},
{
"id": "message_queue",
Expand Down
7 changes: 6 additions & 1 deletion testdata/generated/categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
{
"id": "custom",
"title": "Custom",
"count": 12
"count": 13
},
{
"id": "datastore",
"title": "Datastore",
"count": 1
},
{
"id": "web",
Expand Down
99 changes: 99 additions & 0 deletions testdata/generated/package/integration_input/1.0.0/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"name": "integration_input",
"title": "Integration input",
"version": "1.0.0",
"release": "ga",
"description": "This is the example integration",
"type": "integration",
"download": "/epr/integration_input/integration_input-1.0.0.zip",
"path": "/package/integration_input/1.0.0",
"conditions": {
"kibana": {
"version": "^8.4.0"
}
},
"owner": {
"github": "ruflin"
},
"categories": [
"crm",
"azure"
],
"format_version": "1.0.0",
"readme": "/package/integration_input/1.0.0/docs/README.md",
"license": "basic",
"screenshots": [
{
"src": "/img/kibana-envoyproxy.jpg",
"path": "/package/integration_input/1.0.0/img/kibana-envoyproxy.jpg",
"title": "IP Tables Ubiquity Dashboard",
"size": "1492x1464",
"type": "image/png"
}
],
"assets": [
"/package/integration_input/1.0.0/manifest.yml",
"/package/integration_input/1.0.0/docs/README.md",
"/package/integration_input/1.0.0/img/icon.png",
"/package/integration_input/1.0.0/img/kibana-envoyproxy.jpg",
"/package/integration_input/1.0.0/data_stream/foo/manifest.yml",
"/package/integration_input/1.0.0/kibana/dashboard/0c610510-5cbd-11e9-8477-077ec9664dbd.json",
"/package/integration_input/1.0.0/kibana/visualization/0a994af0-5c9d-11e9-8477-077ec9664dbd.json",
"/package/integration_input/1.0.0/kibana/visualization/36f872a0-5c03-11e9-85b4-19d0072eb4f2.json",
"/package/integration_input/1.0.0/kibana/visualization/38f96190-5c99-11e9-8477-077ec9664dbd.json",
"/package/integration_input/1.0.0/kibana/visualization/7e4084e0-5c99-11e9-8477-077ec9664dbd.json",
"/package/integration_input/1.0.0/kibana/visualization/80844540-5c97-11e9-8477-077ec9664dbd.json",
"/package/integration_input/1.0.0/kibana/visualization/ab48c3f0-5ca6-11e9-8477-077ec9664dbd.json",
"/package/integration_input/1.0.0/data_stream/foo/fields/base-fields.yml",
"/package/integration_input/1.0.0/data_stream/foo/agent/stream/stream.yml.hbs",
"/package/integration_input/1.0.0/data_stream/foo/elasticsearch/ingest_pipeline/pipeline-entry.json",
"/package/integration_input/1.0.0/data_stream/foo/elasticsearch/ingest_pipeline/pipeline-http.json",
"/package/integration_input/1.0.0/data_stream/foo/elasticsearch/ingest_pipeline/pipeline-json.json",
"/package/integration_input/1.0.0/data_stream/foo/elasticsearch/ingest_pipeline/pipeline-plaintext.json",
"/package/integration_input/1.0.0/data_stream/foo/elasticsearch/ingest_pipeline/pipeline-tcp.json"
],
"policy_templates": [
{
"name": "logs",
"title": "Logs datasource",
"description": "Datasource for your log files.",
"inputs": [
{
"type": "foo"
}
],
"multiple": true,
"categories": [
"datastore"
]
}
],
"data_streams": [
{
"type": "logs",
"dataset": "integration_input.foo",
"title": "Foo",
"release": "ga",
"ingest_pipeline": "pipeline-entry",
"streams": [
{
"input": "foo",
"vars": [
{
"name": "paths",
"type": "text",
"description": "Path to log files to be collected",
"multi": true,
"required": true,
"show_user": false
}
],
"template_path": "stream.yml.hbs",
"enabled": true
}
],
"package": "integration_input",
"path": "foo"
}
]
}
61 changes: 61 additions & 0 deletions testdata/generated/package/integration_input/1.0.2/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "integration_input",
"title": "Integration Input",
"version": "1.0.2",
"release": "ga",
"description": "Sample package that was an integration and got migrated to input",
"type": "input",
"download": "/epr/integration_input/integration_input-1.0.2.zip",
"path": "/package/integration_input/1.0.2",
"icons": [
{
"src": "/img/sample-logo.svg",
"path": "/package/integration_input/1.0.2/img/sample-logo.svg",
"type": "image/svg+xml"
}
],
"conditions": {
"kibana": {
"version": "^8.4.0"
}
},
"owner": {
"github": "elastic/integrations"
},
"categories": [
"custom",
"datastore"
],
"format_version": "1.0.0",
"readme": "/package/integration_input/1.0.2/docs/README.md",
"license": "basic",
"screenshots": [
{
"src": "/img/sample-screenshot.png",
"path": "/package/integration_input/1.0.2/img/sample-screenshot.png",
"title": "Sample screenshot",
"size": "600x600",
"type": "image/png"
}
],
"assets": [
"/package/integration_input/1.0.2/changelog.yml",
"/package/integration_input/1.0.2/manifest.yml",
"/package/integration_input/1.0.2/docs/README.md",
"/package/integration_input/1.0.2/fields/input.yml",
"/package/integration_input/1.0.2/img/sample-logo.svg",
"/package/integration_input/1.0.2/img/sample-screenshot.png",
"/package/integration_input/1.0.2/agent/input/input.yml.hbs"
],
"policy_templates": [
{
"name": "sql_query",
"title": "SQL Query",
"description": "Query the database to capture metrics.",
"multiple": true,
"type": "metrics",
"input": "sql",
"template_path": "input.yml.hbs"
}
]
}
56 changes: 56 additions & 0 deletions testdata/generated/package/sql_input/0.2.0/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "sql_input",
"title": "SQL Input",
"version": "0.2.0",
"release": "beta",
"description": "Execute custom queries against an SQL database and store the results in Elasticsearch.",
"type": "input",
"download": "/epr/sql_input/sql_input-0.2.0.zip",
"path": "/package/sql_input/0.2.0",
"icons": [
{
"src": "/img/sample-logo.svg",
"path": "/package/sql_input/0.2.0/img/sample-logo.svg",
"type": "image/svg+xml"
}
],
"owner": {
"github": "elastic/integrations"
},
"categories": [
"custom",
"datastore"
],
"format_version": "1.0.0",
"readme": "/package/sql_input/0.2.0/docs/README.md",
"license": "basic",
"screenshots": [
{
"src": "/img/sample-screenshot.png",
"path": "/package/sql_input/0.2.0/img/sample-screenshot.png",
"title": "Sample screenshot",
"size": "600x600",
"type": "image/png"
}
],
"assets": [
"/package/sql_input/0.2.0/changelog.yml",
"/package/sql_input/0.2.0/manifest.yml",
"/package/sql_input/0.2.0/docs/README.md",
"/package/sql_input/0.2.0/fields/input.yml",
"/package/sql_input/0.2.0/img/sample-logo.svg",
"/package/sql_input/0.2.0/img/sample-screenshot.png",
"/package/sql_input/0.2.0/agent/input/input.yml.hbs"
],
"policy_templates": [
{
"name": "sql_query",
"title": "SQL Query",
"description": "Query the database to capture metrics.",
"multiple": true,
"type": "metrics",
"input": "sql",
"template_path": "input.yml.hbs"
}
]
}
Loading