@@ -140,6 +140,20 @@ impl Storage {
140140 }
141141 }
142142
143+ pub ( crate ) fn get_public_access ( & self , path : & str ) -> Result < bool > {
144+ match & self . backend {
145+ StorageBackend :: Database ( db) => db. get_public_access ( path) ,
146+ StorageBackend :: S3 ( s3) => s3. get_public_access ( path) ,
147+ }
148+ }
149+
150+ pub ( crate ) fn set_public_access ( & self , path : & str , public : bool ) -> Result < ( ) > {
151+ match & self . backend {
152+ StorageBackend :: Database ( db) => db. set_public_access ( path, public) ,
153+ StorageBackend :: S3 ( s3) => s3. set_public_access ( path, public) ,
154+ }
155+ }
156+
143157 fn max_file_size_for ( & self , path : & str ) -> usize {
144158 if path. ends_with ( ".html" ) {
145159 self . config . max_file_size_html
@@ -620,9 +634,38 @@ mod backend_tests {
620634 Ok ( ( ) )
621635 }
622636
637+ fn test_set_public ( storage : & Storage ) -> Result < ( ) > {
638+ let path: & str = "foo/bar.txt" ;
639+
640+ storage. store_blobs ( vec ! [ Blob {
641+ path: path. into( ) ,
642+ mime: "text/plain" . into( ) ,
643+ date_updated: Utc :: now( ) ,
644+ compression: None ,
645+ content: b"test content\n " . to_vec( ) ,
646+ } ] ) ?;
647+
648+ assert ! ( !storage. get_public_access( path) ?) ;
649+ storage. set_public_access ( path, true ) ?;
650+ assert ! ( storage. get_public_access( path) ?) ;
651+ storage. set_public_access ( path, false ) ?;
652+ assert ! ( !storage. get_public_access( path) ?) ;
653+
654+ for path in & [ "bar.txt" , "baz.txt" , "foo/baz.txt" ] {
655+ assert ! ( storage
656+ . set_public_access( path, true )
657+ . unwrap_err( )
658+ . downcast_ref:: <PathNotFoundError >( )
659+ . is_some( ) ) ;
660+ }
661+
662+ Ok ( ( ) )
663+ }
664+
623665 fn test_get_object ( storage : & Storage ) -> Result < ( ) > {
666+ let path: & str = "foo/bar.txt" ;
624667 let blob = Blob {
625- path : "foo/bar.txt" . into ( ) ,
668+ path : path . into ( ) ,
626669 mime : "text/plain" . into ( ) ,
627670 date_updated : Utc :: now ( ) ,
628671 compression : None ,
@@ -631,16 +674,25 @@ mod backend_tests {
631674
632675 storage. store_blobs ( vec ! [ blob. clone( ) ] ) ?;
633676
634- let found = storage. get ( "foo/bar.txt" , std:: usize:: MAX ) ?;
677+ let found = storage. get ( path , std:: usize:: MAX ) ?;
635678 assert_eq ! ( blob. mime, found. mime) ;
636679 assert_eq ! ( blob. content, found. content) ;
637680
681+ // default visibility is private
682+ assert ! ( !storage. get_public_access( path) ?) ;
683+
638684 for path in & [ "bar.txt" , "baz.txt" , "foo/baz.txt" ] {
639685 assert ! ( storage
640686 . get( path, std:: usize :: MAX )
641687 . unwrap_err( )
642688 . downcast_ref:: <PathNotFoundError >( )
643689 . is_some( ) ) ;
690+
691+ assert ! ( storage
692+ . get_public_access( path)
693+ . unwrap_err( )
694+ . downcast_ref:: <PathNotFoundError >( )
695+ . is_some( ) ) ;
644696 }
645697
646698 Ok ( ( ) )
@@ -1028,6 +1080,7 @@ mod backend_tests {
10281080 test_delete_prefix_without_matches,
10291081 test_delete_percent,
10301082 test_exists_without_remote_archive,
1083+ test_set_public,
10311084 }
10321085
10331086 tests_with_metrics {
0 commit comments