Skip to content

Commit faba278

Browse files
Added basic iotcore mqtt test on cli
1 parent a273e51 commit faba278

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dist/*
88
config.cfg
99
aws-auth
1010
*.log
11-
*.certs
11+
*.certs*
1212
!.github/*
1313
docs/_*
14-
conf.sh
14+
*.sh

src/iotswarm/scripts/cli.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,65 @@ def main(ctx: click.Context, log_config: Path):
4141
main.add_command(test)
4242

4343

44+
@main.command()
45+
@click.pass_context
46+
@click.argument(
47+
"client-id",
48+
type=click.STRING,
49+
)
50+
@click.argument("topic", type=click.STRING)
51+
@click.argument("message", type=click.STRING)
52+
@click.option(
53+
"--endpoint",
54+
type=click.STRING,
55+
required=True,
56+
envvar="IOT_SWARM_MQTT_ENDPOINT",
57+
help="Endpoint of the MQTT receiving host.",
58+
)
59+
@click.option(
60+
"--cert-path",
61+
type=click.Path(exists=True),
62+
required=True,
63+
envvar="IOT_SWARM_MQTT_CERT_PATH",
64+
help="Path to public key certificate for the device. Must match key assigned to the `--client-id` in the cloud provider.",
65+
)
66+
@click.option(
67+
"--key-path",
68+
type=click.Path(exists=True),
69+
required=True,
70+
envvar="IOT_SWARM_MQTT_KEY_PATH",
71+
help="Path to the private key that pairs with the `--cert-path`.",
72+
)
73+
@click.option(
74+
"--ca-cert-path",
75+
type=click.Path(exists=True),
76+
required=True,
77+
envvar="IOT_SWARM_MQTT_CA_CERT_PATH",
78+
help="Path to the root Certificate Authority (CA) for the MQTT host.",
79+
)
80+
def test_mqtt(
81+
ctx: click.Context,
82+
message,
83+
topic,
84+
client_id: str,
85+
endpoint: str,
86+
cert_path: str,
87+
key_path: str,
88+
ca_cert_path: str,
89+
):
90+
"""Tests that a basic message can be sent via mqtt."""
91+
92+
connection = IotCoreMQTTConnection(
93+
endpoint=endpoint,
94+
cert_path=cert_path,
95+
key_path=key_path,
96+
ca_cert_path=ca_cert_path,
97+
client_id=client_id,
98+
)
99+
100+
connection.send_message(message, topic)
101+
102+
44103
@main.group()
45104
@click.pass_context
46105
@click.option(

0 commit comments

Comments
 (0)