diff --git a/.gitignore b/.gitignore index 84d0cd3..5f7ab70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ __pycache__ dist -nftables_api.egg-info +nftables_api*.egg-info venv diff --git a/nft_http_api_client/LICENSE b/nft_http_api_client/LICENSE new file mode 120000 index 0000000..ea5b606 --- /dev/null +++ b/nft_http_api_client/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file diff --git a/nft_http_api_client/README.md b/nft_http_api_client/README.md new file mode 100644 index 0000000..3040e3d --- /dev/null +++ b/nft_http_api_client/README.md @@ -0,0 +1 @@ +# RESTful HTTP API for nftables - Client diff --git a/nft_http_api_client/nftables_api_client/__init__.py b/nft_http_api_client/nftables_api_client/__init__.py new file mode 100644 index 0000000..470c8b0 --- /dev/null +++ b/nft_http_api_client/nftables_api_client/__init__.py @@ -0,0 +1,11 @@ +""" +A RESTful HTTP API client for nftables +Copyright 2024, Georg Pfuetzenreuter + +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__ diff --git a/nft_http_api_client/nftables_api_client/__version__.py b/nft_http_api_client/nftables_api_client/__version__.py new file mode 100644 index 0000000..1d0a2e0 --- /dev/null +++ b/nft_http_api_client/nftables_api_client/__version__.py @@ -0,0 +1,11 @@ +""" +A RESTful HTTP API client for nftables +Copyright 2024, Georg Pfuetzenreuter + +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' diff --git a/nft_http_api_client/nftables_api_client/client.py b/nft_http_api_client/nftables_api_client/client.py new file mode 100644 index 0000000..3df5e77 --- /dev/null +++ b/nft_http_api_client/nftables_api_client/client.py @@ -0,0 +1,46 @@ +""" +A RESTful HTTP API client for nftables +Copyright 2024, Georg Pfuetzenreuter + +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 diff --git a/nft_http_api_client/pyproject.toml b/nft_http_api_client/pyproject.toml new file mode 100644 index 0000000..42edb1a --- /dev/null +++ b/nft_http_api_client/pyproject.toml @@ -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 = ['.'] diff --git a/nft_http_api_client/setup.cfg b/nft_http_api_client/setup.cfg new file mode 100644 index 0000000..750fe14 --- /dev/null +++ b/nft_http_api_client/setup.cfg @@ -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=.