Skip to content

Commit 81ad7ff

Browse files
committed
Turning into proper Python package
1 parent 326ab40 commit 81ad7ff

File tree

9 files changed

+58
-39
lines changed

9 files changed

+58
-39
lines changed

.idea/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
11
# HAProxy SPOA
2-
This is a rudimentary, but functional implementation of a Stream Processing Offload Agent (SPOA) for HAProxy 1.8 and above, written in pure Python.
2+
A pure Python implementation of an HAProxy Stream Processing Offload Agent with asyncio support.
3+
4+
This library handles the lower level details of the Stream Processing Offload Protocol, allowing quick implementation of custom agents.
5+
See the `example` folder for the full example, including an example HAProxy configuration.
6+
7+
```python
8+
from ipaddress import IPv4Address
9+
10+
from haproxyspoa.payloads.ack import AckPayload
11+
from haproxyspoa.spoa_server import SpoaServer
12+
13+
agent = SpoaServer()
14+
15+
16+
@agent.handler("earth-to-mars")
17+
async def handle_earth_to_mars(src: IPv4Address, req_host: str):
18+
return AckPayload().set_txn_var("src_echo", str(src) + req_host)
19+
20+
21+
if __name__ == "__main__":
22+
agent.run(host='127.0.0.1', port=9002)
23+
```
24+
25+
## TODO:
26+
* Add automated tests of our SPOP protocol implementation
27+
* Our target runtime was Python 3.8 or above, but it is possible this implementation could work with earlier versions.
28+
* Better debug logging / crash handling.
29+
* Document a recommended deployment strategy.

haproxyspoa/spoa_server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import functools
3+
import logging
34
from collections import defaultdict
45
from typing import List
56

@@ -34,10 +35,10 @@ async def handle_connection(self, reader: asyncio.StreamReader, writer: asyncio.
3435
await self.handle_hello_handshake(haproxy_hello_frame, writer)
3536

3637
if HaproxyHelloPayload(haproxy_hello_frame.payload).healthcheck():
37-
print("It is just a health check, immediately disconnecting")
38+
logging.info("It is just a health check, immediately disconnecting")
3839
return
3940

40-
print("Completed new handshake with Haproxy")
41+
logging.info("Completed new handshake with Haproxy")
4142

4243
while True:
4344
frame = await Frame.read_frame(reader)
@@ -82,7 +83,7 @@ async def send_agent_disconnect(self, writer: asyncio.StreamWriter):
8283
async def handle_haproxy_disconnect(self, frame: Frame):
8384
payload = HaproxyDisconnectPayload(frame.payload)
8485
if payload.status_code() != DisconnectStatusCode.NORMAL:
85-
print(f"Haproxy is disconnecting us with status code {payload.status_code()} - `{payload.message()}`")
86+
logging.info(f"Haproxy is disconnecting us with status code {payload.status_code()} - `{payload.message()}`")
8687

8788
async def handle_hello_handshake(self, frame: Frame, writer: asyncio.StreamWriter):
8889
agent_hello_frame = AgentHelloFrame(

setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pathlib
2+
from setuptools import setup, find_packages
3+
4+
README = (pathlib.Path(__file__).parent / "README.md").read_text()
5+
6+
setup(
7+
name="haproxyspoa",
8+
version="0.0.1",
9+
description="A pure-python asyncio implementation of an HAProxy Stream Processing Offload Agent (SPOA)",
10+
long_description=README,
11+
long_description_content_type="text/markdown",
12+
url="https://github.com/krrg/haproxy-python-spoa",
13+
author="Ken Reese",
14+
author_email="[email protected]",
15+
license="Apache 2",
16+
classifiers=[
17+
"License :: OSI Approved :: Apache Software License",
18+
"Programming Language :: Python :: 3",
19+
# "Programming Language :: Python :: 3.7",
20+
"Programming Language :: Python :: 3.8",
21+
"Programming Language :: Python :: 3.9",
22+
],
23+
packages=find_packages(exclude=("example")),
24+
# include_package_data=True,
25+
install_requires=[],
26+
)

0 commit comments

Comments
 (0)