Skip to content

Commit

Permalink
Add 'constraints' and 'owner' to /search responses (#734)
Browse files Browse the repository at this point in the history
This adds the constraints.kibana.version and owner fields to /search responses.

It also removes HTML escaping from the JSON responses to make them more readable.

Closes #731
  • Loading branch information
andrewkroh authored Sep 30, 2021
1 parent 1bf2229 commit 85a31cf
Show file tree
Hide file tree
Showing 50 changed files with 600 additions and 156 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `constraints` and `owner` fields to `/search` responses. [#731](https://github.com/elastic/package-registry/issues/731) [#734](https://github.com/elastic/package-registry/pull/734)
* Add categories to /search output. Categories are added to the package and policy-templates. [#735](https://github.com/elastic/package-registry/pull/735)

### Deprecated
Expand Down
5 changes: 2 additions & 3 deletions categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
"sort"
Expand Down Expand Up @@ -51,7 +50,7 @@ func categoriesHandler(packagesBasePaths []string, cacheTime time.Duration) func

cacheHeaders(w, cacheTime)
jsonHeader(w)
fmt.Fprint(w, string(data))
w.Write(data)
}
}

Expand Down Expand Up @@ -208,5 +207,5 @@ func getCategoriesOutput(ctx context.Context, categories map[string]*Category) (
outputCategories = append(outputCategories, c)
}

return json.MarshalIndent(outputCategories, "", " ")
return util.MarshalJSONPretty(outputCategories)
}
5 changes: 3 additions & 2 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
package main

import (
"encoding/json"
"net/http"
"time"

"github.com/elastic/package-registry/util"
)

type indexData struct {
Expand All @@ -20,7 +21,7 @@ func indexHandler(cacheTime time.Duration) (func(w http.ResponseWriter, r *http.
ServiceName: serviceName,
Version: version,
}
body, err := json.MarshalIndent(&data, "", " ")
body, err := util.MarshalJSONPretty(&data)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions package_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package main

import (
"encoding/json"
"log"
"net/http"
"time"
Expand Down Expand Up @@ -68,7 +67,7 @@ func packageIndexHandler(packagesBasePaths []string, cacheTime time.Duration) fu
return
}

body, err := json.MarshalIndent(p, "", " ")
body, err := util.MarshalJSONPretty(p)
if err != nil {
log.Printf("marshaling package index failed (path '%s'): %v", packagePath, err)

Expand Down
5 changes: 2 additions & 3 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
"sort"
Expand Down Expand Up @@ -46,7 +45,7 @@ func searchHandler(packagesBasePaths []string, cacheTime time.Duration) func(w h

cacheHeaders(w, cacheTime)
jsonHeader(w)
fmt.Fprint(w, string(data))
w.Write(data)
}
}

Expand Down Expand Up @@ -261,5 +260,5 @@ func getPackageOutput(ctx context.Context, packagesList map[string]map[string]ut
return []byte("[]"), nil
}

return json.MarshalIndent(output, "", " ")
return util.MarshalJSONPretty(output)
}
2 changes: 1 addition & 1 deletion testdata/generated/categories-experimental.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"title": "Web",
"count": 3
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
"title": "Web",
"count": 3
}
]
]
2 changes: 1 addition & 1 deletion testdata/generated/categories-kibana652.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"title": "Web",
"count": 1
}
]
]
2 changes: 1 addition & 1 deletion testdata/generated/categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"title": "Web",
"count": 3
}
]
]
6 changes: 3 additions & 3 deletions testdata/generated/index.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"service.name": "package-registry",
"service.version": "1.2.1"
}
"service.name": "package-registry",
"service.version": "1.2.1"
}
20 changes: 10 additions & 10 deletions testdata/generated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
"type": "integration",
"download": "/epr/example/example-1.0.0.zip",
"path": "/package/example/1.0.0",
"conditions": {
"kibana": {
"version": "~7.x.x"
}
},
"owner": {
"github": "ruflin"
},
"format_version": "1.0.0",
"readme": "/package/example/1.0.0/docs/README.md",
"license": "basic",
"categories": [
"crm",
"azure"
],
"conditions": {
"kibana": {
"version": "~7.x.x"
}
},
"screenshots": [
{
"src": "/img/kibana-envoyproxy.jpg",
Expand Down Expand Up @@ -92,8 +95,5 @@
"package": "example",
"path": "foo"
}
],
"owner": {
"github": "ruflin"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"path": "test"
}
]
}
}
2 changes: 1 addition & 1 deletion testdata/generated/package/datasources/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@
"path": "examplemetric"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"path": "foo"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"path": "foo"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"type": "solution",
"download": "/epr/elasticsearch_privileges/elasticsearch_privileges-1.0.0.zip",
"path": "/package/elasticsearch_privileges/1.0.0",
"conditions": {
"kibana": {
"version": ">=7.16.0"
}
},
"format_version": "1.0.0",
"readme": "/package/elasticsearch_privileges/1.0.0/docs/README.md",
"license": "basic",
"categories": [
"custom"
],
"conditions": {
"kibana": {
"version": "\u003e=7.16.0"
}
},
"assets": [
"/package/elasticsearch_privileges/1.0.0/manifest.yml",
"/package/elasticsearch_privileges/1.0.0/docs/README.md",
Expand Down Expand Up @@ -45,4 +45,4 @@
"path": "elasticsearch_privileges"
}
]
}
}
12 changes: 6 additions & 6 deletions testdata/generated/package/example/0.0.2/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"type": "integration",
"download": "/epr/example/example-0.0.2.zip",
"path": "/package/example/0.0.2",
"conditions": {
"kibana": {
"version": ">=6.0.0"
}
},
"format_version": "1.0.0",
"readme": "/package/example/0.0.2/docs/README.md",
"license": "basic",
"categories": [
"web"
],
"conditions": {
"kibana": {
"version": "\u003e=6.0.0"
}
},
"assets": [
"/package/example/0.0.2/manifest.yml",
"/package/example/0.0.2/docs/README.md",
Expand All @@ -35,4 +35,4 @@
"/package/example/0.0.2/kibana/visualization/80844540-5c97-11e9-8477-077ec9664dbd.json",
"/package/example/0.0.2/kibana/visualization/ab48c3f0-5ca6-11e9-8477-077ec9664dbd.json"
]
}
}
20 changes: 10 additions & 10 deletions testdata/generated/package/example/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
"type": "integration",
"download": "/epr/example/example-1.0.0.zip",
"path": "/package/example/1.0.0",
"conditions": {
"kibana": {
"version": "~7.x.x"
}
},
"owner": {
"github": "ruflin"
},
"format_version": "1.0.0",
"readme": "/package/example/1.0.0/docs/README.md",
"license": "basic",
"categories": [
"crm",
"azure"
],
"conditions": {
"kibana": {
"version": "~7.x.x"
}
},
"screenshots": [
{
"src": "/img/kibana-envoyproxy.jpg",
Expand Down Expand Up @@ -92,8 +95,5 @@
"package": "example",
"path": "foo"
}
],
"owner": {
"github": "ruflin"
}
}
]
}
2 changes: 1 addition & 1 deletion testdata/generated/package/experimental/0.0.1/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"/package/experimental/0.0.1/manifest.yml",
"/package/experimental/0.0.1/docs/README.md"
]
}
}
12 changes: 6 additions & 6 deletions testdata/generated/package/foo/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"type": "solution",
"download": "/epr/foo/foo-1.0.0.zip",
"path": "/package/foo/1.0.0",
"conditions": {
"kibana": {
"version": ">=7.0.0"
}
},
"format_version": "1.0.0",
"readme": "/package/foo/1.0.0/docs/README.md",
"license": "basic",
"categories": [
"custom"
],
"conditions": {
"kibana": {
"version": "\u003e=7.0.0"
}
},
"assets": [
"/package/foo/1.0.0/manifest.yml",
"/package/foo/1.0.0/docs/README.md"
]
}
}
12 changes: 6 additions & 6 deletions testdata/generated/package/hidden/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"type": "solution",
"download": "/epr/hidden/hidden-1.0.0.zip",
"path": "/package/hidden/1.0.0",
"conditions": {
"kibana": {
"version": ">=7.0.0"
}
},
"format_version": "1.0.0",
"readme": "/package/hidden/1.0.0/docs/README.md",
"license": "basic",
"categories": [
"custom"
],
"conditions": {
"kibana": {
"version": "\u003e=7.0.0"
}
},
"assets": [
"/package/hidden/1.0.0/manifest.yml",
"/package/hidden/1.0.0/docs/README.md",
Expand All @@ -41,4 +41,4 @@
"path": "hidden"
}
]
}
}
12 changes: 6 additions & 6 deletions testdata/generated/package/ilm_policy/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"type": "solution",
"download": "/epr/ilmpolicy/ilmpolicy-1.0.0.zip",
"path": "/package/ilmpolicy/1.0.0",
"conditions": {
"kibana": {
"version": ">=7.0.0"
}
},
"format_version": "1.0.0",
"readme": "/package/ilmpolicy/1.0.0/docs/README.md",
"license": "basic",
"categories": [
"custom"
],
"conditions": {
"kibana": {
"version": "\u003e=7.0.0"
}
},
"assets": [
"/package/ilmpolicy/1.0.0/manifest.yml",
"/package/ilmpolicy/1.0.0/docs/README.md",
Expand All @@ -42,4 +42,4 @@
"path": "ilm_policy"
}
]
}
}
Loading

0 comments on commit 85a31cf

Please sign in to comment.