Compare commits
2 Commits
97dab92da0
...
8913c5a2fe
Author | SHA1 | Date | |
---|---|---|---|
8913c5a2fe | |||
98b3f82397 |
@ -1 +1,14 @@
|
||||
# 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,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user