Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct tags filtering on consumer-group consumers (#88)
Due to the nature of the Consumer Group API, it's not possible to natively filter its Consumers using tags: ``` $ http :8001/consumer_groups/foo_group_1/consumers\?tags="managed-by:deck" HTTP/1.1 400 Bad Request { "code": 11, "message": "invalid option (tags: cannot be used with 'consumer_group_consumers')", "name": "invalid options", "options": { "tags": "cannot be used with 'consumer_group_consumers'" } } ``` So, in order to fetch ConsumerGroup:Consumer mappings, we need to rely on the unfiltered Consumer Group API: ``` $ http :8001/consumer_groups/foo_group_1 HTTP/1.1 200 OK { "consumer_group": { "created_at": 1715183554, "id": "e0e495f2-9acd-41f7-b4da-33659033af13", "name": "foo_group_1", "tags": [ "managed-by-deck" ], "updated_at": 1715183554 }, "consumers": [ { "created_at": 1715183563, "id": "a704b13e-1a9b-409b-9611-fd2bfcea63bb", "tags": [ "managed-by:api" ], "type": 0, "updated_at": 1715183563, "username": "foo", "username_lower": "foo" } ] } ``` This is a problem in cases when Consumer Groups are managed by decK while their mappings with Consumers are managed directly via the API. In such case, since the current library implementation doesn't allow to filter mappings by tags, decK would wipe out the API managed mappings when running against the specific tags it handle: ``` $ cat kong.yaml _format_version: "3.0" _info: select_tags: - managed-by:deck consumer_groups: - id: c0f6c818-470c-4df7-8515-c8e904765fcc name: foo_group_1 tags: - managed-by:deck ``` ``` $ deck gateway sync kong.yaml deleting consumer-group-consumer foo Summary: Created: 0 Updated: 0 Deleted: 1 ``` This commit makes sure the correct filtering is "manually" done, avoiding existing Consumers to be wiped out during syncs when using Tags: ``` $ deck gateway sync kong.yaml Summary: Created: 0 Updated: 0 Deleted: 0 ``` ``` $ http :8001/consumer_groups/foo_group_1 HTTP/1.1 200 OK { "consumer_group": { "created_at": 1716450737, "id": "c0f6c818-470c-4df7-8515-c8e904765fcc", "name": "foo_group_1", "tags": [ "managed-by:deck" ], "updated_at": 1716451431 }, "consumers": [ { "created_at": 1716450861, "id": "bafd4f5d-3f4e-4c0f-8d6c-6901b0b8f483", "tags": [ "managed-by:api" ], "type": 0, "updated_at": 1716450861, "username": "foo" } ] } ``` --------- Co-authored-by: Patryk Małek <[email protected]>
- Loading branch information