diff --git a/python-steps/api-step/step.json b/python-steps/api-step/step.json new file mode 100644 index 0000000..10add37 --- /dev/null +++ b/python-steps/api-step/step.json @@ -0,0 +1,123 @@ +{ + "meta" : { + "label": "API connect step", + "description": "Call any API as step of a scenario", + "icon": "icon-rocket" + }, + "params": [ + { + "type": "SEPARATOR", + "label": "Authentication" + }, + { + "name": "credential", + "label": "Credential preset", + "type": "PRESET", + "parameterSetId": "credential" + }, + { + "type": "SEPARATOR", + "label": "API call parameters" + }, + { + "name": "custom_key_values", + "label": "Custom keys / values", + "description": "Replace {{key}} by value in presets (optional)", + "type": "KEY_VALUE_LIST", + "visibilityCondition": false + }, + + { + "name": "endpoint_url", + "label": "URL template", + "description": "https://{{variable}}.exmpl.com/usr/{{username}}/details", + "type": "TEXTAREA" + }, + { + "name": "http_method", + "label": "HTTP method", + "description": "", + "type": "SELECT", + "defaultValue": "GET", + "selectChoices":[ + {"value": "GET", "label": "GET"}, + {"value": "POST", "label": "POST"}, + {"value": "PUT", "label": "PUT"}, + {"value": "PATCH", "label": "PATCH"}, + {"value": "DELETE", "label": "DELETE"} + ] + }, + { + "name": "endpoint_query_string", + "label": "Query Params", + "description": "Will add ?key1=val1&key2=val2 to the URL", + "type": "KEY_VALUE_LIST" + }, + { + "name": "endpoint_body", + "label": "Body", + "description": "", + "type": "KEY_VALUE_LIST", + "visibilityCondition": false + }, + { + "name": "endpoint_headers", + "label": "Headers", + "description": "", + "type": "KEY_VALUE_LIST", + "defaultValue": [ + { + "from": "Content-Type", + "to": "application/json" + }, + { + "from": "Accept", + "to": "application/json" + } + ] + }, + { + "name": "body_format", + "label": "Body", + "description": "", + "type": "SELECT", + "defaultValue": null, + "selectChoices":[ + {"value": null, "label": "None"}, + {"value": "FORM_DATA", "label": "Form-data"}, + {"value": "RAW", "label": "Raw"} + ] + }, + { + "name": "text_body", + "label": "Request's body", + "description": "", + "type": "TEXTAREA", + "visibilityCondition": "model.body_format=='RAW'" + }, + { + "name": "key_value_body", + "label": "Request's body", + "description": "", + "type": "KEY_VALUE_LIST", + "visibilityCondition": "(['FORM_DATA'].indexOf(model.body_format)>-1)" + }, + { + "type": "SEPARATOR", + "label": "Advanced" + }, + { + "name": "ignore_ssl_check", + "label": "Ignore SSL check", + "type": "BOOLEAN", + "defaultValue": false + }, + { + "name": "timeout", + "label": "Timeout (s)", + "description": "-1 for no limit", + "type": "INT", + "defaultValue": 3600 + } + ] +} diff --git a/python-steps/api-step/step.py b/python-steps/api-step/step.py new file mode 100644 index 0000000..78ff25b --- /dev/null +++ b/python-steps/api-step/step.py @@ -0,0 +1,19 @@ +from dataiku.customstep import get_plugin_config +from safe_logger import SafeLogger +from rest_api_client import RestAPIClient +from dku_utils import get_dku_key_values, get_endpoint_parameters + + +logger = SafeLogger("api-connect plugin", forbiden_keys=["token", "password"]) + +# settings at the plugin level (set by plugin administrators in the Plugins section) +plugin_config = get_plugin_config() +config = plugin_config.get("config", {}) +logger.info("config={}".format(logger.filter_secrets(config))) +endpoint_parameters = get_endpoint_parameters(config) +credential = config.get("credential", {}) +custom_key_values = get_dku_key_values(config.get("custom_key_values", {})) +client = RestAPIClient(credential, endpoint_parameters, custom_key_values) +client.has_more_data() +json_response = client.paginated_api_call() +logger.info(json_response)