Add client library
Initial code for a client library. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
1e84b2e57d
commit
49a39e7970
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
__pycache__
|
||||
dist
|
||||
nftables_api.egg-info
|
||||
nftables_api*.egg-info
|
||||
venv
|
||||
|
1
nft_http_api_client/LICENSE
Symbolic link
1
nft_http_api_client/LICENSE
Symbolic link
@ -0,0 +1 @@
|
||||
../LICENSE
|
1
nft_http_api_client/README.md
Normal file
1
nft_http_api_client/README.md
Normal file
@ -0,0 +1 @@
|
||||
# RESTful HTTP API for nftables - Client
|
11
nft_http_api_client/nftables_api_client/__init__.py
Normal file
11
nft_http_api_client/nftables_api_client/__init__.py
Normal file
@ -0,0 +1,11 @@
|
||||
"""
|
||||
A RESTful HTTP API client for nftables
|
||||
Copyright 2024, Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
|
||||
|
||||
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence").
|
||||
You may not use this work except in compliance with the Licence.
|
||||
An English copy of the Licence is shipped in a file called LICENSE along with this applications source code.
|
||||
You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
|
||||
"""
|
||||
|
||||
from .__version__ import __version__ as __version__
|
11
nft_http_api_client/nftables_api_client/__version__.py
Normal file
11
nft_http_api_client/nftables_api_client/__version__.py
Normal file
@ -0,0 +1,11 @@
|
||||
"""
|
||||
A RESTful HTTP API client for nftables
|
||||
Copyright 2024, Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
|
||||
|
||||
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence").
|
||||
You may not use this work except in compliance with the Licence.
|
||||
An English copy of the Licence is shipped in a file called LICENSE along with this applications source code.
|
||||
You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
|
||||
"""
|
||||
|
||||
__version__ = '0.0.1'
|
46
nft_http_api_client/nftables_api_client/client.py
Normal file
46
nft_http_api_client/nftables_api_client/client.py
Normal file
@ -0,0 +1,46 @@
|
||||
"""
|
||||
A RESTful HTTP API client for nftables
|
||||
Copyright 2024, Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
|
||||
|
||||
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence").
|
||||
You may not use this work except in compliance with the Licence.
|
||||
An English copy of the Licence is shipped in a file called LICENSE along with this applications source code.
|
||||
You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12.
|
||||
"""
|
||||
|
||||
from os import getenv
|
||||
|
||||
import urllib3
|
||||
|
||||
|
||||
class NftablesRemote:
|
||||
def __init__(self, endpoint, token=None):
|
||||
if token is None:
|
||||
token = getenv('NFT-API-TOKEN')
|
||||
|
||||
if token is None:
|
||||
raise ValueError('Missing token, pass one as an argument or via NFT-API-TOKEN.')
|
||||
|
||||
self.endpoint = endpoint
|
||||
|
||||
self.auth_headers = {
|
||||
'X-NFT-API-Token': token,
|
||||
}
|
||||
|
||||
|
||||
def get(self, path):
|
||||
retmap = {
|
||||
'status': -1,
|
||||
'data': {},
|
||||
}
|
||||
|
||||
response = urllib3.request(
|
||||
'GET',
|
||||
f'{self.endpoint}/{path}',
|
||||
headers=self.auth_headers,
|
||||
)
|
||||
|
||||
retmap['status'] = response.status
|
||||
retmap['data'] = response.json()
|
||||
|
||||
return retmap
|
49
nft_http_api_client/pyproject.toml
Normal file
49
nft_http_api_client/pyproject.toml
Normal file
@ -0,0 +1,49 @@
|
||||
[build-system]
|
||||
requires = ['setuptools', 'wheel']
|
||||
build-backend = 'setuptools.build_meta'
|
||||
|
||||
|
||||
[project]
|
||||
name = 'nftables_api-client'
|
||||
description = 'RESTful HTTP API for nftables (client)'
|
||||
dynamic = ['license', 'readme', 'version']
|
||||
authors = [
|
||||
{ name='Georg Pfuetzenreuter', email='georg+python@lysergic.dev' },
|
||||
]
|
||||
classifiers = [
|
||||
'Development Status :: 3 - Alpha',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Programming Language :: Python :: 3.7',
|
||||
'Programming Language :: Python :: 3.8',
|
||||
'Programming Language :: Python :: 3.9',
|
||||
'Programming Language :: Python :: 3.10',
|
||||
'Programming Language :: Python :: 3.11',
|
||||
'Programming Language :: Python :: 3.12',
|
||||
'Topic :: Software Development',
|
||||
'Typing :: Typed',
|
||||
'Operating System :: POSIX :: Linux',
|
||||
]
|
||||
requires-python = '>=3.6'
|
||||
|
||||
dependencies = [
|
||||
'urllib3',
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
'pytest',
|
||||
'ruff',
|
||||
]
|
||||
|
||||
[tool.setuptools]
|
||||
include-package-data = false
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
version = {attr = 'nftables_api_client.__version__'}
|
||||
readme = {file = ['README.md']}
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ['.']
|
17
nft_http_api_client/setup.cfg
Normal file
17
nft_http_api_client/setup.cfg
Normal file
@ -0,0 +1,17 @@
|
||||
[metadata]
|
||||
name = nftables_api-client
|
||||
version = attr: nftables_api_client.__version__
|
||||
author = Georg Pfuetzenreuter
|
||||
author_email = georg+python@lysergic.dev
|
||||
description = RESTful HTTP API for nftables (Client)
|
||||
license = EUPL-1.2
|
||||
long_description = file: README.md, LICENSE
|
||||
|
||||
[options]
|
||||
package_dir=
|
||||
=.
|
||||
packages=find:
|
||||
python_requires = >=3.6
|
||||
|
||||
[options.packages.find]
|
||||
where=.
|
Loading…
x
Reference in New Issue
Block a user