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

Feat/kong 1.2 #3

Merged
merged 5 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .ci/setup_kong.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ sudo apt-get update
sudo apt-get install openssl libpcre3 procps perl wget

/usr/bin/curl -sL \
"https://kong.bintray.com/kong-community-edition-deb/dists/kong-community-edition-${KONG_VERSION}.trusty.all.deb" \
-o kong.deb -o kong.deb
"https://kong.bintray.com/kong-deb/kong-${KONG_VERSION}.trusty.all.deb" \
-o kong.deb

sudo dpkg -i kong.deb

Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ addons:
env:
matrix:
- KONG_VERSION=1.0.3 GOPROXY=https://gocenter.io GO111MODULE=on
- KONG_VERSION=1.1.1 GOPROXY=https://gocenter.io GO111MODULE=on
- KONG_VERSION=1.1.2 GOPROXY=https://gocenter.io GO111MODULE=on
- KONG_VERSION=1.2.0 GOPROXY=https://gocenter.io GO111MODULE=on

before_install:
- psql -c 'create database kong;' -U postgres
Expand Down
12 changes: 11 additions & 1 deletion kong/custom_entity_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ func (s *CustomEntityService) Create(ctx context.Context,
"' not registered")
}

method := "POST"
queryPath, err := def.PostEndpoint(entity)
if err != nil {
return nil, err
}
if entity.Object() != nil {
if _, ok := entity.Object()["id"]; ok {
queryPath, err = def.PatchEndpoint(entity)
if err != nil {
return nil, err
}
method = "PUT"
}
}

o := entity.Object()
// Necessary to Marshal an empty map
// as {} and not null
if o == nil || len(o) == 0 {
o = make(map[string]interface{})
}
req, err := s.client.newRequest("POST", queryPath, nil, o)
req, err := s.client.newRequest(method, queryPath, nil, o)

if err != nil {
return nil, err
Expand Down
10 changes: 8 additions & 2 deletions kong/custom_entity_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ func TestCustomEntityService(T *testing.T) {
assert.Nil(err)
assert.Equal("my-secret", e1.Object()["key"])

// list endpoint
// PUT request
k2 := custom.NewEntityObject("key-auth")
k2.SetObject(map[string]interface{}{"key": "super-secret"})
id := "fc3898d9-4b4d-4491-a834-8358646e2d20"
k2.SetObject(map[string]interface{}{
"id": id,
"key": "super-secret",
})
k2.AddRelation("consumer_id", *consumer.ID)
e2, err := client.CustomEntities.Create(defaultCtx, k2)
assert.NotNil(e2)
assert.Nil(err)
assert.Equal("super-secret", e2.Object()["key"])
assert.Equal(id, e2.Object()["id"])

se = custom.NewEntityObject("key-auth")
se.AddRelation("consumer_id", *consumer.ID)
Expand All @@ -58,6 +63,7 @@ func TestCustomEntityService(T *testing.T) {
assert.Nil(err)
assert.Equal(2, len(keyAuths))

// list endpoint
keyAuths, err = client.CustomEntities.ListAll(defaultCtx, se)
assert.Nil(err)
assert.Equal(2, len(keyAuths))
Expand Down
2 changes: 2 additions & 0 deletions kong/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Route struct {
Sources []*CIDRPort `json:"sources,omitempty" yaml:"sources,omitempty"`
Destinations []*CIDRPort `json:"destinations,omitempty" yaml:"destinations,omitempty"`
Tags []*string `json:"tags,omitempty" yaml:"tags,omitempty"`

HTTPSRedirectStatusCode *int `json:"https_redirect_status_code,omitempty" yaml:"https_redirect_status_code,omitempty"`
}

// Valid checks if all the fields in Route are valid.
Expand Down
5 changes: 5 additions & 0 deletions kong/zz_generated.deepcopy.go

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