@@ -791,7 +791,7 @@ async function read_object_md(req) {
791
791
throw new RpcError ( 'UNAUTHORIZED' , 'requesting account is not authorized to read the object' ) ;
792
792
}
793
793
794
- check_md_conditions ( md_conditions , obj ) ;
794
+ http_utils . check_md_conditions ( md_conditions , obj ) ;
795
795
const info = get_object_info ( obj , { role : req . role } ) ;
796
796
_check_encryption_permissions ( obj . encryption , encryption ) ;
797
797
@@ -1593,51 +1593,6 @@ function check_object_mode(req, obj, rpc_code) {
1593
1593
return obj ;
1594
1594
}
1595
1595
1596
- function check_md_conditions ( conditions , obj ) {
1597
- if ( ! conditions ) return ;
1598
- if ( ! conditions . if_match_etag &&
1599
- ! conditions . if_none_match_etag &&
1600
- ! conditions . if_modified_since &&
1601
- ! conditions . if_unmodified_since ) return ;
1602
-
1603
- const data = obj ? {
1604
- etag : obj . etag ,
1605
- last_modified : obj . create_time ?
1606
- obj . create_time . getTime ( ) : obj . _id . getTimestamp ( ) . getTime ( ) ,
1607
- } : {
1608
- etag : '' ,
1609
- last_modified : 0 ,
1610
- } ;
1611
-
1612
- // See http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectHEAD.html#req-header-consideration-1
1613
- // See https://tools.ietf.org/html/rfc7232 (HTTP Conditional Requests)
1614
- let matched = false ;
1615
- let unmatched = false ;
1616
-
1617
- if ( conditions . if_match_etag ) {
1618
- if ( ! ( obj && http_utils . match_etag ( conditions . if_match_etag , data . etag ) ) ) {
1619
- throw new RpcError ( 'IF_MATCH_ETAG' , 'check_md_conditions failed' , data ) ;
1620
- }
1621
- matched = true ;
1622
- }
1623
- if ( conditions . if_none_match_etag ) {
1624
- if ( obj && http_utils . match_etag ( conditions . if_none_match_etag , data . etag ) ) {
1625
- throw new RpcError ( 'IF_NONE_MATCH_ETAG' , 'check_md_conditions failed' , data ) ;
1626
- }
1627
- unmatched = true ;
1628
- }
1629
- if ( conditions . if_modified_since ) {
1630
- if ( ! unmatched && ( ! obj || conditions . if_modified_since > data . last_modified ) ) {
1631
- throw new RpcError ( 'IF_MODIFIED_SINCE' , 'check_md_conditions failed' , data ) ;
1632
- }
1633
- }
1634
- if ( conditions . if_unmodified_since ) {
1635
- if ( ! matched && ( ! obj || conditions . if_unmodified_since < data . last_modified ) ) {
1636
- throw new RpcError ( 'IF_UNMODIFIED_SINCE' , 'check_md_conditions failed' , data ) ;
1637
- }
1638
- }
1639
- }
1640
-
1641
1596
/**
1642
1597
* Return the etag ("Entity tag") for the given entity.
1643
1598
* Entity can be ObjectMD or ObjectMultipart or an updates for one of those.
@@ -1736,8 +1691,8 @@ async function _put_object_handle_latest({ req, put_obj, set_updates, unset_upda
1736
1691
1737
1692
if ( bucket_versioning === 'DISABLED' ) {
1738
1693
const obj = await MDStore . instance ( ) . find_object_null_version ( req . bucket . _id , put_obj . key ) ;
1694
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1739
1695
if ( obj ) {
1740
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1741
1696
// 2, 3, 6, 7
1742
1697
await MDStore . instance ( ) . complete_object_upload_latest_mark_remove_current_and_delete ( {
1743
1698
unmark_obj : obj ,
@@ -1754,8 +1709,8 @@ async function _put_object_handle_latest({ req, put_obj, set_updates, unset_upda
1754
1709
1755
1710
if ( bucket_versioning === 'ENABLED' ) {
1756
1711
const obj = await MDStore . instance ( ) . find_object_latest ( req . bucket . _id , put_obj . key ) ;
1712
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1757
1713
if ( obj ) {
1758
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1759
1714
// 3, 6
1760
1715
await MDStore . instance ( ) . complete_object_upload_latest_mark_remove_current ( {
1761
1716
unmark_obj : obj ,
@@ -1773,12 +1728,11 @@ async function _put_object_handle_latest({ req, put_obj, set_updates, unset_upda
1773
1728
if ( bucket_versioning === 'SUSPENDED' ) {
1774
1729
const obj = await MDStore . instance ( ) . find_object_null_version ( req . bucket . _id , put_obj . key ) ;
1775
1730
if ( obj ) {
1776
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1777
1731
// 2, 3, 6, 7
1778
1732
if ( obj . version_past ) {
1779
1733
const latest_obj = await MDStore . instance ( ) . find_object_latest ( req . bucket . _id , put_obj . key ) ;
1734
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1780
1735
if ( latest_obj ) {
1781
- check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1782
1736
// 2, 3, 6, 7
1783
1737
await MDStore . instance ( ) . complete_object_upload_latest_mark_remove_current_and_delete ( {
1784
1738
delete_obj : obj ,
@@ -1792,6 +1746,7 @@ async function _put_object_handle_latest({ req, put_obj, set_updates, unset_upda
1792
1746
await MDStore . instance ( ) . update_object_by_id ( put_obj . _id , set_updates , unset_updates ) ;
1793
1747
}
1794
1748
} else {
1749
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1795
1750
await MDStore . instance ( ) . complete_object_upload_latest_mark_remove_current_and_delete ( {
1796
1751
unmark_obj : obj ,
1797
1752
put_obj,
@@ -1801,8 +1756,8 @@ async function _put_object_handle_latest({ req, put_obj, set_updates, unset_upda
1801
1756
}
1802
1757
} else {
1803
1758
const latest_obj = await MDStore . instance ( ) . find_object_latest ( req . bucket . _id , put_obj . key ) ;
1759
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1804
1760
if ( latest_obj ) {
1805
- check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1806
1761
// 3, 6
1807
1762
await MDStore . instance ( ) . complete_object_upload_latest_mark_remove_current ( {
1808
1763
unmark_obj : latest_obj ,
@@ -1828,10 +1783,10 @@ async function _delete_object_version(req) {
1828
1783
1829
1784
if ( bucket_versioning === 'DISABLED' ) {
1830
1785
const obj = version_id === 'null' && await MDStore . instance ( ) . find_object_or_upload_null_version ( req . bucket . _id , req . rpc_params . key ) ;
1786
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1831
1787
1832
1788
if ( ! obj ) return { reply : { } } ;
1833
1789
if ( obj . delete_marker ) dbg . error ( 'versioning disabled bucket null objects should not have delete_markers' , obj ) ;
1834
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1835
1790
// 2, 3, 8
1836
1791
await MDStore . instance ( ) . remove_object_and_unset_latest ( obj ) ;
1837
1792
return { obj, reply : _get_delete_obj_reply ( obj ) } ;
@@ -1841,6 +1796,7 @@ async function _delete_object_version(req) {
1841
1796
const obj = version_id === 'null' ?
1842
1797
await MDStore . instance ( ) . find_object_or_upload_null_version ( req . bucket . _id , req . rpc_params . key ) :
1843
1798
await MDStore . instance ( ) . find_object_by_version ( req . bucket . _id , req . rpc_params . key , version_seq ) ;
1799
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1844
1800
if ( ! obj ) return { reply : { } } ;
1845
1801
1846
1802
if ( config . WORM_ENABLED && obj . lock_settings ) {
@@ -1863,7 +1819,6 @@ async function _delete_object_version(req) {
1863
1819
}
1864
1820
}
1865
1821
}
1866
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1867
1822
if ( obj . version_past ) {
1868
1823
// 2, 8
1869
1824
await MDStore . instance ( ) . delete_object_by_id ( obj . _id ) ;
@@ -1873,7 +1828,6 @@ async function _delete_object_version(req) {
1873
1828
// we need to find the previous and make it the new latest
1874
1829
const prev_version = await MDStore . instance ( ) . find_object_prev_version ( req . bucket . _id , req . rpc_params . key ) ;
1875
1830
if ( prev_version ) {
1876
- check_md_conditions ( req . rpc_params . md_conditions , prev_version ) ;
1877
1831
// 2, 3, 4, 8
1878
1832
await MDStore . instance ( ) . remove_object_move_latest ( obj , prev_version ) ;
1879
1833
return { obj, reply : _get_delete_obj_reply ( obj ) } ;
@@ -1891,8 +1845,8 @@ async function _delete_object_only_key(req) {
1891
1845
1892
1846
if ( bucket_versioning === 'DISABLED' ) {
1893
1847
const obj = await MDStore . instance ( ) . find_object_latest ( req . bucket . _id , req . rpc_params . key ) ;
1848
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1894
1849
if ( ! obj ) return { reply : { } } ;
1895
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1896
1850
if ( obj . delete_marker ) dbg . error ( 'versioning disabled bucket null objects should not have delete_markers' , obj ) ;
1897
1851
// 2, 3, 8
1898
1852
await MDStore . instance ( ) . remove_object_and_unset_latest ( obj ) ;
@@ -1901,8 +1855,8 @@ async function _delete_object_only_key(req) {
1901
1855
1902
1856
if ( bucket_versioning === 'ENABLED' ) {
1903
1857
const obj = await MDStore . instance ( ) . find_object_latest ( req . bucket . _id , req . rpc_params . key ) ;
1858
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1904
1859
if ( obj ) {
1905
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1906
1860
// 3, 5
1907
1861
const delete_marker = await MDStore . instance ( ) . insert_object_delete_marker_move_latest (
1908
1862
obj , /* version_enabled: */ true ) ;
@@ -1922,12 +1876,11 @@ async function _delete_object_only_key(req) {
1922
1876
if ( bucket_versioning === 'SUSPENDED' ) {
1923
1877
const obj = await MDStore . instance ( ) . find_object_null_version ( req . bucket . _id , req . rpc_params . key ) ;
1924
1878
if ( obj ) {
1925
- check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1926
1879
if ( obj . version_past ) {
1927
1880
const latest_obj = await MDStore . instance ( ) . find_object_latest ( req . bucket . _id , req . rpc_params . key ) ;
1928
1881
if ( latest_obj ) {
1929
- check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1930
1882
// 3, 5
1883
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1931
1884
const delete_marker = await MDStore . instance ( ) . insert_object_delete_marker_move_latest_with_delete ( obj , latest_obj ) ;
1932
1885
return { obj, reply : _get_delete_obj_reply ( obj , delete_marker ) } ;
1933
1886
} else {
@@ -1936,13 +1889,14 @@ async function _delete_object_only_key(req) {
1936
1889
}
1937
1890
} else {
1938
1891
// 2, 3, 5
1892
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , obj ) ;
1939
1893
const delete_marker = await MDStore . instance ( ) . insert_object_delete_marker_move_latest_with_delete ( obj ) ;
1940
1894
return { obj, reply : _get_delete_obj_reply ( obj , delete_marker ) } ;
1941
1895
}
1942
1896
} else {
1943
1897
const latest_obj = await MDStore . instance ( ) . find_object_latest ( req . bucket . _id , req . rpc_params . key ) ;
1898
+ http_utils . check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1944
1899
if ( latest_obj ) {
1945
- check_md_conditions ( req . rpc_params . md_conditions , latest_obj ) ;
1946
1900
// 3, 5
1947
1901
const delete_marker = await MDStore . instance ( ) . insert_object_delete_marker_move_latest ( latest_obj ) ;
1948
1902
return { reply : _get_delete_obj_reply ( null , delete_marker ) } ;
0 commit comments