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

Add input groups support #685

Merged
merged 23 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c1aa90f
add icons from policy templates and package level vars
kaiyan-sheng Mar 29, 2021
d26ab1d
add categories at policy template level
kaiyan-sheng Mar 29, 2021
0540e30
Merge remote-tracking branch 'upstream/master' into input_groups
kaiyan-sheng Mar 29, 2021
3761555
update format
kaiyan-sheng Mar 29, 2021
ffedd09
add screenshots at policy template level
kaiyan-sheng Mar 29, 2021
fc13d63
adjust test data package version
kaiyan-sheng Mar 29, 2021
06ad054
Merge remote-tracking branch 'upstream/master' into input_groups
kaiyan-sheng Mar 31, 2021
e3e844d
Add policy template icons into /search endpoint
kaiyan-sheng Mar 31, 2021
a6a596f
fix base policy templates
kaiyan-sheng Mar 31, 2021
0a1cdcb
Fix policy template icon path
kaiyan-sheng Apr 1, 2021
45348d0
fix screenshot paths
kaiyan-sheng Apr 1, 2021
39db2ea
update /categories endpoint to include policy templates
kaiyan-sheng Apr 1, 2021
8a3e734
add include_policy_templates parameter for /categories endpoint
kaiyan-sheng Apr 5, 2021
777176e
update README for /categories?include_policy_templates=true
kaiyan-sheng Apr 5, 2021
78e7990
add changelog
kaiyan-sheng Apr 5, 2021
b11ecd1
add input_groups into manifest.yml
kaiyan-sheng Apr 7, 2021
ea0b18e
add readme into policy templates
kaiyan-sheng Apr 8, 2021
3fbf902
fix include_policy_templates flag
kaiyan-sheng Apr 8, 2021
5b546c2
Merge remote-tracking branch 'upstream/master' into input_groups
kaiyan-sheng Apr 8, 2021
2ef3d80
fix include_policy_templates
kaiyan-sheng Apr 8, 2021
e55db35
Merge remote-tracking branch 'upstream/master' into input_groups
kaiyan-sheng Apr 12, 2021
423cf8a
remove predefined input groups
kaiyan-sheng Apr 12, 2021
ab574d3
add check for os.PathError
kaiyan-sheng Apr 14, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Add input groups support. [#685] (https://github.com/elastic/package-registry/pull/685)

### Deprecated

### Known Issues
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ The `/search` API endpoint has few additional query parameters. More might be ad
a package requires 7.4, the package will not be returned or an older compatible package will be shown.
By default this endpoint always returns only the newest compatible package.
* category: Filters the package by the given category. Available categories can be seend when going to `/categories` endpoint.
* package: Filters by a specific package name, for example `mysql`. Returns the most recent version.
* package: Filters by a specific package name, for example `mysql`. Returns the most recent version.
* internal: This can be set to true, to also list internal packages. This is set to `false` by default.
* all: This can be set to true to list all package versions. This is set to `false` by default.
* experimental: This can be set to true to list packages considered to be experimental. This is set to `false` by default.

The different query parameters above can be combined, so `?package=mysql&kibana=7.3.0` will return all mysql package versions
which are compatible with `7.3.0`.

The `/categories` API endpoint has two additional query parameters.

* experimental: This can be set to true to list categories from experimental packages. This is set to `false` by default.
* include_policy_templates: This can be set to true to include categories from policy templates. This is set to `false` by default.

## Package structure

The structure of each package is standardised. It looks as following:
Expand Down Expand Up @@ -196,4 +201,4 @@ CI automatically creates a new Docker image which will be available under `docke
After the new registry Docker image is available, update the following projects that consume it:
- Integrations: Update the version of the Package Registry Docker image as shown in this [sample PR](https://github.com/elastic/integrations/pull/581).
- Package Storage: Follow the [documentation](https://github.com/elastic/package-storage#update-package-registry-for-a-distribution) on how to update the distributions.
- Kibana: Do this only after all Package Storage distributions have been updated and released as new Docker images. Update the version of the Package Registry Distribution Docker image as shown in this [sample PR](https://github.com/elastic/kibana/pull/89776).
- Kibana: Do this only after all Package Storage distributions have been updated and released as new Docker images. Update the version of the Package Registry Distribution Docker image as shown in this [sample PR](https://github.com/elastic/kibana/pull/89776).
36 changes: 36 additions & 0 deletions categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func

query := r.URL.Query()
var experimental bool
var includePolicyTemplates bool

// Read query filter params which can affect the output
if len(query) > 0 {
if v := query.Get("experimental"); v != "" {
Expand All @@ -41,6 +43,14 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func
return
}
}

if v := query.Get("include_policy_templates"); v != "" {
includePolicyTemplates, err = strconv.ParseBool(v)
if err != nil {
badRequest(w, fmt.Sprintf("invalid 'include_policy_templates' query param: '%s'", v))
return
}
}
}

packageList := map[string]util.Package{}
Expand Down Expand Up @@ -81,6 +91,32 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func

categories[c].Count = categories[c].Count + 1
}

if includePolicyTemplates {
for _, t := range p.PolicyTemplates {
// Skip when policy template level `categories` is empty and there is only one policy template
if t.Categories == nil && len(p.PolicyTemplates) == 1 {
continue
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
}

for _, c := range p.Categories {
categories[c].Count = categories[c].Count + 1
}

// Add policy template level categories.
for _, c := range t.Categories {
if _, ok := categories[c]; !ok {
categories[c] = &Category{
Id: c,
Title: c,
Count: 0,
}
}

categories[c].Count = categories[c].Count + 1
}
}
}
}

data, err := getCategoriesOutput(categories)
Expand Down
2 changes: 2 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func TestEndpoints(t *testing.T) {
{"/categories", "/categories", "categories.json", categoriesHandler(packagesBasePaths, testCacheTime)},
{"/categories?experimental=true", "/categories", "categories-experimental.json", categoriesHandler(packagesBasePaths, testCacheTime)},
{"/categories?experimental=foo", "/categories", "categories-experimental-error.json", categoriesHandler(packagesBasePaths, testCacheTime)},
{"/categories?include_policy_templates=true", "/categories", "categories-include-policy-templates.json", categoriesHandler(packagesBasePaths, testCacheTime)},
{"/categories?include_policy_templates=foo", "/categories", "categories-include-policy-templates-error.json", categoriesHandler(packagesBasePaths, testCacheTime)},
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
{"/search?kibana.version=6.5.2", "/search", "search-kibana652.json", searchHandler(packagesBasePaths, testCacheTime)},
{"/search?kibana.version=7.2.1", "/search", "search-kibana721.json", searchHandler(packagesBasePaths, testCacheTime)},
{"/search?category=web", "/search", "search-category-web.json", searchHandler(packagesBasePaths, testCacheTime)},
Expand Down
7 changes: 6 additions & 1 deletion testdata/generated/categories-experimental.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
{
"id": "aws",
"title": "AWS",
"count": 1
"count": 2
},
{
"id": "azure",
"title": "Azure",
"count": 1
},
{
"id": "cloud",
"title": "Cloud",
"count": 1
},
{
"id": "containers",
"title": "Containers",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid 'include_policy_templates' query param: 'foo'
52 changes: 52 additions & 0 deletions testdata/generated/categories-include-policy-templates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"id": "aws",
"title": "AWS",
"count": 2
},
{
"id": "azure",
"title": "Azure",
"count": 1
},
{
"id": "cloud",
"title": "Cloud",
"count": 2
},
{
"id": "compute",
"title": "compute",
"count": 1
},
{
"id": "containers",
"title": "Containers",
"count": 1
},
{
"id": "crm",
"title": "CRM",
"count": 1
},
{
"id": "custom",
"title": "Custom",
"count": 13
},
{
"id": "message_queue",
"title": "Message Queue",
"count": 1
},
{
"id": "monitoring",
"title": "Monitoring",
"count": 1
},
{
"id": "web",
"title": "Web",
"count": 3
}
]
10 changes: 10 additions & 0 deletions testdata/generated/categories.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
[
{
"id": "aws",
"title": "AWS",
"count": 1
},
{
"id": "azure",
"title": "Azure",
"count": 1
},
{
"id": "cloud",
"title": "Cloud",
"count": 1
},
{
"id": "containers",
"title": "Containers",
Expand Down
Loading