@@ -6,7 +6,7 @@ use stor_port::types::v0::openapi::{
66} ;
77
88use anyhow:: anyhow;
9- use std:: { collections:: HashMap , sync:: Arc , time:: Duration } ;
9+ use std:: { collections:: HashMap , path :: PathBuf , sync:: Arc , time:: Duration } ;
1010use stor_port:: types:: v0:: openapi:: {
1111 apis:: {
1212 app_nodes_api:: tower:: client:: direct:: AppNodes ,
@@ -107,6 +107,7 @@ impl AppNodesClientWrapper {
107107 /// Initialize AppNodes API client instance.
108108 pub ( crate ) fn initialize (
109109 endpoint : Option < & String > ,
110+ ca_certificate_path : Option < & PathBuf > ,
110111 ) -> anyhow:: Result < Option < AppNodesClientWrapper > > {
111112 const REST_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
112113
@@ -117,12 +118,49 @@ impl AppNodesClientWrapper {
117118 let url = clients:: tower:: Url :: parse ( endpoint)
118119 . map_err ( |error| anyhow ! ( "Invalid API endpoint URL {endpoint}: {error:?}" ) ) ?;
119120
120- let tower = clients:: tower:: Configuration :: builder ( )
121- . with_timeout ( REST_TIMEOUT )
122- . build_url ( url)
123- . map_err ( |error| {
124- anyhow:: anyhow!( "Failed to create openapi configuration, Error: '{error:?}'" )
125- } ) ?;
121+ let cert = match ca_certificate_path {
122+ Some ( path) => {
123+ let cert = std:: fs:: read ( path) . map_err ( |error| {
124+ anyhow:: anyhow!(
125+ "Failed to create openapi configuration at path {}, Error: '{:?}'" ,
126+ path. display( ) ,
127+ error
128+ )
129+ } ) ?;
130+ Some ( cert)
131+ }
132+ None => None ,
133+ } ;
134+
135+ let tower = match ( url. scheme ( ) , cert) {
136+ ( "https" , Some ( cert) ) => clients:: tower:: Configuration :: builder ( )
137+ . with_timeout ( REST_TIMEOUT )
138+ . with_concurrency_limit ( Some ( 10 ) )
139+ . with_certificate ( & cert)
140+ . build_url ( url)
141+ . map_err ( |error| {
142+ anyhow:: anyhow!(
143+ "Failed to create openapi configuration***, Error: '{:?}'" ,
144+ error
145+ )
146+ } ) ?,
147+ ( "https" , None ) => {
148+ anyhow:: bail!( "HTTPS endpoint requires a CA certificate path" ) ;
149+ }
150+ ( _, Some ( _path) ) => {
151+ anyhow:: bail!( "CA certificate path is only supported for HTTPS endpoints" ) ;
152+ }
153+ _ => clients:: tower:: Configuration :: builder ( )
154+ . with_timeout ( REST_TIMEOUT )
155+ . with_concurrency_limit ( Some ( 10 ) )
156+ . build_url ( url)
157+ . map_err ( |error| {
158+ anyhow:: anyhow!(
159+ "Failed to create openapi configuration, Error???: '{:?}'" ,
160+ error
161+ )
162+ } ) ?,
163+ } ;
126164
127165 info ! (
128166 "API client is initialized with endpoint {endpoint}, request timeout = {REST_TIMEOUT:?}"
@@ -169,20 +207,56 @@ pub(crate) struct VolumesClientWrapper {
169207
170208impl VolumesClientWrapper {
171209 /// Initialize VolumesClientWrapper instance.
172- pub ( crate ) fn new ( endpoint : & str ) -> anyhow:: Result < Self > {
210+ pub ( crate ) fn new (
211+ endpoint : & str ,
212+ ca_certificate_path : Option < PathBuf > ,
213+ ) -> anyhow:: Result < Self > {
173214 /// TODO: what's the NodeStage timeout?
174215 const REST_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
175216
176217 let url = clients:: tower:: Url :: parse ( endpoint)
177218 . map_err ( |error| anyhow ! ( "Invalid API endpoint URL {endpoint}: {error:?}" ) ) ?;
219+ let cert = match ca_certificate_path {
220+ Some ( path) => {
221+ let cert = std:: fs:: read ( path. clone ( ) ) . map_err ( |error| {
222+ anyhow:: anyhow!(
223+ "Failed to create openapi configuration at path {}, Error: '{:?}'" ,
224+ path. display( ) ,
225+ error
226+ )
227+ } ) ?;
228+ Some ( cert)
229+ }
230+ None => None ,
231+ } ;
178232
179- let config = clients:: tower:: Configuration :: builder ( )
180- . with_timeout ( REST_TIMEOUT )
181- . with_concurrency_limit ( Some ( 10 ) )
182- . build_url ( url)
183- . map_err ( |error| {
184- anyhow:: anyhow!( "Failed to create openapi configuration, Error: '{error:?}'" )
185- } ) ?;
233+ let config = match ( url. scheme ( ) , cert) {
234+ ( "https" , Some ( cert) ) => clients:: tower:: Configuration :: builder ( )
235+ . with_timeout ( REST_TIMEOUT )
236+ . with_certificate ( & cert)
237+ . build_url ( url)
238+ . map_err ( |error| {
239+ anyhow:: anyhow!(
240+ "Failed to create openapi configuration***, Error: '{:?}'" ,
241+ error
242+ )
243+ } ) ?,
244+ ( "https" , None ) => {
245+ anyhow:: bail!( "HTTPS endpoint requires a CA certificate path" ) ;
246+ }
247+ ( _, Some ( _path) ) => {
248+ anyhow:: bail!( "CA certificate path is only supported for HTTPS endpoints" ) ;
249+ }
250+ _ => clients:: tower:: Configuration :: builder ( )
251+ . with_timeout ( REST_TIMEOUT )
252+ . build_url ( url)
253+ . map_err ( |error| {
254+ anyhow:: anyhow!(
255+ "Failed to create openapi configuration, Error???: '{:?}'" ,
256+ error
257+ )
258+ } ) ?,
259+ } ;
186260
187261 info ! (
188262 "VolumesClient API is initialized with endpoint {endpoint}, request timeout = {REST_TIMEOUT:?}"
0 commit comments