1
1
use crate :: { mediatypes:: MediaTypes , v2:: * } ;
2
+ use reqwest:: Certificate ;
2
3
3
4
/// Configuration for a `Client`.
4
5
#[ derive( Debug ) ]
@@ -9,6 +10,7 @@ pub struct Config {
9
10
username : Option < String > ,
10
11
password : Option < String > ,
11
12
accept_invalid_certs : bool ,
13
+ root_certificates : Vec < Certificate > ,
12
14
accepted_types : Option < Vec < ( MediaTypes , Option < f64 > ) > > ,
13
15
}
14
16
@@ -31,6 +33,12 @@ impl Config {
31
33
self
32
34
}
33
35
36
+ /// Add a root certificate the client should trust for TLS verification
37
+ pub fn add_root_certificate ( mut self , certificate : Certificate ) -> Self {
38
+ self . root_certificates . push ( certificate) ;
39
+ self
40
+ }
41
+
34
42
/// Set custom Accept headers
35
43
pub fn accepted_types (
36
44
mut self ,
@@ -87,9 +95,15 @@ impl Config {
87
95
p. unwrap_or_else ( || "" . into ( ) ) ,
88
96
) ) ,
89
97
} ;
90
- let client = reqwest:: ClientBuilder :: new ( )
91
- . danger_accept_invalid_certs ( self . accept_invalid_certs )
92
- . build ( ) ?;
98
+
99
+ let mut builder =
100
+ reqwest:: ClientBuilder :: new ( ) . danger_accept_invalid_certs ( self . accept_invalid_certs ) ;
101
+
102
+ for ca in self . root_certificates {
103
+ builder = builder. add_root_certificate ( ca)
104
+ }
105
+
106
+ let client = builder. build ( ) ?;
93
107
94
108
let accepted_types = match self . accepted_types {
95
109
Some ( a) => a,
@@ -130,6 +144,7 @@ impl Default for Config {
130
144
index : "registry-1.docker.io" . into ( ) ,
131
145
insecure_registry : false ,
132
146
accept_invalid_certs : false ,
147
+ root_certificates : Default :: default ( ) ,
133
148
accepted_types : None ,
134
149
user_agent : Some ( crate :: USER_AGENT . to_owned ( ) ) ,
135
150
username : None ,
0 commit comments