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 default for /search endpoint with package filter #301

Merged
merged 2 commits into from
Mar 30, 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking changes

* Change package path from /package/{packagename}-{version} to /package/{packagename}/{version} [#](https://github.com/elastic/integrations-registry/pull/)
* Change package path from /package/{packagename}-{version} to /package/{packagename}/{version} [#300](https://github.com/elastic/integrations-registry/pull/300)
* By default /search?package= now only returns the most recent package. [#301](https://github.com/elastic/integrations-registry/pull/301)

### Bugfixes

Expand All @@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Allow to set cache times through config. [#271](https://github.com/elastic/integrations-registry/pull/271)
* Make README.md file a required file for a package. [#287](https://github.com/elastic/integrations-registry/pull/287)
* Add stream fields to each dataset [#296](https://github.com/elastic/integrations-registry/pull/296)
* Add `all` query param to return all packages. By default is set false. [#301](https://github.com/elastic/integrations-registry/pull/301)

### Deprecated

Expand Down
47 changes: 47 additions & 0 deletions docs/api/search-all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"description": "Package with data sources",
"download": "/epr/datasources/datasources-1.0.0.tar.gz",
"name": "datasources",
"path": "/package/datasources/1.0.0",
"title": "Default datasource Integration",
"type": "integration",
"version": "1.0.0"
},
{
"description": "Tests if no pipeline is set, it defaults to the default one",
"download": "/epr/default-pipeline/default-pipeline-0.0.2.tar.gz",
"name": "default-pipeline",
"path": "/package/default-pipeline/0.0.2",
"title": "Default pipeline Integration",
"type": "integration",
"version": "0.0.2"
},
{
"description": "This is the example integration.",
"download": "/epr/example/example-0.0.2.tar.gz",
"name": "example",
"path": "/package/example/0.0.2",
"title": "Example",
"type": "integration",
"version": "0.0.2"
},
{
"description": "This is the example integration",
"download": "/epr/example/example-1.0.0.tar.gz",
"name": "example",
"path": "/package/example/1.0.0",
"title": "Example Integration",
"type": "integration",
"version": "1.0.0"
},
{
"description": "This is the foo integration",
"download": "/epr/foo/foo-1.0.0.tar.gz",
"name": "foo",
"path": "/package/foo/1.0.0",
"title": "Foo",
"type": "solution",
"version": "1.0.0"
}
]
20 changes: 20 additions & 0 deletions docs/api/search-package-example-all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"description": "This is the example integration.",
"download": "/epr/example/example-0.0.2.tar.gz",
"name": "example",
"path": "/package/example/0.0.2",
"title": "Example",
"type": "integration",
"version": "0.0.2"
},
{
"description": "This is the example integration",
"download": "/epr/example/example-1.0.0.tar.gz",
"name": "example",
"path": "/package/example/1.0.0",
"title": "Example Integration",
"type": "integration",
"version": "1.0.0"
}
]
9 changes: 0 additions & 9 deletions docs/api/search-package-example.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
[
{
"description": "This is the example integration.",
"download": "/epr/example/example-0.0.2.tar.gz",
"name": "example",
"path": "/package/example/0.0.2",
"title": "Example",
"type": "integration",
"version": "0.0.2"
},
{
"description": "This is the example integration",
"download": "/epr/example/example-1.0.0.tar.gz",
Expand Down
2 changes: 2 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ func TestEndpoints(t *testing.T) {
}{
{"/", "", "info.json", catchAll(publicPath, testCacheTime)},
{"/search", "/search", "search.json", searchHandler(packagesBasePath, testCacheTime)},
{"/search?all=true", "/search", "search-all.json", searchHandler(packagesBasePath, testCacheTime)},
{"/categories", "/categories", "categories.json", categoriesHandler(packagesBasePath, testCacheTime)},
{"/search?kibana=6.5.2", "/search", "search-kibana652.json", searchHandler(packagesBasePath, testCacheTime)},
{"/search?kibana=7.2.1", "/search", "search-kibana721.json", searchHandler(packagesBasePath, testCacheTime)},
{"/search?category=metrics", "/search", "search-category-metrics.json", searchHandler(packagesBasePath, testCacheTime)},
{"/search?category=logs", "/search", "search-category-logs.json", searchHandler(packagesBasePath, testCacheTime)},
{"/search?package=example", "/search", "search-package-example.json", searchHandler(packagesBasePath, testCacheTime)},
{"/search?package=example&all=true", "/search", "search-package-example-all.json", searchHandler(packagesBasePath, testCacheTime)},
{"/search?internal=true", "/search", "search-package-internal.json", searchHandler(packagesBasePath, testCacheTime)},
{"/package/example/1.0.0", "", "package.json", catchAll(publicPath, testCacheTime)},
}
Expand Down
11 changes: 9 additions & 2 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func searchHandler(packagesBasePath string, cacheTime time.Duration) func(w http
var category string
// Leaving out `a` here to not use a reserved name
var packageQuery string
var all bool
var internal bool
var err error

Expand All @@ -51,6 +52,13 @@ func searchHandler(packagesBasePath string, cacheTime time.Duration) func(w http
}
}

if v := query.Get("all"); v != "" {
if v != "" {
// Default is false, also on error
all, _ = strconv.ParseBool(v)
}
}

if v := query.Get("internal"); v != "" {
if v != "" {
// In case of error, keep it false
Expand Down Expand Up @@ -92,8 +100,7 @@ func searchHandler(packagesBasePath string, cacheTime time.Duration) func(w http
continue
}

// If no package Query is set, only the newest version of a package is returned
if packageQuery == "" {
if !all {
// Check if the version exists and if it should be added or not.
for _, versions := range packagesList {
for _, pp := range versions {
Expand Down