Add client library

Initial code for a client library.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2024-09-29 02:33:01 +02:00
parent 1e84b2e57d
commit 49a39e7970
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57
8 changed files with 137 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
__pycache__
dist
nftables_api.egg-info
nftables_api*.egg-info
venv

1
nft_http_api_client/LICENSE Symbolic link
View File

@ -0,0 +1 @@
../LICENSE

View File

@ -0,0 +1 @@
# RESTful HTTP API for nftables - Client

View 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__

View 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'

View 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

View 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 = ['.']

View 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=.