Skip to content

Commit

Permalink
Solved misunderstanding within keep_alive for mllp server and http(s)…
Browse files Browse the repository at this point in the history
… client, updated README, updated yml to publish on Docker Hub
  • Loading branch information
tiagoepr committed Aug 25, 2022
1 parent a2b0784 commit 1cd29e0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 30 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ jobs:
asset_name: ${{ env.name }}
asset_content_type: application/zip

- name: Docker login
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Build the Docker image
run: docker build . --file Dockerfile --tag tiagoepr/mllp-https:$(github.ref)




#name: Publish ${package_name} to PyPI / GitHub
Expand Down
53 changes: 33 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# MLLP/HTTP(S)

[![PyPI](https://img.shields.io/pypi/v/mllp-https)](https://pypi.org/project/mllp-https/)


[Project](https://github.com/tiagoepr/mllp-https/) addapted by: Tiago Rodrigues, SECTRA Iberia, 2022 <br>

This project results on an enhanced package supporting HTTPS of the [original project](https://pypi.org/project/mllp-http/), whose original credits are given to [Rivet Health](https://pypi.org/user/rivet/)
This project results of an enhanced package supporting HTTPS of the [original project](https://pypi.org/project/mllp-http/), whose original credits are given to [Rivet Health](https://pypi.org/user/rivet/)



<p align="center">
<img src="doc/logo.png">
<img src="https://github.com/tiagoepr/mllp-https/raw/master/doc/logo.png">
</p>

## Overview
Expand Down Expand Up @@ -51,73 +53,83 @@ of the HL7 protocol.

## Install


### By [Pip](https://pypi.org/project/awscli-saml/)
```sh
pip install mllp-https
```

### By Command Line
Supports HTTPS (Version 1.2.1)<br>
On the project folder, run the command:
```sh
python setup.py install
```

### By [Pip](https://pypi.org/project/awscli-saml/)
Only from the [original project](https://pypi.org/project/mllp-http/). Without HTTPS functionalities yet!
```sh
pip install mllp-http
```


## Run as
```sh
http2mllp mllp://localhost:2575
http2mllp localhost --mllp_port 2575

mllp2http http://localhost:8000

https2mllp mllp://localhost:2575
https2mllp localhost --mllp_port 2575

mllp2https https://localhost:8000
```

### [Docker](https://hub.docker.com/r/rivethealth/aws-saml)
Only from the [original project](https://pypi.org/project/mllp-http/). Without HTTPS functionalities yet!
### [Docker](https://hub.docker.com/r/tiagoepr/mllp-https)
```sh
docker pull rivethealth/mllp-http
docker pull tiagoepr/mllp-https
```

Run as

```sh
docker run -it -p 2575:2575 --rm rivethealth/mllp-http http2mllp mllp://localhost:2575
docker run -it -p 2575:2575 --rm tiagoepr/mllp-https http2mllp localhost --mllp_port 2575

docker run -it -p 2575:2575 --rm rivethealth/mllp-http mllp2http http://localhost:8000
docker run -it -p 2575:2575 --rm tiagoepr/mllp-https mllp2http http://localhost:8000

docker run -it -p 2575:2575 --rm tiagoepr/mllp-https https2mllp localhost --mllp_port 2575

docker run -it -p 2575:2575 --rm tiagoepr/mllp-https mllp2http http://localhost:8000
```

## Usage

### http2mllp

```
usage: http2mllp [-h] [-H HOST] [-p PORT] [--keep-alive KEEP_ALIVE] [--log-level {error,warn,info}] [--mllp-max-messages MLLP_MAX_MESSAGES] [--mllp-release {1}]
[--timeout TIMEOUT] [-v]
usage: http2mllp [-h] [-H HOST] [-p PORT] [--keep-alive KEEP_ALIVE] [--log-level {error,warn,info}]
[--mllp-keep-alive MLLP_KEEP_ALIVE] [--mllp-max-messages MLLP_MAX_MESSAGES] [--mllp-release {1}]
[--timeout TIMEOUT] [--content-type CONTENT_TYPE] [-v] [--mllp_port MLLP_PORT]
mllp_url
HTTP server that proxies an MLLP server.
Expects an MLLP response message and uses it as the HTTP response.
positional arguments:
mllp_url MLLP URL, e.g. mllp://hostname:port
mllp_url MLLP URL, Defaulf: hostname
optional arguments:
-h, --help show this help message and exit
-H HOST, --host HOST HTTP host (default: 0.0.0.0)
-p PORT, --port PORT HTTP port (default: 8000)
--keep-alive KEEP_ALIVE
keep-alive in milliseconds, or unlimited if -1. (default: 0)
keep-alive in milliseconds, or unlimited if -1. (default: -1)
--log-level {error,warn,info}
--mllp-keep-alive MLLP_KEEP_ALIVE
keep-alive in milliseconds, or unlimited if -1. (default: -1)
--mllp-max-messages MLLP_MAX_MESSAGES
maximum number of messages per connection, or unlimited if -1. (default: -1)
--mllp-release {1} MLLP release version (default: 1)
--timeout TIMEOUT socket timeout, in milliseconds, or unlimited if 0. (default: 0)
--content-type CONTENT_TYPE
HTTP Content-Type header (default: x-application/hl7-v2+er7)
-v, --version show program's version number and exit
--mllp_port MLLP_PORT
MLLP PORT (default: 2575)
```

### mllp2http
Expand Down Expand Up @@ -169,9 +181,10 @@ optional arguments:
-H HOST, --host HOST HTTPS host (default: 0.0.0.0)
-p PORT, --port PORT HTTPS port (default: 8000)
--keep-alive KEEP_ALIVE
keep-alive in milliseconds, or unlimited if -1. (default: 0)
keep-alive in milliseconds, or unlimited if -1. (default: -1)
--log-level {error,warn,info}
--mllp-keep-alive MLLP_KEEP_ALIVE
keep-alive in milliseconds, or unlimited if -1. (default: -1)
--mllp-max-messages MLLP_MAX_MESSAGES
maximum number of messages per connection, or unlimited if -1. (default: -1)
--mllp-release {1} MLLP release version (default: 1)
Expand Down
5 changes: 3 additions & 2 deletions mllp_http_https/http2mllp.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ def send(self, data):


class HttpServerOptions:
def __init__(self, timeout, content_type):
def __init__(self, timeout, content_type, keep_alive):
self.timeout = timeout
self.content_type = content_type
self.keep_alive = keep_alive


class HttpHandler(http.server.BaseHTTPRequestHandler):
Expand Down Expand Up @@ -163,7 +164,7 @@ def serve(address, options, mllp_address, mllp_options):
handler = functools.partial(
HttpHandler,
content_type=options.content_type,
keep_alive=mllp_options.keep_alive,
keep_alive=options.keep_alive,
timeout=options.timeout or None,
mllp_client=client,
)
Expand Down
7 changes: 4 additions & 3 deletions mllp_http_https/https2mllp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _connect(self):
if self.options.timeout:
s.settimeout(self.options.timeout)
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 10)
#print(self.address)
print(self.address)
s.connect(self.address)
connection = MllpConnection(s)
if self.options.keep_alive is not None:
Expand Down Expand Up @@ -110,11 +110,12 @@ def send(self, data):


class HttpsServerOptions:
def __init__(self, timeout, content_type, certfile, keyfile):
def __init__(self, timeout, content_type, certfile, keyfile, keep_alive):
self.timeout = timeout
self.content_type = content_type
self.certfile = certfile
self.keyfile = keyfile
self.keep_alive = keep_alive


class HttpsHandler(http.server.BaseHTTPRequestHandler):
Expand Down Expand Up @@ -151,7 +152,7 @@ def serve(address, options, mllp_address, mllp_options):
handler = functools.partial(
HttpsHandler,
content_type=options.content_type,
keep_alive=mllp_options.keep_alive,
keep_alive=options.keep_alive,
timeout=options.timeout or None,
mllp_client=client,
)
Expand Down
13 changes: 9 additions & 4 deletions mllp_http_https/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def http2mllp():
parser.add_argument(
"--mllp-keep-alive",
type=int,
default=10 * 1000,
default=-1,
help="keep-alive in milliseconds, or unlimited if -1.",
)
parser.add_argument(
"--mllp-max-messages",
Expand Down Expand Up @@ -90,7 +91,7 @@ def http2mllp():
parser.add_argument(
"mllp_url",
#type=url_type,
help="MLLP URL, e.g. mllp://hostname"
help="MLLP URL, Defaulf: hostname"
)
parser.add_argument(
"--mllp_port",
Expand All @@ -111,6 +112,7 @@ def http2mllp():
http_server_options = mllp_http_https.http2mllp.HttpServerOptions(
timeout=args.timeout / 1000,
content_type=args.content_type,
keep_alive=args.keep_alive,
)
mllp_client_options = mllp_http_https.http2mllp.MllpClientOptions(
keep_alive=args.mllp_keep_alive / 1000,
Expand Down Expand Up @@ -325,7 +327,7 @@ def https2mllp():
parser.add_argument(
"--keep-alive",
type=int,
default=0,
default=-1,
help="keep-alive in milliseconds, or unlimited if -1.",
)
parser.add_argument(
Expand All @@ -336,7 +338,9 @@ def https2mllp():
parser.add_argument(
"--mllp-keep-alive",
type=int,
default=10 * 1000,
#default=10 * 1000,
default=-1,
help="keep-alive in milliseconds, or unlimited if -1.",
)
parser.add_argument(
"--mllp-max-messages",
Expand Down Expand Up @@ -402,6 +406,7 @@ def https2mllp():
content_type=args.content_type,
certfile=args.certfile,
keyfile=args.keyfile,
keep_alive=args.keep_alive,
)
mllp_client_options = mllp_http_https.https2mllp.MllpClientOptions(
keep_alive=args.mllp_keep_alive / 1000,
Expand Down
2 changes: 1 addition & 1 deletion mllp_http_https/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.6"
__version__ = "1.2.7"

0 comments on commit 1cd29e0

Please sign in to comment.