File tree Expand file tree Collapse file tree 3 files changed +28
-9
lines changed
tedge/src/cli/certificate Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -69,17 +69,19 @@ impl C8yEndPoint {
69
69
c8y_profile : Option < & str > ,
70
70
) -> Result < Self , C8yEndPointConfigError > {
71
71
let c8y_config = tedge_config. c8y . try_get ( c8y_profile) ?;
72
- let c8y_host = c8y_config. proxy . client . host . to_string ( ) ;
73
- let c8y_mqtt_host = c8y_host. clone ( ) ;
74
72
let auth_proxy_addr = c8y_config. proxy . client . host . clone ( ) ;
75
73
let auth_proxy_port = c8y_config. proxy . client . port ;
76
74
let auth_proxy_protocol = c8y_config
77
75
. proxy
78
76
. cert_path
79
77
. or_none ( )
80
78
. map_or ( Protocol :: Http , |_| Protocol :: Https ) ;
79
+ let c8y_host = format ! (
80
+ "{}://{auth_proxy_addr}:{auth_proxy_port}" ,
81
+ auth_proxy_protocol. as_str( )
82
+ ) ;
83
+ let c8y_mqtt_host = c8y_host. clone ( ) ;
81
84
let proxy = ProxyUrlGenerator :: new ( auth_proxy_addr, auth_proxy_port, auth_proxy_protocol) ;
82
-
83
85
Ok ( C8yEndPoint {
84
86
c8y_host,
85
87
c8y_mqtt_host,
Original file line number Diff line number Diff line change @@ -47,7 +47,10 @@ pub struct RenewCertCmd {
47
47
#[ async_trait:: async_trait]
48
48
impl Command for RenewCertCmd {
49
49
fn description ( & self ) -> String {
50
- format ! ( "renew the device certificate from {}" , self . c8y_url( ) )
50
+ format ! (
51
+ "renew the device certificate via Cumulocity HTTP proxy {}" ,
52
+ self . c8y_url( )
53
+ )
51
54
}
52
55
53
56
async fn execute ( & self ) -> Result < ( ) , MaybeFancy < Error > > {
@@ -103,10 +106,8 @@ impl RenewCertCmd {
103
106
response. status( ) ,
104
107
response. text( ) . await . unwrap_or( "" . to_string( ) )
105
108
) ) ,
106
- Err ( err) => Err ( anyhow ! (
107
- "Fail to connect to {url}: {:?}" ,
108
- get_webpki_error_from_reqwest( err)
109
- ) ) ,
109
+ Err ( err) => Err ( Error :: new ( get_webpki_error_from_reqwest ( err) )
110
+ . context ( format ! ( "Fail to connect to Cumulocity HTTP proxy {url}" ) ) ) ,
110
111
}
111
112
}
112
113
Original file line number Diff line number Diff line change @@ -79,6 +79,12 @@ pub enum CertError {
79
79
#[ error( transparent) ]
80
80
PathsError ( #[ from] PathsError ) ,
81
81
82
+ #[ error( "Connection error: {0}" ) ]
83
+ ReqwestConnect ( String ) ,
84
+
85
+ #[ error( "Request time out" ) ]
86
+ ReqwestTimeout ,
87
+
82
88
#[ error( transparent) ]
83
89
ReqwestError ( #[ from] reqwest:: Error ) ,
84
90
@@ -161,6 +167,16 @@ pub fn get_webpki_error_from_reqwest(err: reqwest::Error) -> CertError {
161
167
{
162
168
CertError :: CertificateError ( tls_error)
163
169
} else {
164
- CertError :: ReqwestError ( err) // any other Error type than `hyper::Error`
170
+ // any other Error type than `hyper::Error`
171
+ if err. is_connect ( ) {
172
+ match err. source ( ) . and_then ( |err| err. source ( ) ) {
173
+ Some ( io_error) => CertError :: ReqwestConnect ( format ! ( "{io_error}" ) ) ,
174
+ None => CertError :: ReqwestError ( err) ,
175
+ }
176
+ } else if err. is_timeout ( ) {
177
+ CertError :: ReqwestTimeout
178
+ } else {
179
+ CertError :: ReqwestError ( err)
180
+ }
165
181
}
166
182
}
You can’t perform that action at this time.
0 commit comments