From 98b3f82397c19bce845a025b3accfd14ca61f31e Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sun, 29 Sep 2024 13:14:28 +0200 Subject: [PATCH] client: implement set_append() Signed-off-by: Georg Pfuetzenreuter --- .../nftables_api_client/client.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/nft_http_api_client/nftables_api_client/client.py b/nft_http_api_client/nftables_api_client/client.py index 3df5e77..ab2d7d4 100644 --- a/nft_http_api_client/nftables_api_client/client.py +++ b/nft_http_api_client/nftables_api_client/client.py @@ -12,6 +12,10 @@ from os import getenv import urllib3 +default_retmap = { + 'status': -1, + 'data': {}, +} class NftablesRemote: def __init__(self, endpoint, token=None): @@ -29,10 +33,7 @@ class NftablesRemote: def get(self, path): - retmap = { - 'status': -1, - 'data': {}, - } + retmap = default_retmap.copy() response = urllib3.request( 'GET', @@ -44,3 +45,20 @@ class NftablesRemote: retmap['data'] = response.json() return retmap + + def set_append(self, path, addresses): + retmap = default_retmap.copy() + + response = urllib3.request( + 'POST', + f'{self.endpoint}/{path}', + headers=self.auth_headers, + json={ + 'addresses': addresses, + }, + ) + + retmap['status'] = response.status + retmap['data'] = response.json() + + return retmap