@@ -73,7 +73,7 @@ impl Command for DownloadCertCmd {
73
73
74
74
impl DownloadCertCmd {
75
75
async fn download_device_certificate ( & self ) -> Result < ( ) , Error > {
76
- let ( common_name, security_token) = self . get_registration_data ( ) ?;
76
+ let ( common_name, security_token) = self . get_registration_data ( ) . await ?;
77
77
if self . generate_csr {
78
78
create_device_csr (
79
79
common_name. clone ( ) ,
@@ -129,25 +129,30 @@ impl DownloadCertCmd {
129
129
/// Prompt the user for the device id and the security token
130
130
///
131
131
/// - unless already set on the command line or using env variables.
132
- fn get_registration_data ( & self ) -> Result < ( String , String ) , std:: io:: Error > {
133
- let device_id = if self . device_id . is_empty ( ) {
134
- print ! ( "Enter device id: " ) ;
135
- std:: io:: stdout ( ) . flush ( ) ?;
136
- let mut input = String :: new ( ) ;
137
- std:: io:: stdin ( ) . read_line ( & mut input) ?;
138
- input. trim_end_matches ( [ '\n' , '\r' ] ) . to_string ( )
139
- } else {
140
- self . device_id . clone ( )
141
- } ;
142
-
143
- // Read the security token from /dev/tty
144
- let security_token = if self . security_token . is_empty ( ) {
145
- rpassword:: read_password_from_tty ( Some ( "Enter security token: " ) ) ?
146
- } else {
147
- self . security_token . clone ( )
148
- } ;
149
-
150
- Ok ( ( device_id, security_token) )
132
+ async fn get_registration_data ( & self ) -> Result < ( String , String ) , std:: io:: Error > {
133
+ let self_device_id = self . device_id . clone ( ) ;
134
+ let self_security_token = self . security_token . clone ( ) ;
135
+ tokio:: task:: spawn_blocking ( move || {
136
+ let device_id = if self_device_id. is_empty ( ) {
137
+ print ! ( "Enter device id: " ) ;
138
+ std:: io:: stdout ( ) . flush ( ) ?;
139
+ let mut input = String :: new ( ) ;
140
+ std:: io:: stdin ( ) . read_line ( & mut input) ?;
141
+ input. trim_end_matches ( [ '\n' , '\r' ] ) . to_string ( )
142
+ } else {
143
+ self_device_id
144
+ } ;
145
+
146
+ // Read the security token from /dev/tty
147
+ let security_token = if self_security_token. is_empty ( ) {
148
+ rpassword:: read_password_from_tty ( Some ( "Enter security token: " ) ) ?
149
+ } else {
150
+ self_security_token
151
+ } ;
152
+
153
+ Ok ( ( device_id, security_token) )
154
+ } )
155
+ . await ?
151
156
}
152
157
153
158
/// Post the device CSR
0 commit comments