This template can be used to create a python based adapter. The template is written in Python.
Template has three actions:
- hello_world
- create_template
- run_script There is also one action which is supposed to be by default in every adapter, verify_target. Usually verify_target action is used to verify connection and credentials to the target during its creation in UI.
Run adapter locally
- Install required packages: python-dotenv, six, requests.
- Create self-signed certificates in the custom python adapter project folder: Run "make create-certs" - this will create all needed certificates to run adapter https service locally
After running certificate creation commands you will have the following files created: "secrets/ssl/cert/certificate.pem" "secrets/ssl/cert/private_key.pem" "secrets/ssl/cert/.disable_cert_validation"
Add following environment variables: export CERTFILE=path_to_certificate.pem export PKEYFILE=path_to_private_key.pem
If you want to use your own certificates, set following environment variables: export CERTFILE=path_to_certificate.pem export PKEYFILE=path_to_private_key.pem export CAFILE=path_to_ca_certificate.pem
- Prepare JAIL environment.
Download Jailkit package and follow the INSTALL.TXT instructions.
Here are common commands to install Jail environment: wget http://olivier.sessink.nl/jailkit/jailkit-2.20.tar.gz tar -xzvf jailkit-2.20.tar.gz cd jailkit-2.20;./configure && make && make install mkdir /jail (or use some other directory) jk_init -j /jail jk_lsh PYTHON_PATH=$(which python) PYTHON_LIB_PATH=$(python -c "import os, inspect; print os.path.dirname(inspect.getfile(inspect))") jk_cp -j /jail $PYTHON_PATH jk_cp -j /jail $PYTHON_LIB_PATH groupadd script_executer adduser script_executer -G script_executer jk_jailuser -n -j /jail script_executer
Export environment variables needed to run the adapter: export JAIL_DIR=/jail export JAIL_USERNAME=script_executer export JAIL_GROUPNAME=script_executer
-
Add the custom adapter project directory to PYTHONPATH using the following command: export PYTHONPATH=PathToCustomPythonAdapterProject
-
Run adapter: python worker/activities-worker
(worker/activities-worker is the main entry point to run the adapter)
Worker URL for requests - http://localhost:8082/api/v1/function
-
setup.py, setup.cfg,requires.txt - are used for building python package
-
Dockerfile - used to create adapter docker container Example commands: cd 'cloned adapter repo folder' python setup.py bdist_wheel docker build -t ad-template ( ad-template - container name for the adapter)
-
Jenkinsfile, Jenkinsfile-lambda - used in jenkins jobs
-
event-json - contains sample api calls to run each action
Actions folder contains three template actions and sample test files:
- Hello World - represents an action to demonstrate input and output parameters.
- Create Template - represents an action with api POST request. BasicConstants.ACTIVITY_2_URL is api relative URL for the action2.
- Run Script - represents an action to run python script in jail env.
- Verify Target - represents an action for verifying target.
common folder - is a common adapter library.
constants folder files: You can change the values of these constants to customize your adapter.
events/event_resolver.py : Type resolver for incoming requests. We have four event types with corresponding actions.
pythonutils - contains different models used in actions.
functions/lambda_function_name/handler.py is used to run adapter as aws lambda function. The name 'lambda_function_name' should be the same as name in adapter lambda schema.
schemas/generate_schemes.py - is used to generate schemes for current template adapter. you can simply run it in python. If you want to make your own changes in schemes please refer to the schemes documentation.
scripts/run_test.sh - script is used in build to run tests
worker/activities-worker - is used to run adapter as microservice