@@ -9,7 +9,6 @@ use regex::Regex;
9
9
use serde_json:: Value ;
10
10
use std:: error:: Error ;
11
11
use std:: hash:: { Hash , Hasher } ;
12
- use std:: path:: PathBuf ;
13
12
use std:: sync:: Arc ;
14
13
use tokio:: sync:: Mutex ;
15
14
use tokio:: task;
@@ -54,23 +53,23 @@ struct Args {
54
53
env = "AWS_IOT_ROOT_CA_PATH" ,
55
54
default_value = "./certs/AmazonRootCA1.pem"
56
55
) ]
57
- root_ca : PathBuf ,
56
+ root_ca_path : String ,
58
57
59
58
/// Path to the device certificate
60
59
#[ arg(
61
60
long,
62
61
env = "AWS_IOT_DEVICE_CERT_PATH" ,
63
62
default_value = "./certs/cert.crt"
64
63
) ]
65
- device_cert : PathBuf ,
64
+ device_cert_path : String ,
66
65
67
66
/// Path to the device private key
68
67
#[ arg(
69
68
long,
70
- env = "AWS_IOT_PRIVATE_KEY_PATH " ,
69
+ env = "AWS_IOT_DEVICE_PRIVATE_KEY_PATH " ,
71
70
default_value = "./certs/key.pem"
72
71
) ]
73
- private_key : PathBuf ,
72
+ device_private_key_path : String ,
74
73
75
74
/// Enable verbose logging
76
75
#[ arg( short, long) ]
@@ -107,12 +106,8 @@ enum CliCommand {
107
106
} ,
108
107
}
109
108
110
- #[ tokio:: main]
111
- async fn main ( ) -> Result < ( ) , Box < dyn Error > > {
112
- let args = Args :: parse ( ) ;
113
- let mut cmd = Args :: command ( ) ;
114
-
115
- if args. verbose {
109
+ fn setup_logging ( verbose : bool ) {
110
+ if verbose {
116
111
env_logger:: Builder :: new ( )
117
112
. filter_level ( log:: LevelFilter :: Debug )
118
113
. init ( ) ;
@@ -121,11 +116,24 @@ async fn main() -> Result<(), Box<dyn Error>> {
121
116
. filter_level ( log:: LevelFilter :: Info )
122
117
. init ( ) ;
123
118
}
119
+ }
124
120
121
+ #[ tokio:: main]
122
+ async fn main ( ) -> Result < ( ) , Box < dyn Error > > {
123
+ let args = Args :: parse ( ) ;
124
+ let mut cmd = Args :: command ( ) ;
125
+
126
+ setup_logging ( args. verbose ) ;
125
127
debug ! ( "Parsed CLI arguments: {:?}" , args) ;
126
128
129
+ let endpoint = args. endpoint ;
130
+ let port = args. port ;
131
+ let client_id = args. client_id ;
132
+ let root_ca_path = args. root_ca_path ;
133
+ let device_cert_path = args. device_cert_path ;
134
+ let device_private_key_path = args. device_private_key_path ;
127
135
let mqtt_option_overrides = MQTTOptionsOverrides {
128
- port : Some ( args . port ) ,
136
+ port : Some ( port) ,
129
137
clean_session : Some ( true ) ,
130
138
keep_alive : None ,
131
139
max_packet_size : None ,
@@ -137,16 +145,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
137
145
transport : None ,
138
146
} ;
139
147
let aws_settings = AWSIoTSettings :: new (
140
- args . client_id . clone ( ) ,
141
- args . root_ca . to_str ( ) . unwrap ( ) . to_string ( ) ,
142
- args . device_cert . to_str ( ) . unwrap ( ) . to_string ( ) ,
143
- args . private_key . to_str ( ) . unwrap ( ) . to_string ( ) ,
144
- args . endpoint . clone ( ) ,
148
+ client_id. clone ( ) ,
149
+ root_ca_path . clone ( ) ,
150
+ device_cert_path . clone ( ) ,
151
+ device_private_key_path . clone ( ) ,
152
+ endpoint. clone ( ) ,
145
153
Some ( mqtt_option_overrides) ,
146
154
) ;
147
155
148
- debug ! ( "Connecting with client_id: {}" , args. client_id. blue( ) ) ;
149
- debug ! ( "Using endpoint: {}" , args. endpoint) ;
156
+ debug ! (
157
+ "Connecting to {} with client_id: {}" ,
158
+ endpoint. clone( ) . blue( ) ,
159
+ client_id. clone( ) . blue( ) ,
160
+ ) ;
150
161
151
162
let ( iot_core_client, ( event_loop, sender) ) = AWSIoTAsyncClient :: new ( aws_settings) . await ?;
152
163
let raw_client = iot_core_client. get_client ( ) . await ;
0 commit comments