Skip to content

Commit

Permalink
Update MQTT broker to use host address
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-josi-aws committed Dec 5, 2024
1 parent 0865e47 commit bc345a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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

0 comments on commit bc345a8

Please sign in to comment.