Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for host address in echo server and MQTT broker #113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion localhost-echo-server/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: 'Localhost Echo Server'
description: 'Starts an echo server using Python.'

inputs:
host_address:
description: "Host address for echo server."
required: false
default: "127.0.0.1"
port_number:
description: "Port for echo server."
required: True
Expand All @@ -13,5 +17,10 @@ runs:
shell: bash
run: |
python3 --version
python3 $GITHUB_ACTION_PATH/local_echo_server.py --port_number=${{ inputs.port_number }} &
# Use the host_address input if provided, otherwise default to 127.0.0.1
HOST=${{ inputs.host_address }}
if [[ -z "$HOST" ]]; then
HOST="127.0.0.1"
fi
python3 $GITHUB_ACTION_PATH/local_echo_server.py --host=$HOST --port_number=${{ inputs.port_number }} &
6 changes: 5 additions & 1 deletion localhost-echo-server/local_echo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ async def echo_handler(reader, writer):

if __name__ == '__main__':
parser = ArgumentParser(description='Localhost Echo server.')
parser.add_argument('--host',
type=str,
required=True,
help='Host address for the echo server.')
parser.add_argument('--port_number',
type=int,
required=True,
Expand All @@ -28,7 +32,7 @@ async def echo_handler(reader, writer):
asyncio.set_event_loop(loop)
factory = asyncio.start_server(
echo_handler,
os.environ.get('HOST'),
os.environ.get('HOST', args.host),
os.environ.get('PORT', args.port_number)
)
server = loop.run_until_complete(factory)
Expand Down
13 changes: 12 additions & 1 deletion localhost-mqtt-broker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: 'Localhost MQTT Broker'
description: 'Starts an MQTT Broker using Python. For TLS connections (including mutual authentication), connect to localhost:8883. For plaintext connections, connect to localhost:1883.'

inputs:
host_address:
description: "Host address for echo server."
required: false
default: "127.0.0.1"
root-ca-cert-path:
description: "Root CA certificate file path."
required: True
Expand All @@ -19,5 +23,12 @@ runs:
run: pip install -r $GITHUB_ACTION_PATH/requirements.txt
shell: bash
- name: Run localhost MQTT broker
run: python3 $GITHUB_ACTION_PATH/localhost_mqtt_broker.py --root-ca-cert-path=${{ inputs.root-ca-cert-path }} --server-priv-key-path=${{ inputs.server-priv-key-path }} --server-cert-path=${{ inputs.server-cert-path }} &
run: |
python3 --version
# Use the host_address input if provided, otherwise default to 127.0.0.1
HOST=${{ inputs.host_address }}
if [[ -z "$HOST" ]]; then
HOST="127.0.0.1"
fi
python3 $GITHUB_ACTION_PATH/localhost_mqtt_broker.py --host=$HOST --root-ca-cert-path=${{ inputs.root-ca-cert-path }} --server-priv-key-path=${{ inputs.server-priv-key-path }} --server-cert-path=${{ inputs.server-cert-path }} &
shell: bash
8 changes: 6 additions & 2 deletions localhost-mqtt-broker/localhost_mqtt_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# Parse passed in credentials
parser = ArgumentParser(description='Localhost MQTT broker.')

parser.add_argument('--host',
type=str,
required=True,
help='Host address for the echo server.')
parser.add_argument('--root-ca-cert-path',
type=str,
required=True,
Expand All @@ -31,12 +35,12 @@
"listeners": {
"default": {
"type": "tcp",
"bind": f"{LOCAL_HOST_IP}:1883",
"bind": f"{args.host}:1883",
"max-connections": 1000,
},
"tls": {
"type": "tcp",
"bind": f"{LOCAL_HOST_IP}:8883",
"bind": f"{args.host}:8883",
"max-connections": 1000,
"ssl": "on",
"cafile": args.root_ca_cert_path,
Expand Down
Loading