@@ -2,7 +2,7 @@ use std::sync::Mutex;
2
2
3
3
use json:: JsonValue ;
4
4
use rayon:: iter:: { IntoParallelRefIterator , ParallelIterator } ;
5
- use ureq:: Error ;
5
+ use ureq:: { Error , ErrorKind } ;
6
6
7
7
use http_auth:: parse_challenges;
8
8
@@ -56,8 +56,20 @@ pub fn get_latest_digest(image: &Image, token: Option<&String>, config: &JsonVal
56
56
digest : None ,
57
57
..image. clone ( )
58
58
}
59
- }
60
- Err ( ureq:: Error :: Transport ( e) ) => error ! ( "Failed to send request!\n {}" , e) ,
59
+ } ,
60
+ Err ( Error :: Transport ( error) ) => {
61
+ match error. kind ( ) {
62
+ ErrorKind :: Dns => {
63
+ warn ! ( "Failed to lookup the IP of the registry, retrying." ) ;
64
+ return get_latest_digest ( image, token, config)
65
+ } , // If something goes really wrong, this can get stuck in a loop
66
+ ErrorKind :: ConnectionFailed => {
67
+ warn ! ( "Connection probably timed out, retrying." ) ;
68
+ return get_latest_digest ( image, token, config)
69
+ } , // Same here
70
+ _ => error ! ( "Failed to retrieve image digest\n {}!" , error)
71
+ }
72
+ } ,
61
73
} ;
62
74
match raw_response. header ( "docker-content-digest" ) {
63
75
Some ( digest) => Image {
@@ -83,7 +95,7 @@ pub fn get_latest_digests(images: Vec<&Image>, token: Option<&String>, config: &
83
95
84
96
pub fn get_token ( images : Vec < & Image > , auth_url : & str , credentials : & Option < String > ) -> String {
85
97
let mut final_url = auth_url. to_owned ( ) ;
86
- for image in images {
98
+ for image in & images {
87
99
final_url = format ! ( "{}&scope=repository:{}:pull" , final_url, image. repository) ;
88
100
}
89
101
let mut base_request = ureq:: get ( & final_url) . set ( "Accept" , "application/vnd.oci.image.index.v1+json" ) ; // Seems to be unnecesarry. Will probably remove in the future
@@ -99,6 +111,19 @@ pub fn get_token(images: Vec<&Image>, auth_url: &str, credentials: &Option<Strin
99
111
error ! ( "Failed to parse response into string!\n {}" , e)
100
112
}
101
113
} ,
114
+ Err ( Error :: Transport ( error) ) => {
115
+ match error. kind ( ) {
116
+ ErrorKind :: Dns => {
117
+ warn ! ( "Failed to lookup the IP of the registry, retrying." ) ;
118
+ return get_token ( images, auth_url, credentials)
119
+ } , // If something goes really wrong, this can get stuck in a loop
120
+ ErrorKind :: ConnectionFailed => {
121
+ warn ! ( "Connection probably timed out, retrying." ) ;
122
+ return get_token ( images, auth_url, credentials)
123
+ } , // Same here
124
+ _ => error ! ( "Token request failed\n {}!" , error)
125
+ }
126
+ } ,
102
127
Err ( e) => {
103
128
error ! ( "Token request failed!\n {}" , e)
104
129
}
0 commit comments