From 3ff2153d68f5a829e6bde7ec5eef45f5e9cc6898 Mon Sep 17 00:00:00 2001 From: ruflin Date: Wed, 25 Mar 2020 14:39:04 +0100 Subject: [PATCH 1/2] Change default for /search endpoint with package filter So far when a `/search?package=foo` query was run, by default all versions of the package found were returned. This was in contrast to that by default only the most recent version of a package is returned. To make the API less surprising the behavior was changed that by default only the most recent package is returned. As there might be still a need to return all packages, and additional param `all=true` was added. This can now be used in combination with all query params. To get the same result as before, `/search?package=foo&all=true` has to be run. By default all is false. add test for all add one more all test --- CHANGELOG.md | 4 +- docs/api/search-all.json | 47 ++++++++++++++++++++++++ docs/api/search-package-example-all.json | 20 ++++++++++ docs/api/search-package-example.json | 9 ----- main_test.go | 2 + search.go | 11 +++++- 6 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 docs/api/search-all.json create mode 100644 docs/api/search-package-example-all.json diff --git a/CHANGELOG.md b/CHANGELOG.md index a019def64..98003ad38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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. [#](https://github.com/elastic/integrations-registry/pull/) ### Deprecated diff --git a/docs/api/search-all.json b/docs/api/search-all.json new file mode 100644 index 000000000..d2d117833 --- /dev/null +++ b/docs/api/search-all.json @@ -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" + } +] \ No newline at end of file diff --git a/docs/api/search-package-example-all.json b/docs/api/search-package-example-all.json new file mode 100644 index 000000000..55fd1f20d --- /dev/null +++ b/docs/api/search-package-example-all.json @@ -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" + } +] \ No newline at end of file diff --git a/docs/api/search-package-example.json b/docs/api/search-package-example.json index 55fd1f20d..1213a420b 100644 --- a/docs/api/search-package-example.json +++ b/docs/api/search-package-example.json @@ -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", diff --git a/main_test.go b/main_test.go index cfa4ca268..15019e9f3 100644 --- a/main_test.go +++ b/main_test.go @@ -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)}, } diff --git a/search.go b/search.go index aa1624243..2a0c0858a 100644 --- a/search.go +++ b/search.go @@ -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 @@ -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 @@ -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 { From 972b99610282149a055fcb7384d50caa0e897a1d Mon Sep 17 00:00:00 2001 From: ruflin Date: Mon, 30 Mar 2020 21:35:45 +0200 Subject: [PATCH 2/2] adjust changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98003ad38..0bc8a32ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +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. [#](https://github.com/elastic/integrations-registry/pull/) +* Add `all` query param to return all packages. By default is set false. [#301](https://github.com/elastic/integrations-registry/pull/301) ### Deprecated