Skip to content

Commit

Permalink
Add tyk check
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Aug 18, 2021
1 parent 44e2ddd commit 4f64d7a
Show file tree
Hide file tree
Showing 11 changed files with 658 additions and 34 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]

jobs:
build-caddy-validator:
name: Checkout code
name: Check that Souin build as caddy module
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -20,3 +20,25 @@ jobs:
sudo apt install xcaddy
- name: Build Souin as caddy module
run: cd plugins/caddy && xcaddy build --with github.com/darkweak/souin/plugins/caddy=./ --with github.com/darkweak/souin@latest=../..
build-tyk-validator:
name: Check that Souin build as Tyk middleware
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
- name: Checkout code
uses: actions/checkout@v2
- name: Build Souin as Tyk plugin
run: make build-and-run-tyk
- name: Wait for Souin is really loaded inside Tyk as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
- name: Set logs result as environment variable
run: cd plugins/tyk && echo "TYK_DC_RESULT=$(docker-compose logs tyk-gateway | grep -i '\[INFO\] Olric bindAddr')" >> $GITHUB_ENV
- name: Check Olric is loaded to define Souin is loaded too
uses: nick-invision/assert-action@v1
with:
expected: '[INFO] Olric bindAddr'
actual: ${{ env.TYK_DC_RESULT }}
comparison: contains
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ build-and-run-caddy-json: ## Run caddy binary with the json configuration
cd plugins/caddy && ./caddy run --config ./configuration.json

build-and-run-tyk: ## Run caddy binary with the json configuration
cd plugins/tyk && $(MAKE) prepare && \
docker-compose up --remove-orphans --build --force-recreate
cd plugins/tyk && $(MAKE) prepare

build-app: env-prod ## Build containers with prod env vars
$(DC_BUILD) souin
Expand Down
10 changes: 7 additions & 3 deletions plugins/tyk/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
.PHONY: prepare

prepare: ## Prepare tyk plugin
go mod tidy && \
go mod download && \
go mod vendor && \
go mod tidy
go mod download
go mod vendor
$(MAKE) replace
cp docker-compose.yml.test docker-compose.yml
docker-compose up tyk-builder
mv souin-plugin.so ./samples/middleware/
docker-compose up -d --remove-orphans --build tyk-pump tyk-gateway

# TODO find another way to do that
replace: ## Replace sources in the vendor folder deeper than the go mod replace
Expand Down
44 changes: 44 additions & 0 deletions plugins/tyk/docker-compose.yml.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3.8'

services:
tyk-builder:
image: tykio/tyk-plugin-compiler:v3.2.2-rc4
command: souin-plugin.so
volumes:
- .:/plugin-source

tyk-gateway:
image: tykio/tyk-gateway:v3.2.2-rc4
ports:
- "8080:8080"
depends_on:
- tyk-redis
volumes:
- ./samples/confs/tyk.conf:/opt/tyk-gateway/tyk.conf
- ./samples/middleware:/opt/tyk-gateway/middleware
- ./samples/apps:/opt/tyk-gateway/apps
tyk-pump:
image: tykio/tyk-pump-docker-pub:latest
depends_on:
- tyk-redis
- tyk-mongo
- tyk-gateway
volumes:
- ./samples/confs/pump.conf:/opt/tyk-pump/pump.conf
tyk-redis:
image: redis
ports:
- "6379:6379"
volumes:
- redis-data:/data
tyk-mongo:
image: mongo:3.2
command: [ "mongod", "--smallfiles" ]
ports:
- "27017:27017"
volumes:
- mongo-data:/data/db

volumes:
redis-data:
mongo-data:
61 changes: 33 additions & 28 deletions plugins/tyk/go.sum

Large diffs are not rendered by default.

215 changes: 215 additions & 0 deletions plugins/tyk/samples/apps/app1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
{
"id": "5a4f1c029764510001dbc3f1",
"name": "Sales Demo API",
"slug": "sales-demo-api",
"api_id": "6b6c9fc301614e607c591e4af785c465",
"org_id": "60e256359626200001088e9f",
"use_keyless": false,
"use_oauth2": false,
"use_openid": false,
"openid_options": {
"providers": [],
"segregate_by_client": false
},
"oauth_meta": {
"allowed_access_types": [],
"allowed_authorize_types": [],
"auth_login_redirect": ""
},
"auth": {
"use_param": false,
"param_name": "",
"use_cookie": false,
"cookie_name": "",
"auth_header_name": "Authorization",
"use_certificate": false
},
"use_basic_auth": false,
"use_mutual_tls_auth": false,
"client_certificates": [],
"upstream_certificates": {},
"enable_jwt": false,
"use_standard_auth": false,
"enable_coprocess_auth": false,
"jwt_signing_method": "",
"jwt_source": "",
"jwt_identity_base_field": "",
"jwt_client_base_field": "",
"jwt_policy_field_name": "",
"notifications": {
"shared_secret": "",
"oauth_on_keychange_url": ""
},
"enable_signature_checking": false,
"hmac_allowed_clock_skew": -1,
"base_identity_provided_by": "UnsetAuth",
"definition": {
"location": "header",
"key": "x-api-version"
},
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"expires": "",
"paths": {
"ignored": [],
"white_list": [],
"black_list": []
},
"use_extended_paths": true,
"extended_paths": {
"ignored": [
{
"path": "/test-path/",
"method_actions": {
"GET": {
"action": "no_action",
"code": 200,
"data": "qzdqzdqzjdkqbdkjbqzkdbjqkzdbjkqzbdkjqzbd",
"headers": {}
}
}
},
{
"path": "/test-path/reply",
"method_actions": {
"GET": {
"action": "reply",
"code": 200,
"data": "{\"foo\":\"bar\"}"
}
}
}
]
},
"global_headers": {},
"global_headers_remove": [],
"ignore_endpoint_case": false,
"global_size_limit": 0,
"override_target": ""
}
}
},
"uptime_tests": {
"check_list": [],
"config": {
"expire_utime_after": 0,
"service_discovery": {
"use_discovery_service": false,
"query_endpoint": "",
"use_nested_query": false,
"parent_data_path": "",
"data_path": "",
"port_data_path": "",
"target_path": "",
"use_target_list": false,
"cache_timeout": 60,
"endpoint_returns_list": false
},
"recheck_wait": 0
}
},
"proxy": {
"preserve_host_header": false,
"listen_path": "/6b6c9fc301614e607c591e4af785c465/",
"target_url": "http://localhost:8080/",
"strip_listen_path": true,
"enable_load_balancing": false,
"target_list": [],
"check_host_against_uptime_tests": false,
"service_discovery": {
"use_discovery_service": false,
"query_endpoint": "",
"use_nested_query": false,
"parent_data_path": "",
"data_path": "",
"port_data_path": "",
"target_path": "",
"use_target_list": false,
"cache_timeout": 0,
"endpoint_returns_list": false
}
},
"disable_rate_limit": false,
"disable_quota": false,
"custom_middleware": {
"pre": [],
"post": [
{
"name": "SouinRequestHandler",
"path": "/opt/tyk-gateway/middleware/souin-plugin.so"
}
],
"post_key_auth": [],
"auth_check": {
"name": "",
"path": "",
"require_session": false
},
"response": [],
"driver": "goplugin",
"id_extractor": {
"extract_from": "",
"extract_with": "",
"extractor_config": {}
}
},
"custom_middleware_bundle": "",
"cache_options": {
"cache_timeout": 60,
"enable_cache": true,
"cache_all_safe_requests": false,
"cache_response_codes": [],
"enable_upstream_cache_control": false
},
"session_lifetime": 0,
"active": true,
"auth_provider": {
"name": "",
"storage_engine": "",
"meta": {}
},
"session_provider": {
"name": "",
"storage_engine": "",
"meta": {}
},
"event_handlers": {
"events": {}
},
"enable_batch_request_support": false,
"enable_ip_whitelisting": false,
"allowed_ips": [],
"dont_set_quota_on_create": false,
"expire_analytics_after": 0,
"response_processors": [],
"CORS": {
"enable": false,
"allowed_origins": [],
"allowed_methods": [],
"allowed_headers": [],
"exposed_headers": [],
"allow_credentials": false,
"max_age": 24,
"options_passthrough": false,
"debug": false
},
"domain": "",
"do_not_track": false,
"tags": [],
"enable_context_vars": true,
"config_data": {},
"tag_headers": [],
"global_rate_limit": {
"rate": 0,
"per": 0
},
"strip_auth_data": false,
"souin": {
"default_cache": {
"ttl": "10s"
}
}
}
26 changes: 26 additions & 0 deletions plugins/tyk/samples/apps/httpbin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name":"httpbin.org",
"api_id":"3",
"org_id":"3",
"use_keyless": true,
"version_data": {
"not_versioned": true,
"versions": {
"Default": {
"name": "Default",
"use_extended_paths": true
}
}
},
"proxy":{
"listen_path":"/httpbin/",
"target_url":"http://httpbin.org/",
"strip_listen_path":true
},
"active":true,
"souin": {
"default_cache": {
"ttl": "10s"
}
}
}
48 changes: 48 additions & 0 deletions plugins/tyk/samples/confs/pump.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"analytics_storage_type": "redis",
"analytics_storage_config": {
"type": "redis",
"host": "tyk-redis",
"port": 6379,
"hosts": null,
"username": "",
"password": "",
"database": 0,
"optimisation_max_idle": 100,
"optimisation_max_active": 100,
"enable_cluster": false
},
"purge_delay": 2,
"pumps": {
"mongo": {
"name": "mongo",
"meta": {
"collection_name": "tyk_analytics",
"mongo_url": "mongodb://tyk-mongo:27017/tyk_analytics",
"max_insert_batch_size_bytes": 80000,
"max_document_size_bytes": 20112
}
},
"mongo-pump-aggregate": {
"name": "mongo-pump-aggregate",
"meta": {
"mongo_url": "mongodb://tyk-mongo:27017/tyk_analytics",
"use_mixed_collection": true
}
},
"mongo-pump-selective": {
"name": "mongo-pump-selective",
"meta": {
"mongo_url": "mongodb://tyk-mongo:27017/tyk_analytics",
"use_mixed_collection": true
}
}
},
"uptime_pump_config": {
"collection_name": "tyk_uptime_analytics",
"mongo_url": "mongodb://tyk-mongo:27017/tyk_analytics",
"max_insert_batch_size_bytes": 500000,
"max_document_size_bytes": 200000
},
"dont_purge_uptime_data": false
}
Loading

0 comments on commit 4f64d7a

Please sign in to comment.