File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -35,17 +35,28 @@ impl CloudFront {
35
35
/// Invalidate a file on CloudFront
36
36
///
37
37
/// `path` is the path to the file to invalidate, such as `config.json`, or `re/ge/regex`
38
- #[ instrument( skip( self ) ) ]
39
38
pub async fn invalidate ( & self , path : & str ) -> anyhow:: Result < ( ) > {
40
- let path = if path. starts_with ( '/' ) {
41
- path. to_string ( )
42
- } else {
43
- format ! ( "/{path}" )
44
- } ;
39
+ self . invalidate_many ( vec ! [ path. to_string( ) ] ) . await
40
+ }
45
41
42
+ /// Invalidate multiple paths on Cloudfront.
43
+ #[ instrument( skip( self ) ) ]
44
+ pub async fn invalidate_many ( & self , mut paths : Vec < String > ) -> anyhow:: Result < ( ) > {
46
45
let now = chrono:: offset:: Utc :: now ( ) . timestamp_micros ( ) ;
47
46
48
- let paths = Paths :: builder ( ) . quantity ( 1 ) . items ( path) . build ( ) ?;
47
+ // We need to ensure that paths have a starting slash.
48
+ for path in paths. iter_mut ( ) {
49
+ if !path. starts_with ( '/' ) {
50
+ * path = format ! ( "/{path}" ) ;
51
+ }
52
+ }
53
+
54
+ let paths = Paths :: builder ( )
55
+ // It looks like you have to set quantity even if you provide a full blown Vec, because
56
+ // reasons.
57
+ . quantity ( paths. len ( ) as i32 )
58
+ . set_items ( Some ( paths) )
59
+ . build ( ) ?;
49
60
50
61
let invalidation_batch = InvalidationBatch :: builder ( )
51
62
. caller_reference ( format ! ( "{now}" ) )
You can’t perform that action at this time.
0 commit comments