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 {
3535 /// Invalidate a file on CloudFront
3636 ///
3737 /// `path` is the path to the file to invalidate, such as `config.json`, or `re/ge/regex`
38- #[ instrument( skip( self ) ) ]
3938 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+ }
4541
42+ /// Invalidate multiple paths on Cloudfront.
43+ #[ instrument( skip( self ) ) ]
44+ pub async fn invalidate_many ( & self , mut paths : Vec < String > ) -> anyhow:: Result < ( ) > {
4645 let now = chrono:: offset:: Utc :: now ( ) . timestamp_micros ( ) ;
4746
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 ( ) ?;
4960
5061 let invalidation_batch = InvalidationBatch :: builder ( )
5162 . caller_reference ( format ! ( "{now}" ) )
You can’t perform that action at this time.
0 commit comments