Pfsense-Fauxapi在Pfsense主机上的客户端蟒
pfsense-fauxapi的Python项目详细描述
pfsensefauxapi-python接口
pfsense fauxapi的python客户端-https://github.com/ndejong/pfsense_fauxapi
作为PyPi包提供,要安装,请安装APIclient以便与 安装了fauxapi包的pfsense主机。
pip3 install pfsense-fauxapi
代码示例
提供了三个python代码示例,演示了接口用法
function-iterate.py
-迭代(几乎)所有fauxapi函数以确认操作。update-aws-aliases.py
-下载最新的awsip-ranges.json
并填充pfsense别名表。usergroup-management.py
-演示以编程方式管理用户和组的能力。
命令行
此外,这个pip包还提供了一个命令行界面,可以与fauxapi一起工作
usage: fauxapi [-h][--host [host]][--apikey [key]][--apisecret [secret]][--verified-ssl][--debug][function][[function] ...][[function-args]] FauxAPI optional arguments: -h, --help show this help message and exit Call: --host [host] Host address of the target pfSense host with the PfsenseFauxapi package installed. --apikey [key] FauxAPI apikey value - alternatively via the FAUXAPI_APIKEY environment variable. --apisecret [secret] FauxAPI apisecret value - alternatively via the FAUXAPI_APIKEY environment variable. --verified-ssl Enable SSL certificate checks - default does NOT check SSL certificates. --debug Enable debug response from the remote FauxAPI - helpful in tracking down issues. [function] The FauxAPI function being called [function-args] Arguments to the function, space separated
命令行示例,使用环境变量传递FAUXAPI_APIKEY
以及FAUXAPI_APIKEY
凭证
$ fauxapi --host 192.168.1.200 gateway_status | jq . {"callid": "5c8d0f7361cba", "action": "gateway_status", "message": "ok", "data": {"gateway_status": {"10.11.12.1": {"monitorip": "10.10.10.1", "srcip": "10.10.10.200", "name": "WAN_DHCP", "delay": "0.422ms", "stddev": "0.073ms", "loss": "0.0%", "status": "none"}}}}
包装测试
对(几乎)所有客户端函数调用的测试都是用模拟的API响应数据实现的 您可以使用pytest检查它们
pytest -v tests
包构建
是否需要/希望从源代码构建包
# obtain the source material git clone https://github.com/ndejong/pfsense_fauxapi_client_python.git cd pfsense_fauxapi_client_python # build the package python3 setup.py sdist bdist_wheel # install the package from the .whl file in the dist path pip install dist/pfsense*.whl