Skip to content

Commit

Permalink
add API versioning
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
  • Loading branch information
Frank Jogeleit committed Feb 1, 2024
1 parent 0eac1bb commit b212ec3
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 1,071 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ The new Trivy Plugin provides details about results comming from VulnerabilityRe

One Plugin relates to one "source" of PolicyReports.

### [GET] Policies API
### [GET] V1 Policies API

The `/policies` API provides a list of Policies. This could be a list of all policies or a list of all policies which produced a __PolicyReportResult__.
The `/v1/policies` API provides a list of Policies. This could be a list of all policies or a list of all policies which produced a __PolicyReportResult__.

#### Trivy Plugin

Expand Down Expand Up @@ -112,9 +112,9 @@ The `/policies` API provides a list of Policies. This could be a list of all pol

![Kyverno Policy List](./screens/kyverno-list.png)

### [GET] Policy API
### [GET] V1 Policy API

The `/policies/{name}` API provides details of a single policy selected by its unique name.
The `/v1/policies/{name}` API provides details of a single policy selected by its unique name.

Examples:

Expand Down
30 changes: 15 additions & 15 deletions example/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import (

type Client struct{}

// @Summary List of Policies
// @Description list all available policies
// @Tags policies
// @Produce json
// @Success 200 {array} PolicyListItem
// @Failure 500
// @Router /policies [get]
// @Summary List of Policies
// @Description list all available policies
// @Tags policies
// @Produce json
// @Success 200 {array} PolicyListItem
// @Failure 500
// @Router /v1/policies [get]
func (c *Client) GetPolicies(_ context.Context) ([]api.PolicyListItem, error) {
return policies, nil
}

// @Summary Get single Policy by Name
// @Description get policy details by unique name, try "disallow-capabilities", "CVE-2022-41723" or "min"
// @Tags policies
// @Produce json
// @Param name path string true "Unique Policy Name"
// @Success 200 {object} Policy
// @Failure 500
// @Router /policies/{name} [get]
// @Summary Get single Policy by Name
// @Description get policy details by unique name, try "disallow-capabilities", "CVE-2022-41723" or "min"
// @Tags policies
// @Produce json
// @Param name path string true "Unique Policy Name"
// @Success 200 {object} Policy
// @Failure 500
// @Router /v1/policies/{name} [get]
func (c *Client) GetPolicy(_ context.Context, name string) (*api.Policy, error) {
pol, ok := details[name]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions example/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/policies": {
"/v1/policies": {
"get": {
"description": "list all available policies",
"produces": [
Expand All @@ -44,7 +44,7 @@ const docTemplate = `{
}
}
},
"/policies/{name}": {
"/v1/policies/{name}": {
"get": {
"description": "get policy details by unique name, try \"disallow-capabilities\", \"CVE-2022-41723\" or \"min\"",
"produces": [
Expand Down
4 changes: 2 additions & 2 deletions example/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"host": "localhost:8080",
"basePath": "/api",
"paths": {
"/policies": {
"/v1/policies": {
"get": {
"description": "list all available policies",
"produces": [
Expand All @@ -38,7 +38,7 @@
}
}
},
"/policies/{name}": {
"/v1/policies/{name}": {
"get": {
"description": "get policy details by unique name, try \"disallow-capabilities\", \"CVE-2022-41723\" or \"min\"",
"produces": [
Expand Down
4 changes: 2 additions & 2 deletions example/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ info:
title: Policy Reporter UI Plugin Example API
version: 0.0.1
paths:
/policies:
/v1/policies:
get:
description: list all available policies
produces:
Expand All @@ -111,7 +111,7 @@ paths:
summary: List of Policies
tags:
- policies
/policies/{name}:
/v1/policies/{name}:
get:
description: get policy details by unique name, try "disallow-capabilities",
"CVE-2022-41723" or "min"
Expand Down
16 changes: 8 additions & 8 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import (
_ "github.com/kyverno/policy-reporter-plugins/example/docs"
)

// @title Policy Reporter UI Plugin Example API
// @version 0.0.1
// @description This is an example API for the Policy Reporter UI Plugin Interface.
// @title Policy Reporter UI Plugin Example API
// @version 0.0.1
// @description This is an example API for the Policy Reporter UI Plugin Interface.

// @contact.name Frank Jogeleit
// @contact.email frank.jogeleit@web.de
// @contact.name Frank Jogeleit
// @contact.email frank.jogeleit@web.de

// @host localhost:8080
// @BasePath /api
// @host localhost:8080
// @BasePath /api
func main() {
client := api.NewClient()

r := gin.Default()

g := r.Group("api")
g := r.Group("api/v1")

g.GET("policies", func(ctx *gin.Context) {
policies, err := client.GetPolicies(ctx)
Expand Down
3 changes: 2 additions & 1 deletion plugins/kyverno/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/kyverno/policy-reporter-plugins/plugins/kyverno/pkg/config"
"github.com/kyverno/policy-reporter-plugins/plugins/kyverno/pkg/server"
v1 "github.com/kyverno/policy-reporter-plugins/plugins/kyverno/pkg/server/v1"
"github.com/kyverno/policy-reporter-plugins/plugins/kyverno/pkg/violation"
)

Expand Down Expand Up @@ -41,7 +42,7 @@ func newRunCMD() *cobra.Command {
}

server, err := resolver.Server(cmd.Context(), []server.ServerOption{
server.WithAPI(client, coreAPI),
v1.WithAPI(client, coreAPI),
server.WithPort(c.Server.Port),
})
if err != nil {
Expand Down
82 changes: 41 additions & 41 deletions plugins/kyverno/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,86 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/segmentio/fasthash v1.0.3
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/spf13/viper v1.18.2
go.uber.org/zap v1.26.0
golang.org/x/net v0.17.0
golang.org/x/sync v0.4.0
golang.org/x/text v0.13.0
golang.org/x/net v0.20.0
golang.org/x/sync v0.6.0
golang.org/x/text v0.14.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.29.0
k8s.io/apiextensions-apiserver v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/pod-security-admission v0.29.0
k8s.io/api v0.29.1
k8s.io/apiextensions-apiserver v0.29.1
k8s.io/apimachinery v0.29.1
k8s.io/client-go v0.29.1
k8s.io/pod-security-admission v0.29.1
)

require (
github.com/bytedance/sonic v1.10.0 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.3 // indirect
github.com/go-playground/validator/v10 v10.17.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.3.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
k8s.io/component-base v0.29.1 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240126223410-2919ad4fcfec // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit b212ec3

Please sign in to comment.