Skip to content

Commit

Permalink
default header fix, custom auth fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kudj committed Jan 7, 2025
1 parent 7ba976f commit 656404c
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 5 deletions.
13 changes: 8 additions & 5 deletions python-sync-actions/src/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def search_dict(d):
return results


def _remove_auth_from_dict(dictionary: dict, to_remove: list) -> dict:
def _remove_auth_from_dict(dictionary: dict, to_remove: list, auth_method: str) -> dict:
filtered_dict = {}
for key, value in dictionary.items():
if isinstance(value, dict):
if isinstance(value, dict) and auth_method == 'bearer':
if key != 'Authorization':
filtered_value = _remove_auth_from_dict(value, to_remove)
if filtered_value:
Expand Down Expand Up @@ -189,8 +189,11 @@ def convert_to_v2(configuration: dict) -> list[Configuration]:
default_headers_org = api_json.get('http', {}).get('headers', {})
default_query_parameters_org = api_json.get('http', {}).get('defaultOptions', {}).get('params', {})

default_headers = _remove_auth_from_dict(default_headers_org, _return_ui_params(configuration))
default_query_parameters = _remove_auth_from_dict(default_query_parameters_org, _return_ui_params(configuration))
auth_method = configuration.get('config').get('__AUTH_METHOD')

default_headers = _remove_auth_from_dict(default_headers_org, _return_ui_params(configuration), auth_method)
default_query_parameters = _remove_auth_from_dict(default_query_parameters_org, _return_ui_params(configuration),
auth_method)

pagination = {}
if api_json.get('pagination', {}).get('scrollers'):
Expand Down Expand Up @@ -380,7 +383,7 @@ def convert(cls, config_parameters: dict) -> Authentication | None:
auth_method = config_parameters.get('config', {}).get('__AUTH_METHOD', None)
# or take it form the authentication section
auth_method = auth_method or config_parameters.get('api', {}).get('authentication', {}).get('type')
if not auth_method:
if not auth_method or auth_method == 'custom':
return None

methods = {
Expand Down
57 changes: 57 additions & 0 deletions python-sync-actions/tests/calls/010-default-header/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"storage": {},
"parameters": {
"__SELECTED_JOB": "0",

"config": {
"jobs": [
{
"__NAME": "orders",
"endpoint": "010-default-header/orders",
"method": "GET",
"dataType": "",
"dataField": "nested.orders"
}
],
"test": "test-value",
"concat": {
"function": "concat",
"args": [
"hello",
"-world"
]
},
"debug": false,
"outputBucket": "in.c-",
"incrementalOutput": false,
"#BEARER_TOKEN": "token"
},
"api": {
"baseUrl": "http://mock-server:80/",
"http": {
"headers": {
"Authorization": {
"attr": "#BEARER_TOKEN"
}
}
}
},
"http": {
"maxRetries": 10,
"codes": [
500,
502,
503,
504,
408,
420,
429
]
}
},
"action": "test_request",
"image_parameters": {
},
"authorization": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET /010-default-header/orders
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accept: */*
authorization: Bearer token
82 changes: 82 additions & 0 deletions python-sync-actions/tests/calls/010-default-header/orders.response
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"nested": {
"orders": [
{
"id": 1,
"customer": "John Doe",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
},
{
"id": 2,
"customer": "Jan Novak",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
},
{
"id": 3,
"customer": "Jana Novakova",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
},
{
"id": 4,
"customer": "Bob Smith",
"address": "123 Main St",
"items": [
{
"id": 1,
"name": "Widget",
"price": 9.99,
"quantity": 2
},
{
"id": 2,
"name": "Thing",
"price": 5.99,
"quantity": 5
}
]
}
]
}
}

0 comments on commit 656404c

Please sign in to comment.