Integrate pyhton plugin on docker


#1

Hi,

i’m following this tuto
https://tyk.io/docs/customise-tyk/plugins/rich-plugins/python/tutorial-add-demo-plugin-api/
i read the tips from this post

but i can’t get my plugin to be used (each time i make a call on the APO without the Header : i got the result, when i should have an unauthorized)
curl http://localhost:8080/firstapi_dummy1/anything

here is my plugin

from tyk.decorators import *
from gateway import TykGateway as tyk

@Hook
def MyAuthMiddleware(request, session, metadata, spec):
  auth_header = request.get_header('Authorization')
  tyk.log("##### Here i am, rocking like tykicain #####", "error")
  if auth_header == '47a0c79c427728b3df4af62b9228c8ae':
    tyk.log("I'm logged!", "info")
    tyk.log("Request body" + request.object.body, "info")
    tyk.log("API config_data" + spec['config_data'], "info")
    session.rate = 1000.0
    session.per = 1.0
    metadata["token"] = "47a0c79c427728b3df4af62b9228c8ae"
  return request, session, metadata

here is my manifest :

{
  "file_list": [
    "middleware.py"
  ],
  "custom_middleware": {
    "driver": "python",
    "auth_check": {
      "name": "MyAuthMiddleware"
    }
  }
}

Here’s my API definition
inspired from https://tyk.io/docs/customise-tyk/plugins/rich-plugins/python/tutorial-add-demo-plugin-api/
{
“custom_middleware_bundle”: “dummy_middle1.zip”,
“use_keyless”: false,
“enable_coprocess_auth”: true,
“name”: “Tyk Test API”,
“api_id”: “4”,
“org_id”: “default”,
“definition”: {
“location”: “”,
“key”: “”
},
“use_keyless”: true,
“auth”: {
“auth_header_name”: “authorization”
},
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“expires”: “3000-01-02 15:04”,
“use_extended_paths”: true,
“extended_paths”: {
“ignored”: [],
“white_list”: [],
“black_list”: []
}
}
}
},
“proxy”: {
“listen_path”: “/firstapi_dummy1/”,
“target_url”: “http://httpbin:80”,
“strip_listen_path”: true
},
“do_not_track”: true
}

Here’s another test of the API definition inspired from
https://tyk.io/docs/customise-tyk/plugins/rich-plugins/python/tutorial-add-demo-plugin-api/
{
“name”: “Tyk Test API”,
“api_id”: “4”,
“org_id”: “default”,
“definition”: {
“location”: “header”,
“key”: “version”
},
“auth”: {
“auth_header_name”: “authorization”
},
“use_keyless”: true,
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“expires”: “3000-01-02 15:04”,
“use_extended_paths”: true,
“extended_paths”: {
“ignored”: [],
“white_list”: [],
“black_list”: []
}
}
}
},
“proxy”: {
“listen_path”: “/firstapi_dummy1/”,
“target_url”: “http://httpbin:80”,
“strip_listen_path”: true
},
“custom_middleware_bundle”: “dummy_middle1.zip”
}

Here is part of the starting log :

Apr  2 10:18:00]  INFO main: ----> Fetching Bundle: dummy_middle1.zip
[Apr  2 10:18:00]  INFO main: Checking security policy: Token api_name=Tyk Test API
127.0.0.1 - - [02/Apr/2019 10:18:00] "GET /dummy_middle1.zip HTTP/1.1" 200 -
[Apr  2 10:18:00]  INFO main: ----> Loading bundle: dummy_middle1.zip
[Apr  2 10:18:00]  INFO main: ----> Verifying bundle: dummy_middle1.zip
[Apr  2 10:18:00]  INFO main: ----> Bundle is valid, adding to spec: dummy_middle1.zip
[Apr  2 10:18:00]  INFO main: Checking security policy: Open api_name=Tyk Test API
[Apr  2 10:18:00]  INFO main: Processed and listening on: /firstapi_dummy1/{rest:.*}

when i do a
curl http://localhost:8080/firstapi_dummy1/anything
it seems the Python module is not used (nothing shows in the logs)

I start tyk with python, here is my docker run command
docker run -ti --rm --name tyk_gateway --network tyk -p 7780:8080 -v /opt/docker/tyk/tyk.standalone.conf:/opt/tyk-gateway/tyk.conf -v /opt/docker/tyk/apps:/opt/tyk-gateway/apps -v /opt/docker/tyk/my-tyk-plugin:/opt/tyk-gateway/my-tyk-plugin -v /opt/docker/tyk/entrypoint-plugin.sh:/opt/tyk-gateway/entrypoint.sh -e TYKLANG='-python' tykio/tyk-gateway:latest

I should see something in the logs, but i don’t
I know it’s probably something stupid in the configuration, but i can’t find it
If any configuration master could give me a hint me on the configuration.

Thanks for any help !


#2

Found it !

“use_keyless”:
needs to be at false
in one of the file the parameter was there twice, and in the other it had the wrong value.

Apologies for bothering you,
it helped me writing the issue though