def _get_items(  # nosec
    get_items, items_key, params=None, next_token=None, next_token_key="NextToken"
):
    """
    Recursive generic function call which concatenates results.

    Returns a list of items from the same items_key in response.
    If response contains a next token, get_items is called again, and items are concatenated.

    Parameters
    ----------
    get_items : function
        function that returns items which may return a next token
    items_key : string
        key containing items
    params : dict
        params passed to get_items function
    next_token : string
        token returned by first get_items call
    next_token_key : string
        key from get_items response that may contain a next_token

    Returns
    -------
    list
        list of items returned by recursive get_items calls
    """
    if not params:
        params = {}

    if next_token:
        params[next_token_key] = next_token

    response = get_items(**params)
    items = response.get(items_key)
    next_token = response.get(next_token_key)

    if next_token:
        items.extend(
            _get_items(get_items, items_key, params, next_token, next_token_key)
        )
    return items