client: implement set_append()

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2024-09-29 13:14:28 +02:00
parent 97dab92da0
commit 98b3f82397
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57

View File

@ -12,6 +12,10 @@ from os import getenv
import urllib3 import urllib3
default_retmap = {
'status': -1,
'data': {},
}
class NftablesRemote: class NftablesRemote:
def __init__(self, endpoint, token=None): def __init__(self, endpoint, token=None):
@ -29,10 +33,7 @@ class NftablesRemote:
def get(self, path): def get(self, path):
retmap = { retmap = default_retmap.copy()
'status': -1,
'data': {},
}
response = urllib3.request( response = urllib3.request(
'GET', 'GET',
@ -44,3 +45,20 @@ class NftablesRemote:
retmap['data'] = response.json() retmap['data'] = response.json()
return retmap 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