@@ -1397,9 +1397,10 @@ def validate_buckets(filename, comp_ids):
13971397 log (f'ROW { i + 3 } : Value of "Auto Tiering" can be only either "Enabled" or "Disabled".' )
13981398 buckets_invalid_check = True
13991399
1400+ # Check for the Object Versioning column
14001401 if columnname == 'Object Versioning' :
1401- if columnvalue .lower () not in ['enabled' ,'disabled' ]:
1402- log (f'ROW { i + 3 } : Value of "Object Versioning" can be only either "Enabled" or "Disabled".' )
1402+ if columnvalue .lower () not in ['enabled' , 'disabled' ]:
1403+ log (f'ROW { i + 3 } : Value of "Object Versioning" can only be "Enabled" or "Disabled".' )
14031404 buckets_invalid_check = True
14041405
14051406 if columnname == 'Emit Object Events' :
@@ -1438,69 +1439,74 @@ def validate_buckets(filename, comp_ids):
14381439 #Check for the retention policy details
14391440 if columnname == 'Retention Rules' :
14401441 rule_values = columnvalue .split ("\n " )
1441- retention_rules = []
1442- for rule in rule_values :
1443- rule_components = rule .split ("::" )
1444- if len (rule_components ) >= 1 :
1445- retention_rule_display_name = rule_components [0 ]
1446- time_unit = None
1447- time_amount = None
1448- time_rule_locked = None
1449-
1450- if len (rule_components ) >= 2 :
1451- if rule_components [1 ].lower () == 'indefinite' :
1452- time_amount = None
1453- else :
1454- time_amount = rule_components [1 ]
1455- if not time_amount .isdigit ():
1456- log (f'ROW { i + 3 } : "time_amount" of retention rule is not in valid format. It should be an "integer" or "indefinite".' )
1457- buckets_invalid_check = True
1458- continue
1442+ if rule_values and str (dfbuckets .loc [i , 'Object Versioning' ]).strip ().lower () == 'enabled' :
1443+ log (f'ROW { i + 3 } : Retention policy cannot be created when Object Versioning is enabled.' )
1444+ buckets_invalid_check = True
1445+
1446+ elif rule_values and str (dfbuckets .loc [i , 'Object Versioning' ]).strip ().lower () == 'disabled' :
1447+ retention_rules = []
1448+ for rule in rule_values :
1449+ rule_components = rule .split ("::" )
1450+ if len (rule_components ) >= 1 :
1451+ retention_rule_display_name = rule_components [0 ]
1452+ time_unit = None
1453+ time_amount = None
1454+ time_rule_locked = None
1455+
1456+ if len (rule_components ) >= 2 :
1457+ if rule_components [1 ].lower () == 'indefinite' :
1458+ time_amount = None
14591459 else :
1460- time_amount = int (time_amount )
1460+ time_amount = rule_components [1 ]
1461+ if not time_amount .isdigit ():
1462+ log (f'ROW { i + 3 } : "time_amount" of retention rule is not in valid format. It should be an "integer" or "indefinite".' )
1463+ buckets_invalid_check = True
1464+ continue
1465+ else :
1466+ time_amount = int (time_amount )
14611467
1462- if len (rule_components ) >= 3 :
1463- time_unit = rule_components [2 ].upper ()
1464- if time_unit not in ('DAYS' , 'YEARS' ):
1465- log (f'ROW { i + 3 } : "time_unit" of retention rule is not in valid format. It should be either DAYS or YEARS.' )
1466- buckets_invalid_check = True
1467- else :
1468- # If time_unit is valid, set the flag to True for processing time_rule_locked
1469- process_time_rule_locked = True
1470-
1471- if len (rule_components ) == 4 and process_time_rule_locked :
1472- time_rule_locked = rule_components [3 ]
1473- if time_rule_locked .endswith (".000Z" ):
1474- time_rule_locked = time_rule_locked [:- 5 ] + "Z"
1475- elif not re .match (r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z" ,time_rule_locked ):
1476- # Convert from "dd-mm-yyyy" to "YYYY-MM-DDThh:mm:ssZ" format
1477- if re .match (r"\d{2}-\d{2}-\d{4}" , time_rule_locked ):
1478- try :
1479- datetime_obj = datetime .datetime .strptime (time_rule_locked , "%d-%m-%Y" )
1480- time_rule_locked = datetime_obj .strftime ("%Y-%m-%dT%H:%M:%SZ" )
1481- except ValueError :
1468+ if len (rule_components ) >= 3 :
1469+ time_unit = rule_components [2 ].upper ()
1470+ if time_unit not in ('DAYS' , 'YEARS' ):
1471+ log (f'ROW { i + 3 } : "time_unit" of retention rule is not in valid format. It should be either DAYS or YEARS.' )
1472+ buckets_invalid_check = True
1473+ else :
1474+ # If time_unit is valid, set the flag to True for processing time_rule_locked
1475+ process_time_rule_locked = True
1476+
1477+ if len (rule_components ) == 4 and process_time_rule_locked :
1478+ time_rule_locked = rule_components [3 ]
1479+ if time_rule_locked .endswith (".000Z" ):
1480+ time_rule_locked = time_rule_locked [:- 5 ] + "Z"
1481+ elif not re .match (r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z" ,time_rule_locked ):
1482+ # Convert from "dd-mm-yyyy" to "YYYY-MM-DDThh:mm:ssZ" format
1483+ if re .match (r"\d{2}-\d{2}-\d{4}" , time_rule_locked ):
1484+ try :
1485+ datetime_obj = datetime .datetime .strptime (time_rule_locked , "%d-%m-%Y" )
1486+ time_rule_locked = datetime_obj .strftime ("%Y-%m-%dT%H:%M:%SZ" )
1487+ except ValueError :
1488+ log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "dd-mm-yyyy".' )
1489+ buckets_invalid_check = True
1490+ continue
1491+ else :
14821492 log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "dd-mm-yyyy".' )
14831493 buckets_invalid_check = True
14841494 continue
1485- else :
1486- log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "dd-mm-yyyy".' )
1495+ # Parse the time_rule_locked into a datetime object
1496+ try :
1497+ time_rule_locked_datetime = datetime .datetime .strptime (time_rule_locked , "%Y-%m-%dT%H:%M:%SZ" )
1498+ except ValueError :
1499+ log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "YYYY-MM-DDThh:mm:ssZ".' )
14871500 buckets_invalid_check = True
14881501 continue
1489- # Parse the time_rule_locked into a datetime object
1490- try :
1491- time_rule_locked_datetime = datetime .datetime .strptime (time_rule_locked , "%Y-%m-%dT%H:%M:%SZ" )
1492- except ValueError :
1493- log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "YYYY-MM-DDThh:mm:ssZ".' )
1494- buckets_invalid_check = True
1495- continue
14961502
1497- # Calculate the difference between current time and time_rule_locked
1498- time_difference = time_rule_locked_datetime - current_time
1503+ # Calculate the difference between current time and time_rule_locked
1504+ time_difference = time_rule_locked_datetime - current_time
14991505
1500- # Check if the difference is less than 14 days
1501- if time_difference .days < 14 :
1502- log (f'ROW { i + 3 } : "time_rule_locked" of retention rule must be more than 14 days from the current time.' )
1503- buckets_invalid_check = True
1506+ # Check if the difference is less than 14 days
1507+ if time_difference .days < 14 :
1508+ log (f'ROW { i + 3 } : "time_rule_locked" of retention rule must be more than 14 days from the current time.' )
1509+ buckets_invalid_check = True
15041510
15051511 # Check for the Lifecycle Policy Details
15061512 if lifecycle_input == True :
@@ -1545,6 +1551,7 @@ def validate_buckets(filename, comp_ids):
15451551 if time_unit not in ['days' ,'years' ]:
15461552 log (f'ROW { i + 3 } : Invalid time amount. "Lifecycle Rule Period" must be "DAYS" or "YEARS".' )
15471553 buckets_invalid_check = True
1554+
15481555 else :
15491556 log (f'ROW { i + 3 } : Invalid format for "Lifecycle Rule Period" ' )
15501557 buckets_invalid_check = True
0 commit comments