Skip to content

Commit

Permalink
treat filter config as opaque JSON value
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Mar 25, 2024
1 parent 9bc2d81 commit 70da1db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
8 changes: 5 additions & 3 deletions kong/filter_chain.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kong

import "encoding/json"

// FilterChain represents a FilterChain in Kong.
// Read https://docs.konghq.com/gateway/latest/admin-api/#filter-chain-object
// +k8s:deepcopy-gen=true
Expand All @@ -18,9 +20,9 @@ type FilterChain struct {
// Filter contains information about each filter in the chain
// +k8s:deepcopy-gen=true
type Filter struct {
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Config *string `json:"config,omitempty" yaml:"config,omitempty"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Config *json.RawMessage `json:"config,omitempty" yaml:"config,omitempty"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}

// FriendlyName returns the endpoint key name or ID.
Expand Down
30 changes: 15 additions & 15 deletions kong/filter_chain_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestFilterChainsService(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
},
},
Service: service,
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestFilterChainsService(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
},
},
Service: service,
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestFilterChainsService(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
Enabled: Bool(true),
},
},
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestFilterChainsService(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
Enabled: Bool(true),
},
},
Expand All @@ -155,7 +155,7 @@ func TestFilterChainsService(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
Enabled: Bool(true),
},
},
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestFilterChainsService(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
Enabled: Bool(true),
},
},
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestFilterChainWithTags(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
},
},
Service: createdService,
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestUnknownFilterChain(T *testing.T) {
Filters: []*Filter{
{
Name: String("filter-chain-not-present"),
Config: String("{ \"option\": true }"),
Config: JsonRawMessage(`"{ \"option\": true }"`),
},
},
Service: createdService,
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestFilterChainListEndpoint(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Hi\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Hi\" }"`),
},
},
},
Expand All @@ -308,7 +308,7 @@ func TestFilterChainListEndpoint(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Hey\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Hey\" }"`),
},
},
},
Expand All @@ -317,7 +317,7 @@ func TestFilterChainListEndpoint(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Howdy\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Howdy\" }"`),
},
},
},
Expand Down Expand Up @@ -424,11 +424,11 @@ func TestFilterChainListAllForEntityEndpoint(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Hello, route\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Hello, route\" }"`),
},
{
Name: String("example-filter"),
Config: String("{ \"option\": false }"),
Config: JsonRawMessage(`"{ \"option\": false }"`),
},
},
Route: createdRoute,
Expand All @@ -439,11 +439,11 @@ func TestFilterChainListAllForEntityEndpoint(T *testing.T) {
Filters: []*Filter{
{
Name: String("example-filter"),
Config: String("{ \"option\": false }"),
Config: JsonRawMessage(`"{ \"option\": false }"`),
},
{
Name: String("example-filter"),
Config: String("{ \"my_greeting\": \"Hello, service\" }"),
Config: JsonRawMessage(`"{ \"my_greeting\": \"Hello, service\" }"`),
},
},
Service: createdService,
Expand Down
6 changes: 6 additions & 0 deletions kong/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func Float64(f float64) *float64 {
return &f
}

// JsonRawMessage returns a pointer to a json.RawMessage
func JsonRawMessage(s string) *json.RawMessage {

Check warning on line 46 in kong/utils.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func JsonRawMessage should be JSONRawMessage (revive)
j := json.RawMessage(s)
return &j
}

func isEmptyString(s *string) bool {
return s == nil || strings.TrimSpace(*s) == ""
}
Expand Down
12 changes: 10 additions & 2 deletions kong/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70da1db

Please sign in to comment.