Compare commits
No commits in common. "8913c5a2fe1c7d760c0a48a9f53dbe03ee83a7de" and "97dab92da0f6b1a4215a7ea2fd20cd0a082cd3fa" have entirely different histories.
8913c5a2fe
...
97dab92da0
@ -1,14 +1 @@
|
|||||||
# RESTful HTTP API for nftables - Client
|
# RESTful HTTP API for nftables - Client
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
The token can be passed either as an argument to `NftablesRemote()` or in the environment variable `NFT-API-TOKEN`.
|
|
||||||
|
|
||||||
```
|
|
||||||
# initialize
|
|
||||||
from nftables_api_client.client import NftablesRemote
|
|
||||||
nft = NftablesRemote('http://localhost:9090', 'mytoken')
|
|
||||||
|
|
||||||
# do things
|
|
||||||
nft.get('/set/inet/filter/foo')
|
|
||||||
```
|
|
||||||
|
@ -12,10 +12,6 @@ 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):
|
||||||
@ -33,7 +29,10 @@ class NftablesRemote:
|
|||||||
|
|
||||||
|
|
||||||
def get(self, path):
|
def get(self, path):
|
||||||
retmap = default_retmap.copy()
|
retmap = {
|
||||||
|
'status': -1,
|
||||||
|
'data': {},
|
||||||
|
}
|
||||||
|
|
||||||
response = urllib3.request(
|
response = urllib3.request(
|
||||||
'GET',
|
'GET',
|
||||||
@ -45,20 +44,3 @@ 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
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user