Skip to content

Commit

Permalink
[Fleet] Allow to specify kibana.version when fetching categories
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed May 10, 2021
1 parent 640373b commit a469ae8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/elastic/package-registry/util"
"github.com/Masterminds/semver/v3"
)

type Category struct {
Expand All @@ -33,6 +34,7 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func
query := r.URL.Query()
var experimental bool
var includePolicyTemplates bool
var kibanaVersion *semver.Version

// Read query filter params which can affect the output
if len(query) > 0 {
Expand All @@ -44,6 +46,14 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func
}
}

if v := query.Get("kibana.version"); v != "" {
kibanaVersion, err = semver.NewVersion(v)
if err != nil {
badRequest(w, fmt.Sprintf("invalid Kibana version '%s': %s", v, err))
return
}
}

if v := query.Get("include_policy_templates"); v != "" {
includePolicyTemplates, err = strconv.ParseBool(v)
if err != nil {
Expand All @@ -56,6 +66,12 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func
packageList := map[string]util.Package{}
// Get unique list of newest packages
for _, p := range packages {
// Check if the package is compatible with Kibana version
if kibanaVersion != nil {
if valid := p.HasKibanaVersion(kibanaVersion); !valid {
continue
}
}

// Skip internal packages
if p.Internal {
Expand Down

0 comments on commit a469ae8

Please sign in to comment.