Hello!
Could you please help me configuring Tyk to make it working with custom python middleware. My problem is that Tyk does not deal with python or bundles at all: I see no entries in log that could relate to python. I’ve learned multiple topics on this forum with no luck.
Here’s my confguration:
docker-compose.yml
(I’m using docker compose)
version: '3.3'
services:
tyk-gateway:
image: docker.tyk.io/tyk-gateway/tyk-gateway:v4.0.0
ports:
- 8081:8080
networks:
- tyk
volumes:
- ./tyk.standalone.conf:/opt/tyk-gateway/tyk.conf
- ./apps:/opt/tyk-gateway/apps
- ./middleware:/opt/tyk-gateway/middleware
- ./certs:/opt/tyk-gateway/certs
- ./policies:/opt/tyk-gateway/policies
- ./bundles:/opt/tyk-gateway/middleware/bundles
environment:
- TYK_GW_SECRET=foo
depends_on:
- tyk-redis
extra_hosts:
- "host.docker.internal:host-gateway"
tyk-redis:
image: redis:5.0-alpine
networks:
- tyk
ports:
- 6379:6379
networks:
tyk:
tyk.standalone.conf
(I’m using a bundle host from someone else’s topic):
{
"listen_port": 8080,
"secret": "352d20ee67be67f6340b4c0605b044b7",
"template_path": "/opt/tyk-gateway/templates",
"tyk_js_path": "/opt/tyk-gateway/js/tyk.js",
"middleware_path": "/opt/tyk-gateway/middleware",
"use_db_app_configs": false,
"app_path": "/opt/tyk-gateway/apps/",
"storage": {
"type": "redis",
"host": "tyk-redis",
"port": 6379,
"username": "",
"password": "",
"database": 0,
"optimisation_max_idle": 2000,
"optimisation_max_active": 4000
},
"enable_analytics": false,
"analytics_config": {
"type": "csv",
"csv_dir": "/tmp",
"mongo_url": "",
"mongo_db_name": "",
"mongo_collection": "",
"purge_delay": -1,
"ignored_ips": []
},
"health_check": {
"enable_health_checks": false,
"health_check_value_timeouts": 60
},
"optimisations_use_async_session_write": false,
"enable_non_transactional_rate_limiter": true,
"enable_sentinel_rate_limiter": false,
"enable_redis_rolling_limiter": false,
"allow_master_keys": false,
"policies": {
"policy_source": "file",
"policy_record_name": "/opt/tyk-gateway/policies/policies.json"
},
"hash_keys": true,
"close_connections": false,
"http_server_options": {
"enable_websockets": true
},
"allow_insecure_configs": true,
"coprocess_options": {
"enable_coprocess": true,
"python_path_prefix": "/opt/tyk-gateway"
},
"enable_bundle_downloader": true,
"bundle_base_url": "https://storage.cloud.google.com/mlt-sandbox/tyk-plugins/",
"global_session_lifetime": 100,
"force_global_session_lifetime": false,
"max_idle_connections_per_host": 500,
"enable_jsvm": true,
"enable_hashed_keys_listing": true,
"log_level": "debug"
}
API definition:
{
"name": "My API",
"slug": "my-api",
"api_id": "100",
"org_id": "",
"auth_configs": {
"authToken": {
"auth_header_name": "Authorization"
}
},
"definition": {
"location": "header",
"key": "x-api-version"
},
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"use_extended_paths": true
}
}
},
"proxy": {
"listen_path": "/graphql/",
"target_url": "http://host.docker.internal:8080/graphql",
"strip_listen_path": true
},
"active": true,
"use_keyless": false,
"enable_jwt": false,
"graphql": {
"enabled": true,
"execution_mode": "proxyOnly",
"schema": "type Query { getString: String }",
"playground": {
"enabled": false
},
"engine": {
"field_configs": null,
"data_sources": null
}
},
"custom_middleware": {
"pre": [
{
"name": "PreHook"
}
],
"post": [
{
"name": "PostHook"
}
],
"post_key_auth": [
{
"name": "PostKeyAuth"
}
],
"response": [
{
"name": "ResponseHook"
}
],
"auth_check": {
"name": "AuthCheck"
},
"driver": "python",
"id_extractor": {
"extract_from": "header",
"extract_with": "value",
"extractor_config": {
"header_name": "Authorization"
}
}
},
"custom_middleware_bundle": "bundle.zip"
}
manifest.json
(it is located in ./middleware
):
{
"file_list": [
"middleware.py"
],
"custom_middleware": {
"pre": [
{
"name": "PreHook"
}
],
"post": [
{
"name": "PostHook"
}
],
"post_key_auth": [
{
"name": "PostKeyAuth"
}
],
"response": [
{
"name": "ResponseHook"
}
],
"auth_check": {
"name": "AuthCheck"
},
"driver": "python",
"id_extractor": {
"extract_from": "header",
"extract_with": "value",
"extractor_config": {
"header_name": "Authorization"
}
}
}
}
I omitted middleware.py
as to make the topic shorter, this file does not seem to be used at all.
Thank you for the greate project!