@@ -140,6 +140,20 @@ impl Storage {
140
140
}
141
141
}
142
142
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
+
143
157
fn max_file_size_for ( & self , path : & str ) -> usize {
144
158
if path. ends_with ( ".html" ) {
145
159
self . config . max_file_size_html
@@ -620,9 +634,38 @@ mod backend_tests {
620
634
Ok ( ( ) )
621
635
}
622
636
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
+
623
665
fn test_get_object ( storage : & Storage ) -> Result < ( ) > {
666
+ let path: & str = "foo/bar.txt" ;
624
667
let blob = Blob {
625
- path : "foo/bar.txt" . into ( ) ,
668
+ path : path . into ( ) ,
626
669
mime : "text/plain" . into ( ) ,
627
670
date_updated : Utc :: now ( ) ,
628
671
compression : None ,
@@ -631,16 +674,25 @@ mod backend_tests {
631
674
632
675
storage. store_blobs ( vec ! [ blob. clone( ) ] ) ?;
633
676
634
- let found = storage. get ( "foo/bar.txt" , std:: usize:: MAX ) ?;
677
+ let found = storage. get ( path , std:: usize:: MAX ) ?;
635
678
assert_eq ! ( blob. mime, found. mime) ;
636
679
assert_eq ! ( blob. content, found. content) ;
637
680
681
+ // default visibility is private
682
+ assert ! ( !storage. get_public_access( path) ?) ;
683
+
638
684
for path in & [ "bar.txt" , "baz.txt" , "foo/baz.txt" ] {
639
685
assert ! ( storage
640
686
. get( path, std:: usize :: MAX )
641
687
. unwrap_err( )
642
688
. downcast_ref:: <PathNotFoundError >( )
643
689
. is_some( ) ) ;
690
+
691
+ assert ! ( storage
692
+ . get_public_access( path)
693
+ . unwrap_err( )
694
+ . downcast_ref:: <PathNotFoundError >( )
695
+ . is_some( ) ) ;
644
696
}
645
697
646
698
Ok ( ( ) )
@@ -1028,6 +1080,7 @@ mod backend_tests {
1028
1080
test_delete_prefix_without_matches,
1029
1081
test_delete_percent,
1030
1082
test_exists_without_remote_archive,
1083
+ test_set_public,
1031
1084
}
1032
1085
1033
1086
tests_with_metrics {
0 commit comments