Skip to content

Axway amplify Unified Catalog integration with Kong Community edition

rathna-axway edited this page Mar 4, 2021 · 10 revisions

Axway amplify Unified Catalog integration with Kong Community edition

Step by step guide to setup and test Kong Community edition and Axway amplify

Install Kong via Docker

  • Create docker network
docker network create kong-net
  • Start Cassandra database
docker run -d --name kong-database \
               --network=kong-net \
               -p 9042:9042 \
               cassandra:3
  • Bootstrap Database
docker run --rm \
     --network=kong-net \
     -e "KONG_DATABASE=cassandra" \
     -e "KONG_PG_HOST=kong-database" \
     -e "KONG_PG_USER=kong" \
     -e "KONG_PG_PASSWORD=kong" \
     -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
     kong:latest kong migrations bootstrap
  • Start Kong
docker run -d --name kong \
     --network=kong-net \
     -e "KONG_DATABASE=cassandra" \
     -e "KONG_PG_HOST=kong-database" \
     -e "KONG_PG_USER=kong" \
     -e "KONG_PG_PASSWORD=kong" \
     -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
     -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
     -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
     -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
     -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
     -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
     -p 8000:8000 \
     -p 8443:8443 \
     -p 127.0.0.1:8001:8001 \
     -p 127.0.0.1:8444:8444 \
     kong:latest

Create a folder and place a swagger file named petstore.json

$cd /Users/axway/agents-kong/
$mkdir spec

Update discovery agent configuration file with Kong specific information

kong:
  adminEndpoint: http://localhost:8001
  proxyEndpoint: localhost
  proxyEndpointProtocols:
    https: 8443
  specDevPortalEnabled: true
  specHomePath: /Users/axway/agents-kong/spec

Create a Service

curl -i -X POST \
  --url http://localhost:8001/services/ \
  --data 'name=petstore' \
  --data 'url=https://petstore.swagger.io' \
  --data 'tags=spec_local_petstore.json'

Create a Route

curl -i -X POST \
http://localhost:8001/services/petstore/routes \
--data 'paths[]=/petstore' \
--data 'name=petstore' \
--data 'protocols[]=https'

Add key auth plugin to route

curl -i -X POST \
  --url http://localhost:8001/routes/petstore/plugins/ \
  --data 'name=key-auth'

Add ACL plugin to route

curl --location --request POST 'http://localhost:8001/routes/petstore/plugins' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "acl",
    "config": {
        "allow": [
            "amplify.group1"
        ]
    }
}'

Add CORS plugin

    curl -X POST http://localhost:8001/routes/petstore/plugins/ \
        --data "name=cors"  \
        --data "config.origins=*" \
        --data "config.methods=GET" \
        --data "config.methods=POST" \
        --data "config.headers=Accept" \
        --data "config.headers=Accept-Version" \
        --data "config.headers=Content-Length" \
        --data "config.headers=Content-MD5" \
        --data "config.headers=Content-Type" \
        --data "config.headers=Date" \
        --data "config.headers=apikey" \
        --data "config.credentials=true" \
        --data "config.max_age=3600"

Add http log plugin globally

curl -X POST http://localhost:8001/plugins/ \
--data "name=http-log" \
--data "config.http_endpoint=http://host.docker.internal:9000/requestlogs" \
--data "config.method=POST" \
--data "config.timeout=1000" \
--data "config.keepalive=1000" \
--data "config.flush_timeout=2" \
--data "config.retry_count=15"

Add additional parameter for tracing

curl -X POST http://localhost:8001/plugins/ \
--data "name=correlation-id" \
--data "config.header_name=Kong-Request-ID" \
--data "config.generator=uuid" \
--data "config.echo_downstream=false"

Build and start Kong traceability and discovery agent

Discovery agent

  • Example discovery agent configuration snapshot for Kong community edition
kong:
  adminEndpoint: http://localhost:8001
  proxyEndpoint: localhost
  proxyEndpointProtocols:
    https: 8443
  specDevPortalEnabled: false
  specHomePath: /Users/rnatarajan/APIM/kong/kong-discovery/agents-kong/spec
  • Build and run discovery agent
$ make build-disc 
$ make run run-disc
  • Discovery agent creates service and catalog.
  • Subscribe to catalog API on Axway amplify catalog
    • It creates an application, apikey and assign appropriate acl

Traceability agent

  • Build and run Traceability agent
$ make build-trace 
$ make run run-trace

Test Route on Kong

curl --location --request GET 'http://localhost:8000/petstore/v2/store/inventory' \
--header 'apikey: 123456'

Test API Observer screen on amplify