Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scenario steps #10

Open
wants to merge 1 commit into
base: release/1.0.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions python-steps/api-step/step.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
19 changes: 19 additions & 0 deletions python-steps/api-step/step.py
Original file line number Diff line number Diff line change
@@ -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)