Skip to content

Commit

Permalink
Merge branch 'main' into feat/consumer-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Jul 6, 2023
2 parents 5e006a3 + c7d0445 commit d36d201
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of Contents

- [v0.45.0](#v0450)
- [v0.44.0](#v0440)
- [v0.43.0](#v0430)
- [v0.42.0](#v0420)
Expand Down Expand Up @@ -58,6 +59,15 @@

## Unreleased

> Release date: TBD
## [v0.45.0]

> Release date: 2023/07/03
- Added `Client.Config` handler, that can be used to obtain Kong's config.
[#354](https://github.com/Kong/go-kong/pull/354)

## [v0.44.0]

> Release date: 2023/06/22
Expand Down Expand Up @@ -789,6 +799,7 @@ authentication credentials in Kong.
releases of Kong since every release of Kong is introducing breaking changes
to the Admin API.

[v0.45.0]: https://github.com/Kong/go-kong/compare/v0.44.0...v0.45.0
[v0.44.0]: https://github.com/Kong/go-kong/compare/v0.43.0...v0.44.0
[v0.43.0]: https://github.com/Kong/go-kong/compare/v0.42.0...v0.43.0
[v0.42.0]: https://github.com/Kong/go-kong/compare/v0.41.0...v0.42.0
Expand Down
2 changes: 1 addition & 1 deletion kong/certificate_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *CertificateService) Update(ctx context.Context,
certificate *Certificate,
) (*Certificate, error) {
if isEmptyString(certificate.ID) {
return nil, fmt.Errorf("ID cannot be nil for Update op eration")
return nil, fmt.Errorf("ID cannot be nil for Update operation")
}

endpoint := fmt.Sprintf("/certificates/%v", *certificate.ID)
Expand Down
25 changes: 25 additions & 0 deletions kong/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kong
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -357,6 +358,30 @@ func (c *Client) Status(ctx context.Context) (*Status, error) {
return &s, nil
}

// Config gets the specified config from the configured Admin API endpoint
// and should contain the JSON serialized body that adheres to the configuration
// format specified at:
// https://docs.konghq.com/gateway/latest/production/deployment-topologies/db-less-and-declarative-config/#declarative-configuration-format
// It returns the response body and an error, if it encounters any.
func (c *Client) Config(ctx context.Context) ([]byte, error) {
req, err := c.NewRequest("GET", "/config", nil, nil)
if err != nil {
return nil, err
}

var configWrapper map[string]string
_, err = c.Do(ctx, req, &configWrapper)
if err != nil {
return nil, err
}
config, ok := configWrapper["config"]
if !ok {
return nil, errors.New("config field not found in GET /config response body")
}

return []byte(config), nil
}

// Root returns the response of GET request on root of Admin API (GET / or /kong with a workspace).
func (c *Client) Root(ctx context.Context) (map[string]interface{}, error) {
endpoint := "/"
Expand Down
17 changes: 17 additions & 0 deletions kong/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)

func TestNewTestClient(t *testing.T) {
Expand All @@ -32,6 +33,22 @@ func TestKongStatus(T *testing.T) {
assert.NotNil(status)
}

func TestKongConfig(t *testing.T) {
RunWhenDBMode(t, "off")
client, err := NewTestClient(nil, nil)
require.NoError(t, err)
require.NotNil(t, client)

config, err := client.Config(defaultCtx)
require.NoError(t, err)
require.NotNil(t, config)

var configStruct map[string]any
require.NoError(t, yaml.Unmarshal(config, &configStruct))
require.Contains(t, configStruct, "_format_version")
require.Contains(t, configStruct, "_transform")
}

func TestRoot(T *testing.T) {
assert := assert.New(T)

Expand Down

0 comments on commit d36d201

Please sign in to comment.