@@ -20,15 +20,25 @@ pub(crate) enum CdnKind {
20
20
21
21
pub enum CdnBackend {
22
22
Dummy ( Arc < Mutex < Vec < ( String , String ) > > > ) ,
23
- CloudFront { runtime : Arc < Runtime > } ,
23
+ CloudFront {
24
+ runtime : Arc < Runtime > ,
25
+ client : Client ,
26
+ } ,
24
27
}
25
28
26
29
impl CdnBackend {
27
30
pub fn new ( config : & Arc < Config > , runtime : & Arc < Runtime > ) -> CdnBackend {
28
31
match config. cdn_backend {
29
- CdnKind :: CloudFront => Self :: CloudFront {
30
- runtime : runtime. clone ( ) ,
31
- } ,
32
+ CdnKind :: CloudFront => {
33
+ let shared_config = runtime. block_on ( aws_config:: load_from_env ( ) ) ;
34
+ let config_builder = aws_sdk_cloudfront:: config:: Builder :: from ( & shared_config)
35
+ . retry_config ( RetryConfig :: new ( ) . with_max_attempts ( 3 ) ) ;
36
+
37
+ Self :: CloudFront {
38
+ runtime : runtime. clone ( ) ,
39
+ client : Client :: from_conf ( config_builder. build ( ) ) ,
40
+ }
41
+ }
32
42
CdnKind :: Dummy => Self :: Dummy ( Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ) ,
33
43
}
34
44
}
@@ -50,15 +60,14 @@ impl CdnBackend {
50
60
let caller_reference = Uuid :: new_v4 ( ) ;
51
61
52
62
match * self {
53
- CdnBackend :: CloudFront { ref runtime } => {
54
- let shared_config = runtime. block_on ( aws_config:: load_from_env ( ) ) ;
55
- let config_builder = aws_sdk_cloudfront:: config:: Builder :: from ( & shared_config)
56
- . retry_config ( RetryConfig :: new ( ) . with_max_attempts ( 3 ) ) ;
57
-
63
+ CdnBackend :: CloudFront {
64
+ ref runtime,
65
+ ref client,
66
+ } => {
58
67
runtime. block_on ( CdnBackend :: cloudfront_invalidation (
59
- & Client :: from_conf ( config_builder . build ( ) ) ,
68
+ client ,
60
69
distribution_id,
61
- & format ! ( "{}" , caller_reference) ,
70
+ & caller_reference. to_string ( ) ,
62
71
path_patterns,
63
72
) ) ?;
64
73
}
0 commit comments