wso2 / carbon-apimgt

Apache License 2.0
166 stars 626 forks source link

Adding support for filtering block conditions based on api context and version #12461

Closed YasasRangika closed 3 months ago

YasasRangika commented 3 months ago

Purpose

To add filters to the management REST API for blacklisting at https://localhost:9443/api/am/admin/v4/throttling/deny-policies. The filters will filter out block conditions based on API context and version for the API type block conditions.

Example behavior:

Imagine a situation where there are multiple entries for block conditions as follows:

{
    "count": 7,
    "list": [
        {
            "conditionId": "211fefd9-1a52-4095-a0b5-414af102501e",
            "conditionType": "API",
            "conditionValue": "/pizzashack/1.0.0",
            "conditionStatus": true
        },
        {
            "conditionId": "e7f793d6-2bd8-4d7b-8ef8-825ad4592b05",
            "conditionType": "SUBSCRIPTION",
            "conditionValue": null,
            "conditionStatus": true
        },
        {
            "conditionId": "77825b1d-b758-4580-b305-4b26476a0ff1",
            "conditionType": "API",
            "conditionValue": "/test/1.0.0",
            "conditionStatus": true
        },
        {
            "conditionId": "9201f2a1-c4d6-4a3c-926b-6d861c9cfe3d",
            "conditionType": "API",
            "conditionValue": "/test/abc/1.0.0",
            "conditionStatus": true
        },
        {
            "conditionId": "776f4e1b-9a8a-4758-8781-57c60994da51",
            "conditionType": "API",
            "conditionValue": "/aa/1.0.0",
            "conditionStatus": true
        },
        {
            "conditionId": "93f2fe9f-7591-4d80-a3ed-b30fde6f65d3",
            "conditionType": "SUBSCRIPTION",
            "conditionValue": null,
            "conditionStatus": true
        },
        {
            "conditionId": "50fd2d11-b8b8-4f18-833d-0568c355f8b1",
            "conditionType": "APPLICATION",
            "conditionValue": "admin:DefaultApplication",
            "conditionStatus": true
        }
    ]
}

If a user wants to filter out only API type block conditions from the list above, they can query as follows: https://localhost:9443/api/am/admin/v4/throttling/deny-policies?query=conditionType:API

If the user wants to filter out API type block conditions that are added for the exact API context and version, such as /pizzashack/1.0.0, then the user can query using: https://localhost:9443/api/am/admin/v4/throttling/deny-policies?query=conditionType:API&conditionValue:/pizzashack/1.0.0

There are some edge cases when filtering the /test API context using the below ways:

Goal

Fixes: https://github.com/wso2/api-manager/issues/2878