6
6
port: The port where the mqtt server is listening
7
7
username: The username to connect to the broker
8
8
password: The password to connect to the broker
9
- cert_path: The directory containing certificate files.
10
- Can be in root of repo or under rulebooks.
11
- ca_certs: The filename of optional certificate authority file containing
9
+ ca_certs: Multi-line string containing
12
10
certificate used to sign mqtt broker certificates
13
11
validate_certs: Disable certificate validation - true/false
14
- certfile: The optional client certificate file name containing
12
+ certfile: The optional multi-line string containing
15
13
the client certificate, as well as CA certificates needed
16
14
to establish the certificate's authenticity
17
- keyfile: The optional client key file name containing the client
15
+ keyfile: Multi-line string containing the client
18
16
private key
19
17
keyfile_password: The optional password to be used when loading the
20
18
certificate chain
25
23
import asyncio
26
24
import json
27
25
import logging
28
- import os
29
26
from typing import Any , Dict
30
27
31
28
import aiomqtt
32
29
33
30
31
+ async def write_certfile (path , content , logger ):
32
+ """
33
+ Function to write certificate data to a temporary file.
34
+
35
+ Args:
36
+ path (str): Path to temporary file
37
+ content (str): Certificate data
38
+ logger (object): Logger object
39
+ """
40
+ with open (path , "w+" , encoding = 'utf-8' ) as certfile :
41
+ certfile .writelines (content )
42
+ logger .info ("Cert data written to %s" , path )
43
+
34
44
async def main (queue : asyncio .Queue , args : Dict [str , Any ]):
35
45
logger = logging .getLogger ()
36
46
@@ -41,41 +51,36 @@ async def main(queue: asyncio.Queue, args: Dict[str, Any]):
41
51
username = args .get ("username" )
42
52
password = args .get ("password" )
43
53
44
- cert_path = args .get ("cert_path" )
45
54
ca_certs = args .get ("ca_certs" )
46
55
validate_certs = bool (args .get ("validate_certs" ))
47
56
certfile = args .get ("certfile" )
48
57
keyfile = args .get ("keyfile" )
49
58
keyfile_password = args .get ("keyfile_password" )
50
59
51
60
# Path management for certificate files
52
- # This solves an issue when using EDA server and finding file paths
53
- path_to_certs = None
61
+ # EDA Server does not support file handling with decision environments
62
+ # We will accept the cert data as strings and write out temporary files
63
+ # to pass when configuring TLS.
64
+ path_to_certs = "/tmp"
54
65
ca_certs_path = None
55
66
certfile_path = None
56
67
keyfile_path = None
57
68
58
- if cert_path :
59
- # Find the absolute path to the ca_certs filename
60
- for root , dirs , _ in os .walk ('./' , topdown = True ):
61
- for dirname in dirs :
62
- if cert_path in dirname :
63
- path_to_certs = os .path .join (root , dirname )
64
- logger .info ("Cert path found at %s" , path_to_certs )
65
- break
66
-
67
- # Build out cert file absolute paths
69
+ # Build out cert file and absolute paths
68
70
if ca_certs and path_to_certs :
69
- ca_certs_path = f'{ path_to_certs } /{ ca_certs } '
70
- logger .info ("ca_certs path found at %s" , ca_certs_path )
71
+ # Write Certificate to file
72
+ ca_certs_path = f'{ path_to_certs } /ca_certs.crt'
73
+ await write_certfile (ca_certs_path , ca_certs , logger )
71
74
72
75
if certfile and path_to_certs :
73
- certfile_path = f'{ path_to_certs } /{ certfile } '
74
- logger .info ("certfile path found at %s" , certfile_path )
76
+ # Write Certificate to file
77
+ certfile_path = f'{ path_to_certs } /certfile.crt'
78
+ await write_certfile (certfile_path , certfile , logger )
75
79
76
80
if keyfile and path_to_certs :
77
- keyfile_path = f'{ path_to_certs } /{ keyfile } '
78
- logger .info ("keyfile path found at %s" , keyfile_path )
81
+ # Write Certificate to file
82
+ keyfile_path = f'{ path_to_certs } /keyfile.crt'
83
+ await write_certfile (keyfile_path , keyfile , logger )
79
84
80
85
if ca_certs_path or certfile_path or keyfile_path :
81
86
logger .info ("Certificates provided, setting tls_params..." )
0 commit comments